mirror of
https://github.com/fluencelabs/hackethberlin
synced 2025-04-25 09:22:21 +00:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
275fcfd25c
@ -11,7 +11,7 @@ sealed trait CodeChunk {
|
|||||||
|
|
||||||
case class CodeBlock(lines: Queue[String]) extends CodeChunk {
|
case class CodeBlock(lines: Queue[String]) extends CodeChunk {
|
||||||
override def toVyper(indent: Int): String =
|
override def toVyper(indent: Int): String =
|
||||||
lines.mkString(CodeChunk.spaces(indent), ";\n" + CodeChunk.spaces(indent), ";\n")
|
lines.mkString(CodeChunk.spaces(indent), "\n" + CodeChunk.spaces(indent), "\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
case class CodeLine(line: String) extends CodeChunk {
|
case class CodeLine(line: String) extends CodeChunk {
|
||||||
|
9
core/src/main/scala/fluence/hackethberlin/Contract.scala
Normal file
9
core/src/main/scala/fluence/hackethberlin/Contract.scala
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package fluence.hackethberlin
|
||||||
|
|
||||||
|
import fluence.hackethberlin.types.DataVyper
|
||||||
|
import shapeless.HList
|
||||||
|
|
||||||
|
class Contract[D <: HList](instructions: D)(implicit dv: DataVyper[D]) {
|
||||||
|
def toVyper: String =
|
||||||
|
dv.toVyperDefinitions(instructions).mkString("\n")
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package fluence.hackethberlin.types
|
package fluence.hackethberlin.types
|
||||||
|
|
||||||
|
import fluence.hackethberlin.{FuncDef, types}
|
||||||
import shapeless._
|
import shapeless._
|
||||||
import shapeless.labelled.FieldType
|
import shapeless.labelled.FieldType
|
||||||
import shapeless.tag._
|
import shapeless.tag._
|
||||||
@ -28,6 +29,19 @@ sealed trait LowPriorityDataVyperImplicits {
|
|||||||
override def toVyperDefinitions(data: FieldType[K, V]): List[String] =
|
override def toVyperDefinitions(data: FieldType[K, V]): List[String] =
|
||||||
s"${wk.value.name}: ${data.toVyper}" :: Nil
|
s"${wk.value.name}: ${data.toVyper}" :: Nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
implicit def productTypeDataVyper[D <: HList]: DataVyper[ProductType[D]] =
|
||||||
|
new DataVyper[ProductType[D]] {
|
||||||
|
override def toVyperDefinitions(data: ProductType[D]): List[String] =
|
||||||
|
data.toDataVyper :: Nil
|
||||||
|
}
|
||||||
|
|
||||||
|
implicit def funcDefDataVyper[Args <: HList, Ret <: types.Type]: DataVyper[FuncDef[Args, Ret]] =
|
||||||
|
new DataVyper[FuncDef[Args, Ret]] {
|
||||||
|
override def toVyperDefinitions(func: FuncDef[Args, Ret]): List[String] =
|
||||||
|
func.toVyper :: Nil
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
object DataVyper extends LowPriorityDataVyperImplicits {
|
object DataVyper extends LowPriorityDataVyperImplicits {
|
||||||
|
@ -46,18 +46,20 @@ object MakeVyperApp extends App {
|
|||||||
|
|
||||||
import Expr.Defs._
|
import Expr.Defs._
|
||||||
|
|
||||||
println(
|
val f = `@public` @:
|
||||||
(
|
sumArgs.funcDef("sum", uint256) { args ⇒
|
||||||
`@public` @:
|
for {
|
||||||
sumArgs.funcDef("sum", uint256) { args ⇒
|
c ← 'c :=: `++`(args.ref('a), args.ref('b))
|
||||||
for {
|
d ← 'd :=: `++`(args.ref('b), c)
|
||||||
c ← 'c :=: `++`(args.ref('a), args.ref('b))
|
sum ← `++`(args.ref('a), d).toReturn
|
||||||
d ← 'd :=: `++`(args.ref('b), c)
|
} yield sum
|
||||||
sum ← `++`(args.ref('a), d).toReturn
|
}
|
||||||
} yield sum
|
|
||||||
}
|
val all = recordStruct :: data :: func :: f :: HNil
|
||||||
).toVyper
|
|
||||||
)
|
val c = new Contract(recordStruct :: struct :: data :: func :: f :: HNil)
|
||||||
|
|
||||||
|
println(c.toVyper)
|
||||||
|
|
||||||
println(
|
println(
|
||||||
func(recordStruct.ref('record_address) :: HNil).toVyper
|
func(recordStruct.ref('record_address) :: HNil).toVyper
|
||||||
|
Loading…
x
Reference in New Issue
Block a user