Void type

This commit is contained in:
alari 2018-09-08 12:03:18 +02:00
parent 27740833d5
commit c4411d879d
3 changed files with 33 additions and 6 deletions

View File

@ -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] =
new FuncDef[Args](name, argsDef, decorators + decorator)
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)
}

View File

@ -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)

View 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 = ""
}