mirror of
https://github.com/fluencelabs/hackethberlin
synced 2025-04-25 17:32:16 +00:00
trying to get from struct type
This commit is contained in:
parent
aa725a41ba
commit
f759c64868
@ -11,25 +11,26 @@ class FuncDef[Args <: HList: DataVyper, Ret <: types.Type](
|
|||||||
) {
|
) {
|
||||||
|
|
||||||
def toVyper: String =
|
def toVyper: String =
|
||||||
s"${decorators.map(_.toVyper).mkString("\n")}\ndef $name(${DataVyper[Args].mkString(argsDef, ", ")})${ret.fold("")(" -> "+_.toVyper)}:\n body;\n"
|
s"${decorators.map(_.toVyper).mkString("\n")}\ndef $name(${DataVyper[Args]
|
||||||
|
.mkString(argsDef, ", ")})${ret.fold("")(" -> " + _.toVyper)}:\n body;\n"
|
||||||
|
|
||||||
def @:(decorator: Decorator): FuncDef[Args, Ret] =
|
def @:(decorator: Decorator): FuncDef[Args, Ret] =
|
||||||
new FuncDef[Args, Ret](name, argsDef, ret, decorators + decorator)
|
new FuncDef[Args, Ret](name, argsDef, ret, decorators + decorator)
|
||||||
}
|
}
|
||||||
|
|
||||||
object FuncDef {
|
object FuncDef {
|
||||||
def apply[Args <: HList : DataVyper, Ret <: types.Type](
|
|
||||||
name: String,
|
def apply[Args <: HList: DataVyper, Ret <: types.Type](
|
||||||
argsDef: Args,
|
name: String,
|
||||||
ret: Ret
|
argsDef: Args,
|
||||||
): FuncDef[Args, Ret] =
|
ret: Ret
|
||||||
|
): FuncDef[Args, Ret] =
|
||||||
new FuncDef(name, argsDef, Some(ret))
|
new FuncDef(name, argsDef, Some(ret))
|
||||||
|
|
||||||
|
def apply[Args <: HList: DataVyper](
|
||||||
def apply[Args <: HList : DataVyper](
|
name: String,
|
||||||
name: String,
|
argsDef: Args
|
||||||
argsDef: Args
|
): FuncDef[Args, types.Void] =
|
||||||
): FuncDef[Args, types.Void] =
|
|
||||||
new FuncDef(name, argsDef, None)
|
new FuncDef(name, argsDef, None)
|
||||||
|
|
||||||
}
|
}
|
@ -2,7 +2,9 @@ package fluence.hackethberlin
|
|||||||
|
|
||||||
import shapeless._
|
import shapeless._
|
||||||
import types._
|
import types._
|
||||||
|
import record._
|
||||||
import Decorator._
|
import Decorator._
|
||||||
|
import shapeless.labelled.FieldType
|
||||||
import syntax.singleton._
|
import syntax.singleton._
|
||||||
|
|
||||||
object MakeVyperApp extends App {
|
object MakeVyperApp extends App {
|
||||||
@ -36,6 +38,8 @@ object MakeVyperApp extends App {
|
|||||||
('record_address ->> address) :: ('other_some ->> uint256) :: HNil
|
('record_address ->> address) :: ('other_some ->> uint256) :: HNil
|
||||||
)
|
)
|
||||||
|
|
||||||
|
println(Console.RED + recordStruct.get('other_some) + Console.RESET)
|
||||||
|
|
||||||
println(recordStruct.toVyper)
|
println(recordStruct.toVyper)
|
||||||
|
|
||||||
println(data.toVyper)
|
println(data.toVyper)
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
package fluence.hackethberlin.types
|
package fluence.hackethberlin.types
|
||||||
|
|
||||||
import shapeless.HList
|
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 {
|
class StructType[D <: HList](dataDef: D)(implicit dv: DataVyper[D]) extends Type {
|
||||||
|
def get(k: Witness)(implicit selector : Selector[D, k.T], ev: k.T <:< Type): Expr.Ref[k.T] =
|
||||||
|
Expr.Ref[k.T]("field should be there")
|
||||||
|
|
||||||
override def toVyper: String = s"{${dv.toVyperDefinitions(dataDef).mkString(", ")}}"
|
override def toVyper: String = s"{${dv.toVyperDefinitions(dataDef).mkString(", ")}}"
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user