align PBS color builtins with RGBA8888
This commit is contained in:
+68
@@ -1019,6 +1019,74 @@ class PBSFrontendPhaseServiceTest {
|
||||
assertTrue(irBackend.getExecutableFunctions().stream().anyMatch(function -> "frame".equals(function.callableName())));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldLowerCoreColorConstructorsAndConstantsFromBootstrapStdlib() throws IOException {
|
||||
final var projectRoot = tempDir.resolve("project-bootstrap-core-color-rgba");
|
||||
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 { Color, RED, TRANSPARENT } from @core:color;
|
||||
import { Gfx } from @sdk:gfx;
|
||||
|
||||
[Frame]
|
||||
fn frame() -> void
|
||||
{
|
||||
let tint: Color = Color.rgba(1, 2, 3, 128);
|
||||
let web: Color = Color.html_rgba("#11223344");
|
||||
Gfx.clear(RED);
|
||||
Gfx.fill_rect(0, 0, 1, 1, tint);
|
||||
Gfx.fill_rect(1, 0, 1, 1, web);
|
||||
Gfx.fill_rect(2, 0, 1, 1, TRANSPARENT);
|
||||
}
|
||||
""");
|
||||
Files.writeString(modBarrel, "pub fn frame() -> void;");
|
||||
|
||||
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,
|
||||
AppMode.Game);
|
||||
final var diagnostics = DiagnosticSink.empty();
|
||||
|
||||
final var irBackend = new PBSFrontendPhaseService().compile(
|
||||
ctx,
|
||||
diagnostics,
|
||||
LogAggregator.empty(),
|
||||
BuildingIssueSink.empty());
|
||||
|
||||
assertFalse(diagnostics.hasErrors(),
|
||||
"diagnostics=" + diagnostics.stream().map(d -> d.getCode() + ":" + d.getMessage()).toList());
|
||||
assertTrue(diagnostics.stream().noneMatch(d ->
|
||||
d.getCode().equals(PbsSemanticsErrors.E_SEM_EXEC_LOWERING_UNRESOLVED_CALLEE.name())),
|
||||
"diagnostics=" + diagnostics.stream().map(d -> d.getCode() + ":" + d.getMessage()).toList());
|
||||
final var intrinsicNames = irBackend.getExecutableFunctions().stream()
|
||||
.flatMap(function -> function.instructions().stream())
|
||||
.filter(instruction -> instruction.kind() == IRBackendExecutableFunction.InstructionKind.CALL_INTRINSIC)
|
||||
.map(instruction -> instruction.intrinsicCall().canonicalName())
|
||||
.toList();
|
||||
assertTrue(intrinsicNames.contains("color.rgba"), "intrinsics=" + intrinsicNames);
|
||||
assertTrue(intrinsicNames.contains("color.html_rgba"), "intrinsics=" + intrinsicNames);
|
||||
assertTrue(intrinsicNames.contains("color.red"), "intrinsics=" + intrinsicNames);
|
||||
assertTrue(intrinsicNames.contains("color.transparent"), "intrinsics=" + intrinsicNames);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldLowerSdkComposerEmitSpriteFacadeUsingCanonicalComposerContract() throws IOException {
|
||||
final var projectRoot = tempDir.resolve("project-bootstrap-sdk-composer-emit-sprite");
|
||||
|
||||
Reference in New Issue
Block a user