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) =>
|
||||
// This constraint should never fail, the scope-checker should have caught it already
|
||||
val exprTyped = checkValue(expr, Constraint.Unconstrained)
|
||||
val format = exprTyped.ty match {
|
||||
case KnownType.Bool | KnownType.String => "%s"
|
||||
case KnownType.Char => "%c"
|
||||
case KnownType.Int => "%d"
|
||||
case _ => "%p"
|
||||
val exprFormat = exprTyped.ty match {
|
||||
case KnownType.Bool | KnownType.String => "%s"
|
||||
case KnownType.Char => "%c"
|
||||
case KnownType.Int => "%d"
|
||||
case KnownType.Pair(_, _) | KnownType.Array(_) | ? => "%p"
|
||||
}
|
||||
List(
|
||||
microWacc.Call(
|
||||
microWacc.Builtin.Printf,
|
||||
List(
|
||||
s"$format${if newline then "\n" else ""}".toMicroWaccCharArray,
|
||||
exprTyped
|
||||
val printfCall = { (value: microWacc.Expr) =>
|
||||
List(
|
||||
microWacc.Call(
|
||||
microWacc.Builtin.Printf,
|
||||
List(
|
||||
s"$exprFormat${if newline then "\n" else ""}".toMicroWaccCharArray,
|
||||
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) =>
|
||||
List(
|
||||
microWacc.If(
|
||||
|
@ -89,7 +89,7 @@ class ParallelExamplesSpec extends AnyFlatSpec with BeforeAndAfterAll {
|
||||
"^.*wacc-examples/valid/array.*$",
|
||||
// "^.*wacc-examples/valid/basic/exit.*$",
|
||||
// "^.*wacc-examples/valid/basic/skip.*$",
|
||||
"^.*wacc-examples/valid/expressions.*$",
|
||||
// "^.*wacc-examples/valid/expressions.*$",
|
||||
"^.*wacc-examples/valid/function/nested_functions.*$",
|
||||
"^.*wacc-examples/valid/function/simple_functions.*$",
|
||||
// "^.*wacc-examples/valid/if.*$",
|
||||
|
Loading…
x
Reference in New Issue
Block a user