Merge remote-tracking branch 'origin/master'

This commit is contained in:
alari 2018-09-09 08:48:24 +02:00
commit 1fb5d3060c
4 changed files with 63 additions and 21 deletions

View File

@ -48,6 +48,18 @@ object Expr {
override def toInlineVyper: String = toVyper
}
case class RightBody[R, T](
op: String,
right: InlineExpr[R],
boxedValue: T,
body: () Free[Expr, Void]
) extends InlineExpr[T] {
def bodyVyper: String =
body().foldMap(CodeChunk.fromExpr).run._1.toVyper(1)
override def toVyper: String = s"$op " + right.toVyper + s":\n$bodyVyper\n"
override def toInlineVyper: String = toVyper
}
case class Assign[T](ref: Ref[T], value: InlineExpr[T]) extends Expr[Ref[T]] {
override def boxedValue: Ref[T] = ref
@ -68,14 +80,14 @@ object Expr {
def `++`(a: InlineExpr[uint256.type], b: InlineExpr[uint256.type]): InlineExpr[uint256.type] =
Infix("+", a, b, uint256)
def `==`[A <: Type, B <: Type](a: InlineExpr[A], b: InlineExpr[B]): InlineExpr[bool.type] =
def `:===:`[A <: Type, B <: Type](a: InlineExpr[A], b: InlineExpr[B]): InlineExpr[bool.type] =
Infix("==", a, b, bool)
def `+:+`(a: InlineExpr[timestamp.type], b: InlineExpr[timedelta.type]): InlineExpr[timestamp.type] =
Infix("+", a, b, timestamp)
def `if`(expr: InlineExpr[bool.type]): InlineExpr[bool.type] =
Right("if", expr, bool)
def `if`(expr: InlineExpr[bool.type], body: () Free[Expr, Void]): InlineExpr[Void] =
Right("if", expr, Void)
def `not`(expr: InlineExpr[bool.type]): InlineExpr[bool.type] =
Right("not", expr, bool)
@ -83,10 +95,10 @@ object Expr {
def `assertt`(expr: InlineExpr[bool.type]): InlineExpr[bool.type] =
Right("assert", expr, bool)
def `<`[A <: Type, B <: Type](a: InlineExpr[A], b: InlineExpr[B]): InlineExpr[bool.type] =
def `<<`[A <: Type, B <: Type](a: InlineExpr[A], b: InlineExpr[B]): InlineExpr[bool.type] =
Infix("<", a, b, bool)
def `>`[A <: Type, B <: Type](a: InlineExpr[A], b: InlineExpr[B]): InlineExpr[bool.type] =
def `>>`[A <: Type, B <: Type](a: InlineExpr[A], b: InlineExpr[B]): InlineExpr[bool.type] =
Infix(">", a, b, bool)
}

View File

@ -2,11 +2,7 @@ package fluence.hackethberlin
import fluence.hackethberlin.types.{DataVyper, ProductType}
import shapeless._
import BasisConstraint._
import cats.free.Free
import shapeless.ops.hlist.{Mapped, ToList}
import shapeless.ops.record.{Keys, Selector, Values}
import shapeless.tag.@@
class FuncDef[Args <: HList, Ret <: types.Type, Params <: HList](
name: String,
@ -52,4 +48,17 @@ object FuncDef {
)(implicit values: ops.record.Values.Aux[Args, _Values]): FuncDef[Args, types.Void, mapped.Out] =
new FuncDef(name, ProductType(argsDef), types.Void, args body(args).map(_ types.Void))
import types._
import syntax.singleton._
val send = {
ProductType(('_addr ->> address) :: ('_money ->> wei_value) :: HNil).funcDef(
"send",
Void
) { args
for {
_ <- Free.pure(Void)
} yield Void
}
}
}

View File

@ -14,10 +14,6 @@ sealed trait DataVyper[T] {
sealed trait LowPriorityDataVyperImplicits {
implicit object hnilDataVyper extends DataVyper[HNil] {
override def toVyperDefinitions(data: HNil): List[String] = Nil
}
implicit def hlistDataVyper[H, T <: HList](implicit dh: DataVyper[H], dt: DataVyper[T]): DataVyper[H :: T] =
new DataVyper[H :: T] {
override def toVyperDefinitions(data: H :: T): List[String] =
@ -49,6 +45,10 @@ object DataVyper extends LowPriorityDataVyperImplicits {
def apply[T](implicit dataVyper: DataVyper[T]): DataVyper[T] = dataVyper
implicit object hnilDataVyper extends DataVyper[HNil] {
override def toVyperDefinitions(data: HNil): List[String] = Nil
}
implicit def pairDataIndexedVyper[K <: Symbol, T <: Type](
implicit wk: Witness.Aux[K]
): DataVyper[FieldType[K, T @@ Indexed]] =

View File

@ -5,6 +5,7 @@ import hackethberlin.types._
import shapeless._
import Decorator._
import cats.free.Free
import fluence.hackethberlin.Expr.Defs
import syntax.singleton._
object MakeVyperApp extends App {
@ -71,6 +72,18 @@ object MakeVyperApp extends App {
}
object Auction {
import Expr.Defs._
val predef = ProductType(
(Symbol("block.timestamp") ->> timestamp) ::
(Symbol("msg.value") ->> uint256) ::
(Symbol("msg.sender") ->> address) ::
HNil
)
val `block.timestamp` = predef.ref(Symbol("block.timestamp"))
val `msg.value` = predef.ref(Symbol("msg.value"))
val `msg.sender` = predef.ref(Symbol("msg.sender"))
val data = ProductType(
('beneficiary ->> public(address)) ::
@ -85,11 +98,10 @@ object Auction {
val auction_start = data.ref('auction_start)
val auction_end = data.ref('auction_end)
val highest_bid = data.ref('highest_bid)
val highest_bidder = data.ref('highest_bidder)
val initArgs = ProductType(('_beneficiary ->> address) :: ('_bidding_time ->> timedelta) :: HNil)
import untag._
val _beneficiary = initArgs.ref('_beneficiary)
val _bidding_time = initArgs.ref('_bidding_time)
@ -102,19 +114,28 @@ object Auction {
for {
_ <- Free.pure(Void)
_ <- beneficiary :=: _beneficiary
// _ <- auction_start :==: block.timestamp
// _ <- auction_end :==: auction_start `+:+` _bidding_time
_ <- auction_start :=: `block.timestamp`
// _ <- auction_end :=: `+:+`(auction_start, _bidding_time)
} yield Void
}
/*val bid = `@public` @: `@payable` @: ProductType(HNil).funcDef(
val bidIf: () Free[Expr, Void] = { () =>
for {
_ <- Free.pure(Void)
// _ <- FuncDef.send(highest_bidder :: highest_bid :: HNil)
} yield Void
}
/*val bid = `@public` @: `@payable` @: ProductType(HNil: HList).funcDef(
"bid",
Void
) { args
for {
_ <- Free.pure(Void)
_ <- `assertt`(block.timestamp `<` auction_end)
_ <- `assertt`(msg.value `>` highest_bid)
_ <- `assertt`(`block.timestamp` `<<` auction_end)
_ <- `assertt`(`msg.value` `>>` highest_bid)
_ <- `if`(`not`(highest_bid `:===:` `msg.value`), bidIf)
_ <- highest_bidder :=: `msg.sender`
_ <- highest_bid :=: `msg.value`
} yield Void
}*/
}