implements PR-19.7 explicit backend globals and synthetic callable model

This commit is contained in:
2026-03-26 19:31:21 +00:00
parent 7fc38010a2
commit c61b9db786
8 changed files with 238 additions and 0 deletions
@@ -2,6 +2,7 @@ package p.studio.compiler.pbs;
import org.junit.jupiter.api.Test;
import p.studio.compiler.messages.HostAdmissionContext;
import p.studio.compiler.models.IRSyntheticCallableKind;
import p.studio.compiler.models.SourceKind;
import p.studio.compiler.pbs.lexer.LexErrors;
import p.studio.compiler.pbs.semantics.PbsSemanticsErrors;
@@ -40,6 +41,33 @@ class PbsFrontendCompilerTest {
assertEquals(1, functions.get(1).parameterCount());
}
@Test
void shouldExposeGlobalsAndSyntheticLifecycleArtifactsInBackendFile() {
final var source = """
declare global SCORE: int = 0;
[Init]
fn boot() -> void { return; }
[Frame]
fn frame() -> void { return; }
""";
final var diagnostics = DiagnosticSink.empty();
final var compiler = new PbsFrontendCompiler();
final var fileBackend = compiler.compileFile(new FileId(1), source, diagnostics);
assertTrue(diagnostics.isEmpty(), diagnostics.stream().map(d -> d.getCode() + ":" + d.getMessage()).toList().toString());
assertEquals(1, fileBackend.globals().size());
assertEquals("SCORE", fileBackend.globals().getFirst().name());
assertEquals(4, fileBackend.syntheticFunctions().size());
assertTrue(fileBackend.syntheticFunctions().stream().anyMatch(fn -> fn.kind() == IRSyntheticCallableKind.FILE_INIT_FRAGMENT));
assertTrue(fileBackend.syntheticFunctions().stream().anyMatch(fn -> fn.kind() == IRSyntheticCallableKind.MODULE_INIT));
assertTrue(fileBackend.syntheticFunctions().stream().anyMatch(fn -> fn.kind() == IRSyntheticCallableKind.PROJECT_INIT));
assertTrue(fileBackend.syntheticFunctions().stream().anyMatch(fn -> fn.kind() == IRSyntheticCallableKind.PUBLISHED_FRAME_WRAPPER));
assertTrue(fileBackend.syntheticFunctions().stream().allMatch(fn -> !fn.origin().anchorCallableName().isBlank()));
}
@Test
void shouldReportDuplicateFunctionNames() {
final var source = """