packer & compiler test

This commit is contained in:
2026-03-24 13:42:56 +00:00
parent 3fbcb30dff
commit d7a26473c8
12 changed files with 339 additions and 7 deletions
@@ -28,7 +28,7 @@ declare host LowGfx {
[Host(module = "gfx", name = "set_sprite", version = 1)]
[Capability(name = "gfx")]
fn set_sprite(
asset_name: str,
bank_id: int,
index: int,
x: int,
y: int,
@@ -82,7 +82,7 @@ declare service Gfx
}
fn set_sprite(
asset_name: str,
bank_id: int,
index: int,
x: int,
y: int,
@@ -94,7 +94,7 @@ declare service Gfx
priority: int
) -> int
{
return LowGfx.set_sprite(asset_name, index, x, y, tile_id, palette_id, active, flip_x, flip_y, priority);
return LowGfx.set_sprite(bank_id, index, x, y, tile_id, palette_id, active, flip_x, flip_y, priority);
}
fn draw_text(x: int, y: int, message: str, color: Color) -> void
@@ -627,6 +627,57 @@ class PBSFrontendPhaseServiceTest {
assertTrue(irBackend.getExecutableFunctions().stream().anyMatch(function -> "frame".equals(function.callableName())));
}
@Test
void shouldLowerSdkGfxSetSpriteFacadeUsingBankIdContract() throws IOException {
final var projectRoot = tempDir.resolve("project-bootstrap-sdk-gfx-set-sprite");
final var sourceRoot = projectRoot.resolve("src");
final var modulePath = sourceRoot.resolve("app");
Files.createDirectories(modulePath);
final var sourceFile = modulePath.resolve("source.pbs");
final var modBarrel = modulePath.resolve("mod.barrel");
Files.writeString(sourceFile, """
import { Gfx } from @sdk:gfx;
fn frame() -> int
{
return Gfx.set_sprite(2, 0, 12, 18, 7, 3, true, false, true, 1);
}
""");
Files.writeString(modBarrel, "pub fn frame() -> int;");
final var projectTable = new ProjectTable();
final var fileTable = new FileTable(1);
final var projectId = projectTable.register(ProjectDescriptor.builder()
.rootPath(projectRoot)
.name("app")
.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))),
1);
final var diagnostics = DiagnosticSink.empty();
final var irBackend = new PBSFrontendPhaseService().compile(
ctx,
diagnostics,
LogAggregator.empty(),
BuildingIssueSink.empty());
assertTrue(diagnostics.stream().noneMatch(d ->
d.getCode().equals(PbsSemanticsErrors.E_SEM_EXEC_LOWERING_UNRESOLVED_CALLEE.name())));
assertTrue(irBackend.getExecutableFunctions().stream().anyMatch(function -> "frame".equals(function.callableName())));
assertTrue(irBackend.getReservedMetadata().hostMethodBindings().stream()
.anyMatch(h -> h.ownerName().equals("LowGfx") && h.sourceMethodName().equals("set_sprite")));
}
@Test
void shouldReportInconsistentBarrelInsideSdkBootstrapFixture() throws IOException {
final var projectRoot = tempDir.resolve("project-stdlib-barrel-inconsistent");
@@ -8,4 +8,12 @@ dependencies {
implementation(project(":prometeu-compiler:prometeu-compiler-core"))
implementation(project(":prometeu-compiler:prometeu-frontend-api"))
implementation(project(":prometeu-compiler:prometeu-frontend-registry"))
}
}
tasks.register<JavaExec>("runCompile") {
group = "application"
description = "Runs p.studio.compiler.Compile against test-projects/main."
classpath = sourceSets.main.get().runtimeClasspath
mainClass = "p.studio.compiler.Compile"
workingDir = rootDir
}