Fixing while

This commit is contained in:
Apoorva Ranade
2021-05-02 20:11:59 +05:30
parent ade63910b8
commit 54b792ba10
+2 -2
View File
@@ -718,13 +718,13 @@ public class CodeGenImpl extends CodeGenBase
{ {
Label startLoop = generateLocalLabel(); Label startLoop = generateLocalLabel();
backend.emitLocalLabel(startLoop, "Beginning of while loop"); backend.emitLocalLabel(startLoop, "Beginning of while loop");
node.condition.dispatch(this); Register result = node.condition.dispatch(this);
Label endLoop = elseBlock; Label endLoop = elseBlock;
backend.emitBEQZ(result, endLoop,"Jump to beginning of loop");
for(Stmt stmt:node.body) for(Stmt stmt:node.body)
stmt.dispatch(this); stmt.dispatch(this);
backend.emitJ(startLoop, "Jump to beginning of loop"); backend.emitJ(startLoop, "Jump to beginning of loop");
backend.emitLocalLabel(endLoop, "End of while loop"); backend.emitLocalLabel(endLoop, "End of while loop");
return null; return null;
} }