Compare commits
2 Commits
74e3cb8016
...
0fcea195de
Author | SHA1 | Date | |
---|---|---|---|
|
0fcea195de | ||
|
f2260c7a73 |
@ -45,17 +45,19 @@ public class IfElseStatement extends AbstractType implements IStatement{
|
||||
@Override
|
||||
public void codeGen(MethodVisitor mv, HashMap<String, String> localVars) throws Exception {
|
||||
|
||||
HashMap<String, String> blockLocalVars = new HashMap<>(localVars);
|
||||
|
||||
Label conditionFalse = new Label();
|
||||
Label statementEnd = new Label();
|
||||
|
||||
condition.codeGen(mv);
|
||||
|
||||
mv.visitJumpInsn(Opcodes.IFEQ, conditionFalse); //Checks if the condition is false (0)
|
||||
ifStatement.codeGen(mv); //If the condition is true, execute the ifBlock
|
||||
ifStatement.codeGen(mv, blockLocalVars); //If the condition is true, execute the ifBlock
|
||||
mv.visitJumpInsn(Opcodes.GOTO, statementEnd); //Jump to the end of the if-else statement
|
||||
|
||||
mv.visitLabel(conditionFalse);
|
||||
elseStatement.codeGen(mv); //If the condition is false, execute the elseBlock
|
||||
elseStatement.codeGen(mv, blockLocalVars); //If the condition is false, execute the elseBlock
|
||||
|
||||
mv.visitLabel(statementEnd); //End of the if-else statement
|
||||
|
||||
|
@ -38,12 +38,14 @@ public class IfStatement extends AbstractType implements IStatement{
|
||||
@Override
|
||||
public void codeGen(MethodVisitor mv, HashMap<String, String> localVars) throws Exception {
|
||||
|
||||
HashMap<String, String> blockLocalVars = new HashMap<>(localVars);
|
||||
|
||||
Label conditionFalse = new Label();
|
||||
|
||||
condition.codeGen(mv);
|
||||
|
||||
mv.visitJumpInsn(Opcodes.IFEQ, conditionFalse); //Checks if the condition is false (0)
|
||||
ifStatement.codeGen(mv);
|
||||
ifStatement.codeGen(mv, blockLocalVars);
|
||||
|
||||
mv.visitLabel(conditionFalse); // If the condition is false, the Statements in the ifBlock will not be executed
|
||||
}
|
||||
|
@ -36,6 +36,9 @@ public class WhileStatement extends AbstractType implements IStatement {
|
||||
|
||||
@Override
|
||||
public void codeGen(MethodVisitor mv, HashMap<String, String> localVars) throws Exception {
|
||||
|
||||
HashMap<String, String> blockLocalVars = new HashMap<>(localVars);
|
||||
|
||||
Label conditionFalse = new Label();
|
||||
Label LoopStart = new Label();
|
||||
|
||||
@ -44,7 +47,7 @@ public class WhileStatement extends AbstractType implements IStatement {
|
||||
condition.codeGen(mv);
|
||||
mv.visitJumpInsn(Opcodes.IFEQ, conditionFalse); // Checks if the condition is false (0)
|
||||
|
||||
statement.codeGen(mv);
|
||||
statement.codeGen(mv, blockLocalVars);
|
||||
//TODO: If the block ends with a return statement, we might have to pop it from the stack
|
||||
// So the next iteration starts with a clean stack
|
||||
mv.visitJumpInsn(Opcodes.GOTO, LoopStart); // Jump to the start of the while loop
|
||||
|
@ -51,6 +51,9 @@ public class AssignStatementExpression extends AbstractType implements IExpressi
|
||||
|
||||
@Override
|
||||
public void codeGen(MethodVisitor mv, HashMap<String, String> localVars) throws Exception {
|
||||
if (left instanceof VarRefExpression varRef) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user