fix: copy whole register on assignment

This commit is contained in:
2025-02-28 18:41:31 +00:00
parent 578a28a222
commit 37812fb5a7

View File

@@ -161,15 +161,15 @@ object asmGenerator {
labelGenerator: LabelGenerator
): Chain[AsmLine] = {
var asm = Chain.empty[AsmLine]
asm += Comment(stmt.toString)
stmt match {
case Assign(lhs, rhs) =>
lhs match {
case ident: Ident =>
if (!stack.contains(ident)) asm += stack.reserve(ident)
val dest = Register(ident.ty.size, AX)
asm ++= evalExprOntoStack(rhs)
asm += stack.pop(RAX)
asm += Move(stack.accessVar(ident), dest)
asm += Move(stack.accessVar(ident).copy(opSize = Some(Size.Q64)), RAX)
case ArrayElem(x, i) =>
asm ++= evalExprOntoStack(rhs)
asm ++= evalExprOntoStack(i)