Skip to content

Commit

Permalink
Construct: Computed with mandatory lambda and implemented SwitchType …
Browse files Browse the repository at this point in the history
…output
  • Loading branch information
GreyCat committed Mar 27, 2018
1 parent eb82243 commit d800654
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class ConstructClassCompiler(classSpecs: ClassSpecs, topClass: ClassSpec) extend
}

def compileValueInstance(id: Identifier, vis: ValueInstanceSpec): Unit = {
val typeStr = s"Computed(${translator.translate(vis.value)})"
val typeStr = s"Computed(lambda this: ${translator.translate(vis.value)})"
val typeStr2 = wrapWithIf(typeStr, vis.ifExpr)
out.puts(s"'${idToStr(id)}' / $typeStr2,")
}
Expand Down Expand Up @@ -163,6 +163,8 @@ class ConstructClassCompiler(classSpecs: ClassSpecs, topClass: ClassSpec) extend
}
case et: EnumType =>
s"${enumToStr(et.enumSpec.get)}(${typeToStr(et.basedOn)})"
case st: SwitchType =>
attrSwitchType(st)
case _ => "???"
}

Expand Down Expand Up @@ -190,6 +192,13 @@ class ConstructClassCompiler(classSpecs: ClassSpecs, topClass: ClassSpec) extend
s"consume=${translator.doBoolLiteral(btt.consume)})"
}

def attrSwitchType(st: SwitchType): String = {
s"Switch(${translator.translate(st.on)}, {" +
st.cases.map { case (caseExpr, caseType) =>
s"${translator.translate(caseExpr)}: ${typeToStr(caseType)}, "
}.mkString + "})"
}

def signToStr(signed: Boolean) = if (signed) "s" else "u"

def fixedEndianToStr(e: FixedEndian) = e match {
Expand Down

0 comments on commit d800654

Please sign in to comment.