diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedDoWhile.java b/src/main/java/de/maishai/typedast/typedclass/TypedDoWhile.java index 7a831d7..c95617f 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedDoWhile.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedDoWhile.java @@ -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); } } diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedWhile.java b/src/main/java/de/maishai/typedast/typedclass/TypedWhile.java index 6591278..8625a07 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedWhile.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedWhile.java @@ -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); } } diff --git a/src/main/resources/JavaTestfiles/ClassCanBeBytecoded.java b/src/main/resources/JavaTestfiles/ClassCanBeBytecoded.java index 05b5dcf..09d873d 100644 --- a/src/main/resources/JavaTestfiles/ClassCanBeBytecoded.java +++ b/src/main/resources/JavaTestfiles/ClassCanBeBytecoded.java @@ -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; } } \ No newline at end of file