(fixes) test-projects main have to run

This commit is contained in:
2026-03-27 05:29:24 +00:00
parent e582527937
commit e905055cb0
15 changed files with 391 additions and 121 deletions
@@ -134,6 +134,59 @@ class PbsFrontendCompilerTest {
i.kind() == p.studio.compiler.models.IRBackendExecutableFunction.InstructionKind.CALL_FUNC));
}
@Test
void shouldLowerGlobalReadsAndWritesInExecutableBodies() {
final var source = """
declare global tile_id: int = 0;
fn tick() -> int {
tile_id = tile_id + 1;
if (tile_id > 7) {
tile_id = 0;
}
return tile_id;
}
""";
final var diagnostics = DiagnosticSink.empty();
final var compiler = new PbsFrontendCompiler();
final var fileBackend = compiler.compileFile(new FileId(46), source, diagnostics);
assertTrue(diagnostics.isEmpty(), diagnostics.stream().map(d -> d.getCode() + ":" + d.getMessage()).toList().toString());
final var executableTick = fileBackend.executableFunctions().stream()
.filter(fn -> fn.callableName().equals("tick"))
.findFirst()
.orElseThrow();
assertTrue(executableTick.instructions().stream().anyMatch(i ->
i.kind() == p.studio.compiler.models.IRBackendExecutableFunction.InstructionKind.GET_GLOBAL));
assertTrue(executableTick.instructions().stream().anyMatch(i ->
i.kind() == p.studio.compiler.models.IRBackendExecutableFunction.InstructionKind.SET_GLOBAL));
}
@Test
void shouldLowerUserConstIdentifiersInExecutableBodies() {
final var source = """
declare const MAX_FRAMES: int = 10;
fn tick(frame_counter: int) -> bool {
return frame_counter > MAX_FRAMES;
}
""";
final var diagnostics = DiagnosticSink.empty();
final var compiler = new PbsFrontendCompiler();
final var fileBackend = compiler.compileFile(new FileId(47), source, diagnostics);
assertTrue(diagnostics.isEmpty(), diagnostics.stream().map(d -> d.getCode() + ":" + d.getMessage()).toList().toString());
final var executableTick = fileBackend.executableFunctions().stream()
.filter(fn -> fn.callableName().equals("tick"))
.findFirst()
.orElseThrow();
assertTrue(executableTick.instructions().stream().anyMatch(i ->
i.kind() == p.studio.compiler.models.IRBackendExecutableFunction.InstructionKind.PUSH_I32
&& "10".equals(i.label())));
}
@Test
void shouldClassifyCallableCallEvenWhenNameLooksHostLike() {
final var source = """
@@ -42,6 +42,28 @@ class PbsSemanticsAssignmentTest {
d.getCode().equals(PbsSemanticsErrors.E_SEM_FIELD_WRITE_ACCESS_DENIED.name())));
}
@Test
void shouldAllowGlobalAssignments() {
final var source = """
declare global tile_id: int = 0;
fn tick(next: int) -> int {
tile_id = tile_id + next;
return tile_id;
}
""";
final var diagnostics = DiagnosticSink.empty();
new PbsFrontendCompiler().compileFile(new FileId(0), source, diagnostics);
assertFalse(diagnostics.stream().anyMatch(d ->
d.getCode().equals(PbsSemanticsErrors.E_SEM_ASSIGN_TARGET_UNRESOLVED.name())));
assertFalse(diagnostics.stream().anyMatch(d ->
d.getCode().equals(PbsSemanticsErrors.E_SEM_ASSIGN_TARGET_NOT_ASSIGNABLE.name())));
assertFalse(diagnostics.stream().anyMatch(d ->
d.getCode().equals(PbsSemanticsErrors.E_SEM_ASSIGN_TYPE_MISMATCH.name())));
}
@Test
void shouldRejectUnresolvedImmutableAndTypeMismatchedAssignments() {
final var source = """
@@ -381,16 +381,18 @@ class PBSFrontendPhaseServiceTest {
.filter(function -> irBackend.getEntryPointCallableName().equals(function.callableName()))
.findFirst()
.orElseThrow();
assertEquals(9, wrapper.instructions().size());
assertEquals(11, wrapper.instructions().size());
assertEquals(p.studio.compiler.models.IRBackendExecutableFunction.InstructionKind.GET_GLOBAL, wrapper.instructions().get(0).kind());
assertEquals(p.studio.compiler.models.IRBackendExecutableFunction.InstructionKind.JMP_IF_TRUE, wrapper.instructions().get(1).kind());
assertTrue(wrapper.instructions().get(2).calleeCallableName().startsWith("__pbs.module_init$m"));
assertTrue(wrapper.instructions().get(3).calleeCallableName().startsWith("__pbs.project_init$m"));
assertEquals(p.studio.compiler.models.IRBackendExecutableFunction.InstructionKind.PUSH_BOOL, wrapper.instructions().get(4).kind());
assertEquals(p.studio.compiler.models.IRBackendExecutableFunction.InstructionKind.SET_GLOBAL, wrapper.instructions().get(5).kind());
assertEquals(p.studio.compiler.models.IRBackendExecutableFunction.InstructionKind.LABEL, wrapper.instructions().get(6).kind());
assertEquals("frame", wrapper.instructions().get(7).calleeCallableName());
assertEquals(p.studio.compiler.models.IRBackendExecutableFunction.InstructionKind.RET, wrapper.instructions().get(8).kind());
assertEquals(p.studio.compiler.models.IRBackendExecutableFunction.InstructionKind.PUSH_BOOL, wrapper.instructions().get(1).kind());
assertEquals(p.studio.compiler.models.IRBackendExecutableFunction.InstructionKind.EQ, wrapper.instructions().get(2).kind());
assertEquals(p.studio.compiler.models.IRBackendExecutableFunction.InstructionKind.JMP_IF_TRUE, wrapper.instructions().get(3).kind());
assertTrue(wrapper.instructions().get(4).calleeCallableName().startsWith("__pbs.module_init$m"));
assertTrue(wrapper.instructions().get(5).calleeCallableName().startsWith("__pbs.project_init$m"));
assertEquals(p.studio.compiler.models.IRBackendExecutableFunction.InstructionKind.PUSH_BOOL, wrapper.instructions().get(6).kind());
assertEquals(p.studio.compiler.models.IRBackendExecutableFunction.InstructionKind.SET_GLOBAL, wrapper.instructions().get(7).kind());
assertEquals(p.studio.compiler.models.IRBackendExecutableFunction.InstructionKind.LABEL, wrapper.instructions().get(8).kind());
assertEquals("frame", wrapper.instructions().get(9).calleeCallableName());
assertEquals(p.studio.compiler.models.IRBackendExecutableFunction.InstructionKind.RET, wrapper.instructions().get(10).kind());
}
@Test