added fragments

This commit is contained in:
2026-03-27 22:35:09 +00:00
parent 19a0312753
commit 456b332d74
4 changed files with 49 additions and 46 deletions
@@ -285,20 +285,29 @@ final class PbsExecutableBodyLowerer {
private boolean lowerForStatement(
final PbsAst.ForStatement forStatement,
final PbsExecutableLoweringContext context) {
final var iteratorSlot = context.declareLocalSlot(forStatement.iteratorName());
lowerExpression(forStatement.fromExpression(), context);
emitSetLocal(iteratorSlot, forStatement.span(), context);
final var loopStart = context.nextLabel("for_start");
final var loopExit = context.nextLabel("for_exit");
final var loopContinue = context.nextLabel("for_continue");
emitLabel(loopStart, forStatement.span(), context);
emitGetLocal(iteratorSlot, forStatement.span(), context);
lowerExpression(forStatement.untilExpression(), context);
emitBinaryOperatorInstruction("<", forStatement.span(), context);
emitJump(IRBackendExecutableFunction.InstructionKind.JMP_IF_FALSE, loopExit, forStatement.span(), context);
context.pushLoop(loopContinue, loopExit);
lowerBlock(forStatement.body(), context);
context.popLoop();
emitLabel(loopContinue, forStatement.span(), context);
emitGetLocal(iteratorSlot, forStatement.span(), context);
if (forStatement.stepExpression() != null) {
lowerExpression(forStatement.stepExpression(), context);
} else {
emitPushI32(1, forStatement.span(), context);
}
emitBinaryOperatorInstruction("+", forStatement.span(), context);
emitSetLocal(iteratorSlot, forStatement.span(), context);
emitJump(IRBackendExecutableFunction.InstructionKind.JMP, loopStart, forStatement.span(), context);
emitLabel(loopExit, forStatement.span(), context);
return false;