feat(pbs): align typed values and Pad input facade
This commit is contained in:
+14
-5
@@ -41,6 +41,15 @@ class PbsGateUSdkInterfaceConformanceTest {
|
||||
@TempDir
|
||||
Path tempDir;
|
||||
|
||||
@Test
|
||||
void removedInputObjectsExplainTheirMigration() throws IOException {
|
||||
final var result = compileWorkspaceModule(tempDir.resolve("removed-input"), """
|
||||
import { Input } from @sdk:input;
|
||||
fn main() -> void { let button = Input.pad().a(); }
|
||||
""", "pub fn main() -> void;", 1, null);
|
||||
assertTrue(result.diagnostics().stream().anyMatch(d -> d.getMessage().contains("migrate to Pad.pressed")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void gateU_shouldClassifySourceKindForInterfaceDeclarations() {
|
||||
final var source = """
|
||||
@@ -88,12 +97,12 @@ class PbsGateUSdkInterfaceConformanceTest {
|
||||
import { Color } from @core:color;
|
||||
import { Composer } from @sdk:composer;
|
||||
import { Gfx } from @sdk:gfx;
|
||||
import { Input, InputPad, InputButton } from @sdk:input;
|
||||
import { Pad, Button, Touch } from @sdk:input;
|
||||
import { Assets } from @sdk:asset;
|
||||
import { Log } from @sdk:log;
|
||||
|
||||
declare contract Renderer {
|
||||
fn render(composer: Composer, gfx: Gfx, color: Color, input: Input, pad: InputPad, button: InputButton, assets: Assets, log: Log) -> void;
|
||||
fn render(composer: Composer, gfx: Gfx, color: Color, pad: Pad, button: Button, assets: Assets, log: Log) -> void;
|
||||
}
|
||||
""",
|
||||
"pub contract Renderer;",
|
||||
@@ -106,12 +115,12 @@ class PbsGateUSdkInterfaceConformanceTest {
|
||||
assertTrue(positive.irBackend().getReservedMetadata().builtinTypeSurfaces().stream()
|
||||
.anyMatch(t -> t.sourceTypeName().equals("Color")));
|
||||
assertTrue(positive.irBackend().getReservedMetadata().builtinTypeSurfaces().stream()
|
||||
.anyMatch(t -> t.sourceTypeName().equals("InputType") && t.canonicalTypeName().equals("input")));
|
||||
.anyMatch(t -> t.sourceTypeName().equals("LowPad") && t.canonicalTypeName().equals("input.pad")));
|
||||
assertFalse(positive.irBackend().getReservedMetadata().builtinConstSurfaces().stream()
|
||||
.anyMatch(c -> c.canonicalTarget().equals("input")));
|
||||
assertTrue(positive.irBackend().getReservedMetadata().builtinTypeSurfaces().stream()
|
||||
.anyMatch(t -> t.sourceTypeName().equals("InputButton")
|
||||
&& t.intrinsics().stream().anyMatch(i -> i.canonicalName().equals("input.button.hold"))));
|
||||
.anyMatch(t -> t.sourceTypeName().equals("LowPad")
|
||||
&& t.intrinsics().stream().anyMatch(i -> i.canonicalName().equals("input.pad.a.hold"))));
|
||||
assertTrue(positive.irBackend().getReservedMetadata().hostMethodBindings().stream()
|
||||
.anyMatch(h -> h.ownerName().equals("LowGfx")
|
||||
&& h.abiModule().equals("gfx2d")
|
||||
|
||||
+3
-3
@@ -133,11 +133,11 @@ final class PbsSemanticPresentationContractTest {
|
||||
@Test
|
||||
void shouldClassifyBuiltinTypesExposedByImportedStdlibModules() {
|
||||
final List<FrontendSemanticToken> semanticTokens = PBSDefinitions.PBS.getSemanticTokenProvider().tokenize("""
|
||||
import { Input } from @sdk:input;
|
||||
import { Pad, Button, Touch } from @sdk:input;
|
||||
|
||||
fn main() -> void {
|
||||
let touch : InputTouch = Input.touch();
|
||||
let pad : InputPad = Input.pad();
|
||||
let touch : long = Touch.x();
|
||||
let held : long = Pad.hold(Button.A);
|
||||
}
|
||||
""");
|
||||
|
||||
|
||||
+27
-70
@@ -1152,8 +1152,8 @@ class PBSFrontendPhaseServiceTest {
|
||||
.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);
|
||||
assertTrue(irBackend.getExecutableFunctions().stream().flatMap(f -> f.instructions().stream()).anyMatch(i -> i.kind() == IRBackendExecutableFunction.InstructionKind.BUILTIN_CONST && i.label().equals("color.red@1")));
|
||||
assertTrue(irBackend.getExecutableFunctions().stream().flatMap(f -> f.instructions().stream()).anyMatch(i -> i.kind() == IRBackendExecutableFunction.InstructionKind.BUILTIN_CONST && i.label().equals("color.transparent@1")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1647,7 +1647,7 @@ class PBSFrontendPhaseServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldResolveImportedBuiltinTypeChainsInExpressionFlowSemantics() throws IOException {
|
||||
void shouldResolveImportedPadFacadeAndTypedButton() throws IOException {
|
||||
final var projectRoot = tempDir.resolve("project-builtin-chain");
|
||||
final var sourceRoot = projectRoot.resolve("src");
|
||||
Files.createDirectories(sourceRoot);
|
||||
@@ -1656,12 +1656,12 @@ class PBSFrontendPhaseServiceTest {
|
||||
final var modBarrel = sourceRoot.resolve("mod.barrel");
|
||||
Files.writeString(sourceFile, """
|
||||
import { Log } from @sdk:log;
|
||||
import { Input } from @sdk:input;
|
||||
import { Pad, Button, Touch } from @sdk:input;
|
||||
|
||||
[Frame]
|
||||
fn frame() -> void
|
||||
{
|
||||
if (Input.pad().a().pressed())
|
||||
if (Pad.pressed(Button.A))
|
||||
{
|
||||
Log.debug("Hello World!");
|
||||
}
|
||||
@@ -1722,23 +1722,11 @@ class PBSFrontendPhaseServiceTest {
|
||||
.filter(instruction ->
|
||||
instruction.kind() == p.studio.compiler.models.IRBackendExecutableFunction.InstructionKind.CALL_INTRINSIC)
|
||||
.toList();
|
||||
final var inputPadExecutable = irBackend.getExecutableFunctions().stream()
|
||||
.filter(function -> "Input.pad".equals(function.callableName()))
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
final var inputPadIntrinsics = inputPadExecutable.instructions().stream()
|
||||
.filter(instruction ->
|
||||
instruction.kind() == p.studio.compiler.models.IRBackendExecutableFunction.InstructionKind.CALL_INTRINSIC
|
||||
&& instruction.intrinsicCall() != null)
|
||||
.map(instruction -> instruction.intrinsicCall().canonicalName())
|
||||
.toList();
|
||||
assertTrue(callableCalls.contains("Input.pad"));
|
||||
assertTrue(intrinsicCalls.stream().anyMatch(instruction -> Integer.valueOf(1).equals(instruction.expectedArgSlots())));
|
||||
assertTrue(inputPadIntrinsics.contains("input.pad"));
|
||||
assertTrue(intrinsicCalls.stream().anyMatch(instruction ->
|
||||
instruction.intrinsicCall() != null && "input.pad.a".equals(instruction.intrinsicCall().canonicalName())));
|
||||
assertTrue(intrinsicCalls.stream().anyMatch(instruction ->
|
||||
instruction.intrinsicCall() != null && "input.button.pressed".equals(instruction.intrinsicCall().canonicalName())));
|
||||
assertTrue(callableCalls.contains("Pad.pressed"));
|
||||
assertTrue(intrinsicCalls.isEmpty());
|
||||
final var pad = irBackend.getExecutableFunctions().stream().filter(f -> f.callableName().equals("Pad.pressed")).findFirst().orElseThrow();
|
||||
assertEquals(12, pad.instructions().stream().filter(i -> i.intrinsicCall() != null).count());
|
||||
assertTrue(pad.instructions().stream().filter(i -> i.intrinsicCall() != null).allMatch(i -> i.expectedArgSlots() == 0));
|
||||
assertTrue(
|
||||
irBackend.getExecutableFunctions().stream().anyMatch(function -> "frame".equals(function.callableName())),
|
||||
"diagnostics="
|
||||
@@ -1748,7 +1736,7 @@ class PBSFrontendPhaseServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldResolveIntrinsicChainsWithMethodNameCollisionsByOwnerIdentity() throws IOException {
|
||||
void shouldResolvePadAndTouchQueriesByOwnerIdentity() throws IOException {
|
||||
final var projectRoot = tempDir.resolve("project-intrinsic-owner-collision");
|
||||
final var sourceRoot = projectRoot.resolve("src");
|
||||
Files.createDirectories(sourceRoot);
|
||||
@@ -1756,13 +1744,13 @@ class PBSFrontendPhaseServiceTest {
|
||||
final var sourceFile = sourceRoot.resolve("main.pbs");
|
||||
final var modBarrel = sourceRoot.resolve("mod.barrel");
|
||||
Files.writeString(sourceFile, """
|
||||
import { Input } from @sdk:input;
|
||||
import { Pad, Button, Touch } from @sdk:input;
|
||||
|
||||
[Frame]
|
||||
fn frame() -> void
|
||||
{
|
||||
Input.pad().x().pressed();
|
||||
Input.touch().x();
|
||||
Pad.pressed(Button.X);
|
||||
Touch.x();
|
||||
}
|
||||
""");
|
||||
Files.writeString(modBarrel, "pub fn frame() -> void;");
|
||||
@@ -1811,37 +1799,16 @@ class PBSFrontendPhaseServiceTest {
|
||||
&& instruction.intrinsicCall() != null)
|
||||
.map(instruction -> instruction.intrinsicCall().canonicalName())
|
||||
.toList();
|
||||
final var inputPadExecutable = irBackend.getExecutableFunctions().stream()
|
||||
.filter(function -> "Input.pad".equals(function.callableName()))
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
final var inputTouchExecutable = irBackend.getExecutableFunctions().stream()
|
||||
.filter(function -> "Input.touch".equals(function.callableName()))
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
final var inputPadIntrinsics = inputPadExecutable.instructions().stream()
|
||||
.filter(instruction ->
|
||||
instruction.kind() == p.studio.compiler.models.IRBackendExecutableFunction.InstructionKind.CALL_INTRINSIC
|
||||
&& instruction.intrinsicCall() != null)
|
||||
.map(instruction -> instruction.intrinsicCall().canonicalName())
|
||||
.toList();
|
||||
final var inputTouchIntrinsics = inputTouchExecutable.instructions().stream()
|
||||
.filter(instruction ->
|
||||
instruction.kind() == p.studio.compiler.models.IRBackendExecutableFunction.InstructionKind.CALL_INTRINSIC
|
||||
&& instruction.intrinsicCall() != null)
|
||||
.map(instruction -> instruction.intrinsicCall().canonicalName())
|
||||
.toList();
|
||||
assertTrue(callableCalls.contains("Input.pad"));
|
||||
assertTrue(callableCalls.contains("Input.touch"));
|
||||
assertTrue(inputPadIntrinsics.contains("input.pad"));
|
||||
assertTrue(intrinsicCalls.contains("input.pad.x"));
|
||||
assertTrue(intrinsicCalls.contains("input.button.pressed"));
|
||||
assertTrue(inputTouchIntrinsics.contains("input.touch"));
|
||||
assertTrue(callableCalls.contains("Pad.pressed"));
|
||||
assertTrue(intrinsicCalls.contains("input.touch.x"));
|
||||
assertFalse(intrinsicCalls.contains("input.pad"));
|
||||
final var pad = irBackend.getExecutableFunctions().stream().filter(f -> f.callableName().equals("Pad.pressed")).findFirst().orElseThrow();
|
||||
assertTrue(pad.instructions().stream().anyMatch(i -> i.intrinsicCall() != null && i.intrinsicCall().canonicalName().equals("input.pad.x.pressed")));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldResolveIntrinsicCallsOnBuiltinValuesStoredInLocals() throws IOException {
|
||||
void shouldPassStoredButtonValuesToPadQueries() throws IOException {
|
||||
final var projectRoot = tempDir.resolve("project-intrinsic-local-builtin-receiver");
|
||||
final var sourceRoot = projectRoot.resolve("src");
|
||||
Files.createDirectories(sourceRoot);
|
||||
@@ -1849,14 +1816,14 @@ class PBSFrontendPhaseServiceTest {
|
||||
final var sourceFile = sourceRoot.resolve("main.pbs");
|
||||
final var modBarrel = sourceRoot.resolve("mod.barrel");
|
||||
Files.writeString(sourceFile, """
|
||||
import { Input } from @sdk:input;
|
||||
import { Pad, Button, Touch } from @sdk:input;
|
||||
|
||||
[Frame]
|
||||
fn frame() -> void
|
||||
{
|
||||
let touch = Input.touch();
|
||||
touch.x();
|
||||
touch.y();
|
||||
let button = Button.A;
|
||||
Pad.pressed(button);
|
||||
Touch.y();
|
||||
}
|
||||
""");
|
||||
Files.writeString(modBarrel, "pub fn frame() -> void;");
|
||||
@@ -1905,20 +1872,10 @@ class PBSFrontendPhaseServiceTest {
|
||||
&& instruction.intrinsicCall() != null)
|
||||
.map(instruction -> instruction.intrinsicCall().canonicalName())
|
||||
.toList();
|
||||
final var inputTouchExecutable = irBackend.getExecutableFunctions().stream()
|
||||
.filter(function -> "Input.touch".equals(function.callableName()))
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
final var inputTouchIntrinsics = inputTouchExecutable.instructions().stream()
|
||||
.filter(instruction ->
|
||||
instruction.kind() == p.studio.compiler.models.IRBackendExecutableFunction.InstructionKind.CALL_INTRINSIC
|
||||
&& instruction.intrinsicCall() != null)
|
||||
.map(instruction -> instruction.intrinsicCall().canonicalName())
|
||||
.toList();
|
||||
assertTrue(callableCalls.contains("Input.touch"));
|
||||
assertTrue(inputTouchIntrinsics.contains("input.touch"));
|
||||
assertTrue(intrinsicCalls.contains("input.touch.x"));
|
||||
assertTrue(callableCalls.contains("Pad.pressed"));
|
||||
assertTrue(intrinsicCalls.contains("input.touch.y"));
|
||||
assertFalse(intrinsicCalls.contains("input.touch"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user