mirror of
https://github.com/fluencelabs/hackethberlin
synced 2025-04-24 17:02:18 +00:00
DataDef removed
This commit is contained in:
parent
1165c9a8fc
commit
8f2a329f73
@ -19,6 +19,7 @@ scalacOptions += "-Ypartial-unification"
|
||||
|
||||
libraryDependencies ++= Seq(
|
||||
"org.typelevel" %% "cats-core" % "1.2.0",
|
||||
"org.typelevel" %% "cats-free" % "1.2.0",
|
||||
"com.chuusai" %% "shapeless" % "2.3.3",
|
||||
"org.scalatest" %% "scalatest" % "3.0.5" % Test
|
||||
)
|
@ -1,8 +0,0 @@
|
||||
package fluence.hackethberlin
|
||||
|
||||
import fluence.hackethberlin.types.DataVyper
|
||||
import shapeless.HList
|
||||
|
||||
class DataDef[D <: HList](dataDef: D)(implicit dv: DataVyper[D]) {
|
||||
def toVyper: String = dv.toVyperDefinitions(dataDef).mkString("\n")
|
||||
}
|
@ -1,19 +1,18 @@
|
||||
package fluence.hackethberlin
|
||||
|
||||
import fluence.hackethberlin.types.{DataVyper, StructType}
|
||||
import fluence.hackethberlin.types.{DataVyper, ProductType}
|
||||
import shapeless._
|
||||
|
||||
class FuncDef[Args <: HList: DataVyper, Ret <: types.Type](
|
||||
name: String,
|
||||
argsDef: Args,
|
||||
ret: Option[Ret],
|
||||
body: StructType[Args] ⇒ Expr[Ret],
|
||||
decorators: Set[Decorator] = Set.empty
|
||||
class FuncDef[Args <: HList, Ret <: types.Type](
|
||||
name: String,
|
||||
argsDef: ProductType[Args],
|
||||
ret: Option[Ret],
|
||||
body: ProductType[Args] ⇒ Expr[Ret],
|
||||
decorators: Set[Decorator] = Set.empty
|
||||
) {
|
||||
|
||||
def toVyper: String =
|
||||
s"${decorators.map(_.toVyper).mkString("\n")}\ndef $name(${DataVyper[Args]
|
||||
.mkString(argsDef, ", ")})${ret.fold("")(" -> " + _.toVyper)}:\n${body(new StructType[Args](argsDef)).toVyper(1)};\n"
|
||||
s"${decorators.map(_.toVyper).mkString("\n")}\ndef $name(${argsDef.toArgsVyper})${ret.fold("")(" -> " + _.toVyper)}:\n${body(argsDef).toVyper(1)};\n"
|
||||
|
||||
def @:(decorator: Decorator): FuncDef[Args, Ret] =
|
||||
new FuncDef[Args, Ret](name, argsDef, ret, body, decorators + decorator)
|
||||
@ -25,13 +24,13 @@ object FuncDef {
|
||||
name: String,
|
||||
argsDef: Args,
|
||||
ret: Ret
|
||||
)(body: StructType[Args] ⇒ Expr.Return[Ret]): FuncDef[Args, Ret] =
|
||||
new FuncDef(name, argsDef, Some(ret), body)
|
||||
)(body: ProductType[Args] ⇒ Expr.Return[Ret]): FuncDef[Args, Ret] =
|
||||
new FuncDef(name, ProductType(argsDef), Some(ret), body)
|
||||
|
||||
def apply[Args <: HList: DataVyper](
|
||||
name: String,
|
||||
argsDef: Args
|
||||
)(body: StructType[Args] ⇒ Expr[types.Void]): FuncDef[Args, types.Void] =
|
||||
new FuncDef(name, argsDef, None, body)
|
||||
)(body: ProductType[Args] ⇒ Expr[types.Void]): FuncDef[Args, types.Void] =
|
||||
new FuncDef(name, ProductType(argsDef), None, body)
|
||||
|
||||
}
|
||||
|
@ -7,14 +7,14 @@ import syntax.singleton._
|
||||
|
||||
object MakeVyperApp extends App {
|
||||
|
||||
val struct = new StructType(
|
||||
val struct = ProductType(
|
||||
('address ->> address) ::
|
||||
('owner ->> address) ::
|
||||
('size ->> uint256) ::
|
||||
('time ->> int128) :: HNil
|
||||
)
|
||||
|
||||
val data = new DataDef(
|
||||
val data = ProductType(
|
||||
('address ->> address) ::
|
||||
('owner ->> `public`(address)) ::
|
||||
('holders ->> (address ~>> bool)) ::
|
||||
@ -29,7 +29,7 @@ object MakeVyperApp extends App {
|
||||
address
|
||||
)(args ⇒ args.ref('addr).toReturn)
|
||||
|
||||
val recordStruct = new StructType(
|
||||
val recordStruct = ProductType(
|
||||
('record_address ->> address) :: ('other_some ->> uint256) :: HNil
|
||||
)
|
||||
|
||||
@ -37,7 +37,7 @@ object MakeVyperApp extends App {
|
||||
|
||||
println(recordStruct.toVyper)
|
||||
|
||||
println(data.toVyper)
|
||||
println(data.toDataVyper)
|
||||
|
||||
println(func.toVyper)
|
||||
|
||||
|
32
src/main/scala/fluence/hackethberlin/types/ProductType.scala
Normal file
32
src/main/scala/fluence/hackethberlin/types/ProductType.scala
Normal file
@ -0,0 +1,32 @@
|
||||
package fluence.hackethberlin.types
|
||||
|
||||
import fluence.hackethberlin.{Expr, FuncDef}
|
||||
import shapeless.{HList, Witness}
|
||||
import shapeless.ops.record.Selector
|
||||
|
||||
class ProductType[D <: HList](dataDef: D, dv: DataVyper[D]) extends Type {
|
||||
|
||||
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)
|
||||
|
||||
// type in type definition somewhere
|
||||
override def toVyper: String =
|
||||
s"{${dv.toVyperDefinitions(dataDef).mkString(", ")}}"
|
||||
|
||||
// contract data definition
|
||||
def toDataVyper: String =
|
||||
dv.toVyperDefinitions(dataDef).mkString("\n")
|
||||
|
||||
// function arguments
|
||||
def toArgsVyper: String =
|
||||
dv.toVyperDefinitions(dataDef).mkString(", ")
|
||||
|
||||
def funcDef[Ret <: Type](name: String, ret: Ret)(body: ProductType[D] ⇒ Expr.Return[Ret]): FuncDef[D, Ret] =
|
||||
new FuncDef[D, Ret](name, this, Some(ret), body)
|
||||
|
||||
}
|
||||
|
||||
object ProductType {
|
||||
def apply[D <: HList](dataDef: D)(implicit dv: DataVyper[D]): ProductType[D] =
|
||||
new ProductType[D](dataDef, dv)
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
package fluence.hackethberlin.types
|
||||
|
||||
import fluence.hackethberlin.Expr
|
||||
import shapeless.{HList, Witness}
|
||||
import shapeless.ops.record.Selector
|
||||
|
||||
class StructType[D <: HList](dataDef: D)(implicit dv: DataVyper[D]) extends Type {
|
||||
|
||||
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)
|
||||
|
||||
override def toVyper: String =
|
||||
s"{${dv.toVyperDefinitions(dataDef).mkString(", ")}}"
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user