mirror of
https://github.com/fluencelabs/hackethberlin
synced 2025-04-24 17:02:18 +00:00
Void type
This commit is contained in:
parent
27740833d5
commit
c4411d879d
@ -3,15 +3,33 @@ package fluence.hackethberlin
|
||||
import fluence.hackethberlin.types.DataVyper
|
||||
import shapeless._
|
||||
|
||||
class FuncDef[Args <: HList: DataVyper](
|
||||
class FuncDef[Args <: HList: DataVyper, Ret <: types.Type](
|
||||
name: String,
|
||||
argsDef: Args,
|
||||
ret: Option[Ret],
|
||||
decorators: Set[Decorator] = Set.empty
|
||||
) {
|
||||
|
||||
def toVyper: String =
|
||||
s"${decorators.map(_.toVyper).mkString("\n")}\ndef $name(${DataVyper[Args].mkString(argsDef, ", ")}):\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] =
|
||||
new FuncDef[Args, Ret](name, argsDef, ret, decorators + decorator)
|
||||
}
|
||||
|
||||
object FuncDef {
|
||||
def apply[Args <: HList : DataVyper, Ret <: types.Type](
|
||||
name: String,
|
||||
argsDef: Args,
|
||||
ret: Ret
|
||||
): FuncDef[Args, Ret] =
|
||||
new FuncDef(name, argsDef, Some(ret))
|
||||
|
||||
|
||||
def apply[Args <: HList : DataVyper](
|
||||
name: String,
|
||||
argsDef: Args
|
||||
): FuncDef[Args, types.Void] =
|
||||
new FuncDef(name, argsDef, None)
|
||||
|
||||
def @:(decorator: Decorator): FuncDef[Args] =
|
||||
new FuncDef[Args](name, argsDef, decorators + decorator)
|
||||
}
|
@ -22,9 +22,10 @@ object MakeVyperApp extends App {
|
||||
("struct2" → struct) :: HNil
|
||||
)
|
||||
|
||||
val func = new FuncDef(
|
||||
val func = FuncDef(
|
||||
"myFunc",
|
||||
("address" → address) :: HNil
|
||||
("address" → address) :: HNil,
|
||||
uint256
|
||||
)
|
||||
|
||||
println(data.toVyper)
|
||||
|
8
src/main/scala/fluence/hackethberlin/types/Void.scala
Normal file
8
src/main/scala/fluence/hackethberlin/types/Void.scala
Normal file
@ -0,0 +1,8 @@
|
||||
package fluence.hackethberlin.types
|
||||
|
||||
sealed trait Void extends Type
|
||||
|
||||
// TODO: should it exist as an instance?
|
||||
case object Void extends Type {
|
||||
override def toVyper: String = ""
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user