mirror of
https://github.com/fluencelabs/hackethberlin
synced 2025-04-25 09:22:21 +00:00
assignments for ref
This commit is contained in:
parent
ddf77fc900
commit
c4e3a7c2f9
@ -15,8 +15,8 @@ sealed trait InlineExpr[T] extends Expr[T] with Expr.ToInlineVyper {
|
|||||||
def :=:(name: Symbol): Free[Expr, Expr.Ref[T]] =
|
def :=:(name: Symbol): Free[Expr, Expr.Ref[T]] =
|
||||||
Free.liftF[Expr, Expr.Ref[T]](Expr.Assign[T](Expr.Ref[T](name.name, boxedValue), this))
|
Free.liftF[Expr, Expr.Ref[T]](Expr.Assign[T](Expr.Ref[T](name.name, boxedValue), this))
|
||||||
|
|
||||||
def :==:(ref: Expr.Ref[T]): Free[Expr, Expr.Ref[T]] =
|
def :=:[J <: T](ref: Expr.Ref[J]): Free[Expr, Expr.Ref[T]] =
|
||||||
Free.liftF[Expr, Expr.Ref[T]](Expr.Assign[T](ref, this))
|
Free.liftF[Expr, Expr.Ref[T]](Expr.Assign[T](Expr.Ref[T](ref.name, ref.boxedValue), this))
|
||||||
}
|
}
|
||||||
|
|
||||||
object Expr {
|
object Expr {
|
||||||
|
@ -1,62 +0,0 @@
|
|||||||
package fluence.hackethberlin
|
|
||||||
|
|
||||||
import scala.language.implicitConversions
|
|
||||||
import shapeless._
|
|
||||||
import shapeless.Everywhere
|
|
||||||
import ops.hlist.{Align, Mapper, Prepend}
|
|
||||||
import poly._
|
|
||||||
import record._
|
|
||||||
import syntax.singleton._
|
|
||||||
import shapeless.tag
|
|
||||||
import tag.{@@, Tagged}
|
|
||||||
|
|
||||||
object untag extends Poly1 {
|
|
||||||
implicit def ut[A, B] = at[A @@ B]{ x =>
|
|
||||||
println("untagging " + x)
|
|
||||||
x.asInstanceOf[A]
|
|
||||||
}
|
|
||||||
|
|
||||||
trait Converter[G <: HList, A] {
|
|
||||||
def convert(g: G): A
|
|
||||||
}
|
|
||||||
|
|
||||||
implicit def convert[A, F <: HList, G <: HList](implicit
|
|
||||||
gen: LabelledGeneric.Aux[A, F],
|
|
||||||
align: Align[G, F]) =
|
|
||||||
new Converter[G, A] {
|
|
||||||
def convert(g: G) = gen.from(align(g))
|
|
||||||
}
|
|
||||||
|
|
||||||
implicit class ToConverter[G <: HList, R <: HList, F <: HList](ag: (R, F)) {
|
|
||||||
def convertTo[B](implicit p: Prepend.Aux[R, F, G], c: Converter[G, B]) =
|
|
||||||
c.convert(ag._1 ++ ag._2)
|
|
||||||
}
|
|
||||||
|
|
||||||
implicit class Untag[A, R <: HList](a: A)(implicit
|
|
||||||
gen: LabelledGeneric.Aux[A, R],
|
|
||||||
val e: Everywhere[untag.type, R]) {
|
|
||||||
def untagged: e.Result = e(gen.to(a))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
object Example extends App {
|
|
||||||
|
|
||||||
import untag._
|
|
||||||
|
|
||||||
trait TagInt {}
|
|
||||||
|
|
||||||
case class Foo(a: String, b: Int @@ TagInt)
|
|
||||||
case class Bar(b: Int, a: String, c: String, d: Int)
|
|
||||||
case class Baz(a: String, b: Int)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
println(Foo("foo", tag[TagInt](1)).untagged)
|
|
||||||
// Next line is broken, type info is lost coming from call to untagged
|
|
||||||
// poly is being applied to the tagged field as output shows
|
|
||||||
|
|
||||||
// println(Foo("foo", tag[TagInt](1)).untagged, (('d ->> 3) :: ('c ->> "bar") :: HNil)).convertTo[Bar])
|
|
||||||
|
|
||||||
val gbz = LabelledGeneric[Baz]
|
|
||||||
println((gbz.to(Baz("foo", 1)), (('d ->> 3) :: ('c ->> "bar") :: HNil)).convertTo[Bar])
|
|
||||||
}
|
|
@ -7,8 +7,6 @@ import shapeless.ops.record.Selector
|
|||||||
|
|
||||||
class ProductType[D <: HList](dataDef: D, dv: DataVyper[D]) extends Type {
|
class ProductType[D <: HList](dataDef: D, dv: DataVyper[D]) extends Type {
|
||||||
|
|
||||||
import fluence.hackethberlin.untag._
|
|
||||||
|
|
||||||
def ref[T <: Symbol, V <: Type](k: Witness.Aux[T])(implicit selector: Selector.Aux[D, T, V]): Expr.Ref[V] =
|
def ref[T <: Symbol, V <: Type](k: Witness.Aux[T])(implicit selector: Selector.Aux[D, T, V]): Expr.Ref[V] =
|
||||||
Expr.Ref[V](k.value.name, selector(dataDef))
|
Expr.Ref[V](k.value.name, selector(dataDef))
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ object MakeVyperApp extends App {
|
|||||||
for {
|
for {
|
||||||
c ← 'c :=: `++`(args.ref('a), args.ref('b))
|
c ← 'c :=: `++`(args.ref('a), args.ref('b))
|
||||||
d ← 'd :=: `++`(args.ref('b), c)
|
d ← 'd :=: `++`(args.ref('b), c)
|
||||||
_ ← d :==: c
|
_ ← d :=: c
|
||||||
sum ← `++`(args.ref('a), d).toReturn
|
sum ← `++`(args.ref('a), d).toReturn
|
||||||
} yield sum
|
} yield sum
|
||||||
}
|
}
|
||||||
@ -71,6 +71,7 @@ object MakeVyperApp extends App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
object Auction {
|
object Auction {
|
||||||
|
|
||||||
val data = ProductType(
|
val data = ProductType(
|
||||||
('beneficiary ->> public(address)) ::
|
('beneficiary ->> public(address)) ::
|
||||||
('auction_start ->> public(timestamp)) ::
|
('auction_start ->> public(timestamp)) ::
|
||||||
@ -100,21 +101,20 @@ object Auction {
|
|||||||
) { args ⇒
|
) { args ⇒
|
||||||
for {
|
for {
|
||||||
_ <- Free.pure(Void)
|
_ <- Free.pure(Void)
|
||||||
// _ <- beneficiary :==: _beneficiary
|
_ <- beneficiary :=: _beneficiary
|
||||||
// _ <- auction_start :==: block.timestamp
|
// _ <- auction_start :==: block.timestamp
|
||||||
// _ <- auction_end :==: auction_start `+:+` _bidding_time
|
// _ <- auction_end :==: auction_start `+:+` _bidding_time
|
||||||
} yield Void
|
} yield Void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*val bid = `@public` @: `@payable` @: ProductType(HNil).funcDef(
|
||||||
val bid = `@public` @: `@payable` @: ProductType(HNil).funcDef(
|
|
||||||
"bid",
|
"bid",
|
||||||
Void
|
Void
|
||||||
) { args ⇒
|
) { args ⇒
|
||||||
for {
|
for {
|
||||||
_ <- Free.pure(Void)
|
_ <- Free.pure(Void)
|
||||||
_ <- `assertt` (block.timestamp `<` auction_end)
|
_ <- `assertt`(block.timestamp `<` auction_end)
|
||||||
_ <- `assertt` (msg.value `>` highest_bid)
|
_ <- `assertt`(msg.value `>` highest_bid)
|
||||||
} yield Void
|
} yield Void
|
||||||
}
|
}*/
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user