feat: generate microWacc for printing booleans
This commit is contained in:
parent
16de964f74
commit
4fb399a5e1
@ -216,21 +216,34 @@ object typeChecker {
|
|||||||
case ast.Print(expr, newline) =>
|
case ast.Print(expr, newline) =>
|
||||||
// This constraint should never fail, the scope-checker should have caught it already
|
// This constraint should never fail, the scope-checker should have caught it already
|
||||||
val exprTyped = checkValue(expr, Constraint.Unconstrained)
|
val exprTyped = checkValue(expr, Constraint.Unconstrained)
|
||||||
val format = exprTyped.ty match {
|
val exprFormat = exprTyped.ty match {
|
||||||
case KnownType.Bool | KnownType.String => "%s"
|
case KnownType.Bool | KnownType.String => "%s"
|
||||||
case KnownType.Char => "%c"
|
case KnownType.Char => "%c"
|
||||||
case KnownType.Int => "%d"
|
case KnownType.Int => "%d"
|
||||||
case _ => "%p"
|
case KnownType.Pair(_, _) | KnownType.Array(_) | ? => "%p"
|
||||||
}
|
}
|
||||||
|
val printfCall = { (value: microWacc.Expr) =>
|
||||||
List(
|
List(
|
||||||
microWacc.Call(
|
microWacc.Call(
|
||||||
microWacc.Builtin.Printf,
|
microWacc.Builtin.Printf,
|
||||||
List(
|
List(
|
||||||
s"$format${if newline then "\n" else ""}".toMicroWaccCharArray,
|
s"$exprFormat${if newline then "\n" else ""}".toMicroWaccCharArray,
|
||||||
exprTyped
|
value
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
exprTyped.ty match {
|
||||||
|
case KnownType.Bool =>
|
||||||
|
List(
|
||||||
|
microWacc.If(
|
||||||
|
exprTyped,
|
||||||
|
printfCall("true".toMicroWaccCharArray),
|
||||||
|
printfCall("false".toMicroWaccCharArray)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
case _ => printfCall(exprTyped)
|
||||||
|
}
|
||||||
case ast.If(cond, thenStmt, elseStmt) =>
|
case ast.If(cond, thenStmt, elseStmt) =>
|
||||||
List(
|
List(
|
||||||
microWacc.If(
|
microWacc.If(
|
||||||
|
@ -89,7 +89,7 @@ class ParallelExamplesSpec extends AnyFlatSpec with BeforeAndAfterAll {
|
|||||||
"^.*wacc-examples/valid/array.*$",
|
"^.*wacc-examples/valid/array.*$",
|
||||||
// "^.*wacc-examples/valid/basic/exit.*$",
|
// "^.*wacc-examples/valid/basic/exit.*$",
|
||||||
// "^.*wacc-examples/valid/basic/skip.*$",
|
// "^.*wacc-examples/valid/basic/skip.*$",
|
||||||
"^.*wacc-examples/valid/expressions.*$",
|
// "^.*wacc-examples/valid/expressions.*$",
|
||||||
"^.*wacc-examples/valid/function/nested_functions.*$",
|
"^.*wacc-examples/valid/function/nested_functions.*$",
|
||||||
"^.*wacc-examples/valid/function/simple_functions.*$",
|
"^.*wacc-examples/valid/function/simple_functions.*$",
|
||||||
// "^.*wacc-examples/valid/if.*$",
|
// "^.*wacc-examples/valid/if.*$",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user