This commit is contained in:
404Simon 2024-05-20 20:24:00 +02:00
parent de4082eff3
commit cc68035406
2 changed files with 19 additions and 2 deletions

View File

@ -5,6 +5,8 @@ import de.maishai.typedast.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.objectweb.asm.Label;
import org.objectweb.asm.Opcodes;
import static de.maishai.typedast.Help.TypedExpressionHelp.convertExpression;
@ -42,6 +44,20 @@ public class TypedFor implements TypedStatement {
@Override
public void codeGen(MethodContext ctx) {
Label loopStart = new Label();
Label loopUpdate = new Label();
Label loopEnd = new Label();
assign.codeGen(ctx);
ctx.getMv().visitLabel(loopStart);
cond.codeGen(ctx);
ctx.getMv().visitJumpInsn(Opcodes.IFEQ, loopEnd);
ctx.popStack();
typedBlock.codeGen(ctx);
ctx.getMv().visitLabel(loopUpdate);
inc.codeGen(ctx);
ctx.getMv().visitJumpInsn(Opcodes.GOTO, loopStart);
ctx.getMv().visitLabel(loopEnd);
}
}

View File

@ -9,9 +9,10 @@ public class ClassCanBeBytecoded {
}
public int test(int var1) {
do {
int i;
for (i = 0; i < 12; i = i + 1) {
var1 = var1 + 1;
} while (var1 < 10);
}
return var1;
}
}