fix: fixed implementation of if statement code gen

This commit is contained in:
Guy C 2025-02-26 01:10:14 +00:00
parent f76b7a9dc2
commit 9ca50540e6
2 changed files with 5 additions and 13 deletions

View File

@ -166,8 +166,8 @@ object asmGenerator {
val endLabel = labelGenerator.getLabel()
chain ++= evalExprOntoStack(cond)
chain += Compare(stack.head(SizeDir.Word), ImmediateVal(0))
chain += stack.drop()
chain += stack.pop(RAX)
chain += Compare(RAX, ImmediateVal(0))
chain += Jump(LabelArg(elseLabel), Cond.Equal)
chain ++= thenBranch.foldMap(generateStmt)
@ -183,8 +183,8 @@ object asmGenerator {
chain += LabelDef(startLabel)
chain ++= evalExprOntoStack(cond)
chain += Compare(stack.head(SizeDir.Word), ImmediateVal(0))
chain += stack.drop()
chain += stack.pop(RAX)
chain += Compare(RAX, ImmediateVal(0))
chain += Jump(LabelArg(endLabel), Cond.Equal)
chain ++= body.foldMap(generateStmt)
@ -251,20 +251,12 @@ object asmGenerator {
chain += stack.push(RAX)
case BinaryOperator.Div =>
// chain += stack.pop(RDX)
// chain += stack.pop(RAX)
// chain += stack.push(RDX)
// chain += stack.push(RAX)
chain += CDQ()
chain += Divide(stack.head(SizeDir.Word))
chain += stack.drop()
chain += stack.push(RAX)
case BinaryOperator.Mod =>
// chain += stack.pop(RDX)
// chain += stack.pop(RAX)
// chain += stack.push(RDX)
// chain += stack.push(RAX)
chain += CDQ()
chain += Divide(stack.head(SizeDir.Word))
chain += stack.drop()

View File

@ -92,7 +92,7 @@ class ParallelExamplesSpec extends AnyFlatSpec with BeforeAndAfterAll with Paral
"^.*wacc-examples/valid/expressions.*$",
"^.*wacc-examples/valid/function/nested_functions.*$",
"^.*wacc-examples/valid/function/simple_functions.*$",
"^.*wacc-examples/valid/if.*$",
// "^.*wacc-examples/valid/if.*$",
"^.*wacc-examples/valid/IO/print.*$",
// "^.*wacc-examples/valid/IO/read.*$",
"^.*wacc-examples/valid/IO/IOLoop.wacc.*$",