Skip to content

Commit 2b9e868

Browse files
committed
Feature(compiler): Support break label in DoStatement
1 parent cb31b0d commit 2b9e868

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

src/backend/llvm/code-generation/do-statement.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,15 @@ export class DoStatementGenerator implements NodeGenerateInterface<ts.DoStatemen
1616
const next = llvm.BasicBlock.create(ctx.llvmContext);
1717
ctx.scope.enclosureFunction.llvmFunction.addBasicBlock(next);
1818

19+
ctx.scope.breakBlock = next;
20+
1921
builder.createBr(positiveBlock);
2022
builder.setInsertionPoint(positiveBlock);
2123

2224
passStatement(<any>node.statement, ctx, builder);
2325

26+
ctx.scope.continueBlock = null;
27+
2428
builder.createBr(conditionBlock);
2529
builder.setInsertionPoint(conditionBlock);
2630

tests/snapshots/math/do.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,23 @@
1212
return total;
1313
}
1414

15+
function simpleBreak(): number {
16+
let total: number = 0;
17+
let i: number = 0;
18+
19+
do {
20+
total = total + i;
21+
i += 1;
22+
23+
if (i > 100) {
24+
break;
25+
}
26+
} while (true);
27+
28+
return total;
29+
}
30+
1531
calculateTotalFromRange(1, 100);
1632
calculateTotalFromRange(50, 100);
33+
simpleBreak();
1734
}

0 commit comments

Comments
 (0)