While loop

This commit is contained in:
Apoorva Ranade
2021-04-28 15:32:07 +05:30
parent f92308238b
commit 1fb6f3f085
+14 -6
View File
@@ -381,7 +381,19 @@ public class CodeGenImpl extends CodeGenBase
{
return null;
}
@Override
public Void analyze(WhileStmt node)
{
Label startLoop = generateLocalLabel();
backend.emitLocalLabel(startLoop, "Beginning of while loop");
node.condition.dispatch(this);
Label endLoop = elseBlock;
for(Stmt stmt:node.body)
stmt.dispatch(this);
backend.emitJ(startLoop, "Jump to beginning of loop");
backend.emitLocalLabel(endLoop, "End of while loop");
return null;
}
@Override
public Void analyze(ForStmt node) {
// control flow
@@ -415,11 +427,7 @@ public class CodeGenImpl extends CodeGenBase
@Override
public Void analyze(WhileStmt node) {
// control flow
return defaultAction(node);
}
}
/**