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
@@ -369,6 +369,37 @@ class PbsFrontendCompilerTest {
i.kind() == p.studio.compiler.models.IRBackendExecutableFunction.InstructionKind.JMP_IF_FALSE));
}
@Test
void shouldLowerForLoopIteratorBoundsAndStep() {
final var source = """
fn main() -> int {
let total: int = 0;
for i: int from 0 until 10 step 2 {
total += i;
}
return total;
}
""";
final var diagnostics = DiagnosticSink.empty();
final var compiler = new PbsFrontendCompiler();
final var fileBackend = compiler.compileFile(new FileId(102), source, diagnostics);
assertTrue(diagnostics.isEmpty(), diagnostics.stream().map(d -> d.getCode() + ":" + d.getMessage()).toList().toString());
final var executableMain = fileBackend.executableFunctions().stream()
.filter(fn -> fn.callableName().equals("main"))
.findFirst()
.orElseThrow();
assertTrue(executableMain.instructions().stream().anyMatch(i ->
i.kind() == p.studio.compiler.models.IRBackendExecutableFunction.InstructionKind.LT));
assertTrue(executableMain.instructions().stream().anyMatch(i ->
i.kind() == p.studio.compiler.models.IRBackendExecutableFunction.InstructionKind.ADD));
assertTrue(executableMain.instructions().stream().anyMatch(i ->
i.kind() == p.studio.compiler.models.IRBackendExecutableFunction.InstructionKind.SET_LOCAL));
assertTrue(executableMain.instructions().stream().anyMatch(i ->
i.kind() == p.studio.compiler.models.IRBackendExecutableFunction.InstructionKind.GET_LOCAL));
}
@Test
void shouldNotLowerWhenSyntaxErrorsExist() {
final var source = """