mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-12-27 08:38:03 +00:00
add while and do while
This commit is contained in:
parent
99ed3a322b
commit
de4082eff3
@ -3,6 +3,8 @@ package de.maishai.typedast.typedclass;
|
||||
import de.maishai.ast.records.*;
|
||||
import de.maishai.typedast.*;
|
||||
import lombok.Data;
|
||||
import org.objectweb.asm.Label;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
||||
import static de.maishai.typedast.Help.TypedExpressionHelp.convertExpression;
|
||||
|
||||
@ -33,6 +35,18 @@ public class TypedDoWhile implements TypedStatement {
|
||||
|
||||
@Override
|
||||
public void codeGen(MethodContext ctx) {
|
||||
Label loopStart = new Label();
|
||||
Label loopEnd = new Label();
|
||||
|
||||
ctx.getMv().visitLabel(loopStart);
|
||||
|
||||
typedBlock.codeGen(ctx);
|
||||
|
||||
cond.codeGen(ctx);
|
||||
|
||||
ctx.getMv().visitJumpInsn(Opcodes.IFNE, loopStart);
|
||||
ctx.popStack();
|
||||
|
||||
ctx.getMv().visitLabel(loopEnd);
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,9 @@ package de.maishai.typedast.typedclass;
|
||||
import de.maishai.ast.records.*;
|
||||
import de.maishai.typedast.*;
|
||||
import lombok.Data;
|
||||
import org.objectweb.asm.Label;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
||||
|
||||
import static de.maishai.typedast.Help.TypedExpressionHelp.convertExpression;
|
||||
|
||||
@ -33,6 +36,16 @@ public class TypedWhile implements TypedStatement {
|
||||
|
||||
@Override
|
||||
public void codeGen(MethodContext ctx) {
|
||||
Label loopStart = new Label();
|
||||
Label loopEnd = new Label();
|
||||
|
||||
ctx.getMv().visitLabel(loopStart);
|
||||
cond.codeGen(ctx);
|
||||
|
||||
ctx.getMv().visitJumpInsn(Opcodes.IFEQ, loopEnd);
|
||||
ctx.popStack();
|
||||
typedBlock.codeGen(ctx);
|
||||
ctx.getMv().visitJumpInsn(Opcodes.GOTO, loopStart);
|
||||
ctx.getMv().visitLabel(loopEnd);
|
||||
}
|
||||
}
|
||||
|
@ -9,8 +9,9 @@ public class ClassCanBeBytecoded {
|
||||
}
|
||||
|
||||
public int test(int var1) {
|
||||
int i;
|
||||
i = this.c.c.callable();
|
||||
return i;
|
||||
do {
|
||||
var1 = var1 + 1;
|
||||
} while (var1 < 10);
|
||||
return var1;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user