added fragments
This commit is contained in:
+9
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user