implements PR-19.8 published wrapper entrypoint lowering

This commit is contained in:
2026-03-26 19:38:58 +00:00
parent c61b9db786
commit 58c5ab26d7
5 changed files with 554 additions and 42 deletions
@@ -254,8 +254,69 @@ class PBSFrontendPhaseServiceTest {
BuildingIssueSink.empty());
assertTrue(diagnostics.isEmpty());
assertEquals("frame", irBackend.getEntryPointCallableName());
assertEquals(2, irBackend.getFunctions().size());
assertEquals(2, irBackend.getExecutableFunctions().size());
}
@Test
void shouldPublishSyntheticFrameWrapperAsEntrypointWhenLifecycleMarkersExist() throws IOException {
final var projectRoot = tempDir.resolve("project-lifecycle-wrapper");
final var sourceRoot = projectRoot.resolve("src");
final var modulePath = sourceRoot.resolve("game");
Files.createDirectories(modulePath);
final var sourceFile = modulePath.resolve("source.pbs");
final var modBarrel = modulePath.resolve("mod.barrel");
Files.writeString(sourceFile, """
declare global SCORE: int = 0;
[Init]
fn boot() -> void { return; }
[Frame]
fn frame() -> void { return; }
""");
Files.writeString(modBarrel, """
pub fn boot() -> void;
pub fn frame() -> void;
pub global SCORE;
""");
final var projectTable = new ProjectTable();
final var fileTable = new FileTable(1);
final var projectId = projectTable.register(ProjectDescriptor.builder()
.rootPath(projectRoot)
.name("core")
.version("1.0.0")
.sourceRoots(ReadOnlyList.wrap(List.of(sourceRoot)))
.build());
registerFile(projectId, projectRoot, sourceFile, fileTable);
registerFile(projectId, projectRoot, modBarrel, fileTable);
final var ctx = new FrontendPhaseContext(
projectTable,
fileTable,
new BuildStack(ReadOnlyList.wrap(List.of(projectId))));
final var diagnostics = DiagnosticSink.empty();
final var irBackend = new PBSFrontendPhaseService().compile(
ctx,
diagnostics,
LogAggregator.empty(),
BuildingIssueSink.empty());
assertTrue(diagnostics.isEmpty(), diagnostics.stream().map(d -> d.getCode() + ":" + d.getMessage()).toList().toString());
assertTrue(irBackend.getEntryPointCallableName().startsWith("__pbs.frame_wrapper$m"));
final var wrapper = irBackend.getExecutableFunctions().stream()
.filter(function -> irBackend.getEntryPointCallableName().equals(function.callableName()))
.findFirst()
.orElseThrow();
assertEquals(4, wrapper.instructions().size());
assertTrue(wrapper.instructions().get(0).calleeCallableName().startsWith("__pbs.module_init$m"));
assertTrue(wrapper.instructions().get(1).calleeCallableName().startsWith("__pbs.project_init$m"));
assertEquals("frame", wrapper.instructions().get(2).calleeCallableName());
assertEquals(p.studio.compiler.models.IRBackendExecutableFunction.InstructionKind.RET, wrapper.instructions().get(3).kind());
}
@Test