Fixed Ifs
This commit is contained in:
@@ -415,8 +415,9 @@ public class CodeGenImpl extends CodeGenBase
|
|||||||
@Override
|
@Override
|
||||||
public Register analyze(IfExpr node)
|
public Register analyze(IfExpr node)
|
||||||
{
|
{
|
||||||
node.condition.dispatch(this);
|
Register result = node.condition.dispatch(this);
|
||||||
Label ln = generateLocalLabel();
|
Label ln = generateLocalLabel();
|
||||||
|
backend.emitBEQZ(result, ln,"Jump to beginning of loop");
|
||||||
node.thenExpr.dispatch(this);
|
node.thenExpr.dispatch(this);
|
||||||
backend.emitJ(ln, "Jump to end of if expression");
|
backend.emitJ(ln, "Jump to end of if expression");
|
||||||
backend.emitLocalLabel(elseBlock, "Else part of if expression");
|
backend.emitLocalLabel(elseBlock, "Else part of if expression");
|
||||||
@@ -428,8 +429,9 @@ public class CodeGenImpl extends CodeGenBase
|
|||||||
@Override
|
@Override
|
||||||
public Register analyze(IfStmt node)
|
public Register analyze(IfStmt node)
|
||||||
{
|
{
|
||||||
node.condition.dispatch(this);
|
Register result = node.condition.dispatch(this);
|
||||||
Label ln = generateLocalLabel();
|
Label ln = generateLocalLabel();
|
||||||
|
backend.emitBEQZ(result, ln,"Jump to beginning of loop");
|
||||||
for(Stmt s:node.thenBody)
|
for(Stmt s:node.thenBody)
|
||||||
s.dispatch(this);
|
s.dispatch(this);
|
||||||
backend.emitJ(ln, "Jump to end of if statement");
|
backend.emitJ(ln, "Jump to end of if statement");
|
||||||
|
|||||||
Reference in New Issue
Block a user