mirror of
https://github.com/fluencelabs/hackethberlin
synced 2025-04-24 17:02:18 +00:00
summirizing contract
This commit is contained in:
parent
f4d186dfa9
commit
20e554658f
@ -11,7 +11,7 @@ sealed trait CodeChunk {
|
||||
|
||||
case class CodeBlock(lines: Queue[String]) extends CodeChunk {
|
||||
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 {
|
||||
|
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
|
||||
|
||||
import fluence.hackethberlin.{FuncDef, types}
|
||||
import shapeless._
|
||||
import shapeless.labelled.FieldType
|
||||
import shapeless.tag._
|
||||
@ -28,6 +29,19 @@ sealed trait LowPriorityDataVyperImplicits {
|
||||
override def toVyperDefinitions(data: FieldType[K, V]): List[String] =
|
||||
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 {
|
||||
|
@ -46,17 +46,19 @@ object MakeVyperApp extends App {
|
||||
|
||||
import Expr.Defs._
|
||||
|
||||
println(
|
||||
(
|
||||
`@public` @:
|
||||
sumArgs.funcDef("sum", uint256) { args ⇒
|
||||
for {
|
||||
c ← 'c :=: `++`(args.ref('a), args.ref('b))
|
||||
d ← 'd :=: `++`(args.ref('b), c)
|
||||
sum ← `++`(args.ref('a), d).toReturn
|
||||
} yield sum
|
||||
}
|
||||
).toVyper
|
||||
)
|
||||
val f = `@public` @:
|
||||
sumArgs.funcDef("sum", uint256) { args ⇒
|
||||
for {
|
||||
c ← 'c :=: `++`(args.ref('a), args.ref('b))
|
||||
d ← 'd :=: `++`(args.ref('b), c)
|
||||
sum ← `++`(args.ref('a), d).toReturn
|
||||
} yield sum
|
||||
}
|
||||
|
||||
val all = recordStruct :: data :: func :: f :: HNil
|
||||
|
||||
val c = new Contract(recordStruct :: struct :: data :: func :: f :: HNil)
|
||||
|
||||
println(c.toVyper)
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user