feat: generate microWacc for printing booleans

This commit is contained in:
Gleb Koval 2025-02-26 19:14:12 +00:00
parent 16de964f74
commit 4fb399a5e1
Signed by: cyclane
GPG Key ID: 15E168A8B332382C
2 changed files with 26 additions and 13 deletions

View File

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

View File

@ -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.*$",