new test main with code directly (fixes)
This commit is contained in:
+26
-2
@@ -95,9 +95,10 @@ class PbsGateUSdkInterfaceConformanceTest {
|
||||
import { Color } from @core:color;
|
||||
import { Gfx } from @sdk:gfx;
|
||||
import { Input, InputPad, InputButton } from @sdk:input;
|
||||
import { Log } from @sdk:log;
|
||||
|
||||
declare contract Renderer {
|
||||
fn render(gfx: Gfx, color: Color, input: Input, pad: InputPad, button: InputButton) -> void;
|
||||
fn render(gfx: Gfx, color: Color, input: Input, pad: InputPad, button: InputButton, log: Log) -> void;
|
||||
}
|
||||
""",
|
||||
"pub contract Renderer;",
|
||||
@@ -113,9 +114,19 @@ class PbsGateUSdkInterfaceConformanceTest {
|
||||
.anyMatch(t -> t.sourceTypeName().equals("Input") && t.canonicalTypeName().equals("input")));
|
||||
assertTrue(positive.irBackend().getReservedMetadata().builtinTypeSurfaces().stream()
|
||||
.anyMatch(t -> t.sourceTypeName().equals("InputButton")
|
||||
&& t.intrinsics().stream().anyMatch(i -> i.canonicalName().equals("hold"))));
|
||||
&& t.intrinsics().stream().anyMatch(i -> i.canonicalName().equals("input.button.hold"))));
|
||||
assertTrue(positive.irBackend().getReservedMetadata().hostMethodBindings().stream()
|
||||
.anyMatch(h -> h.ownerName().equals("Gfx")));
|
||||
assertTrue(positive.irBackend().getReservedMetadata().hostMethodBindings().stream()
|
||||
.anyMatch(h -> h.ownerName().equals("LowLog")
|
||||
&& h.abiModule().equals("log")
|
||||
&& h.abiMethod().equals("write")
|
||||
&& h.abiVersion() == 1));
|
||||
assertTrue(positive.irBackend().getReservedMetadata().hostMethodBindings().stream()
|
||||
.anyMatch(h -> h.ownerName().equals("LowLog")
|
||||
&& h.abiModule().equals("log")
|
||||
&& h.abiMethod().equals("write_tag")
|
||||
&& h.abiVersion() == 1));
|
||||
|
||||
final var negative = compileWorkspaceModule(
|
||||
tempDir.resolve("gate-u-reserved-import-negative"),
|
||||
@@ -129,6 +140,19 @@ class PbsGateUSdkInterfaceConformanceTest {
|
||||
final var missingModule = firstDiagnostic(negative.diagnostics(),
|
||||
d -> d.getCode().equals(PbsLinkErrors.E_LINK_IMPORT_MODULE_NOT_FOUND.name()));
|
||||
assertStableDiagnosticIdentity(missingModule, PbsLinkErrors.E_LINK_IMPORT_MODULE_NOT_FOUND.name(), DiagnosticPhase.LINKING);
|
||||
|
||||
final var lowLogNotPublic = compileWorkspaceModule(
|
||||
tempDir.resolve("gate-u-reserved-import-lowlog-hidden"),
|
||||
"""
|
||||
import { LowLog } from @sdk:log;
|
||||
fn run() -> int { return 1; }
|
||||
""",
|
||||
"pub fn run() -> int;",
|
||||
1,
|
||||
d -> d.getCode().equals(PbsLinkErrors.E_LINK_IMPORT_SYMBOL_NOT_PUBLIC.name()));
|
||||
final var notPublic = firstDiagnostic(lowLogNotPublic.diagnostics(),
|
||||
d -> d.getCode().equals(PbsLinkErrors.E_LINK_IMPORT_SYMBOL_NOT_PUBLIC.name()));
|
||||
assertStableDiagnosticIdentity(notPublic, PbsLinkErrors.E_LINK_IMPORT_SYMBOL_NOT_PUBLIC.name(), DiagnosticPhase.LINKING);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+25
@@ -142,6 +142,31 @@ class PbsParserTest {
|
||||
assertTrue(diagnostics.stream().anyMatch(d -> d.getCode().equals(ParseErrors.E_PARSE_ATTRIBUTES_NOT_ALLOWED.name())));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldParseServiceAndMemberNamesUsingErrorKeyword() {
|
||||
final var source = """
|
||||
declare service Log {
|
||||
fn error(msg: str) -> void { return; }
|
||||
fn error(tag: int, msg: str) -> void { return; }
|
||||
}
|
||||
|
||||
fn run() -> void {
|
||||
Log.error("oops");
|
||||
Log.error(7, "oops");
|
||||
return;
|
||||
}
|
||||
""";
|
||||
final var diagnostics = DiagnosticSink.empty();
|
||||
final var fileId = new FileId(0);
|
||||
|
||||
final PbsAst.File ast = PbsParser.parse(PbsLexer.lex(source, fileId, diagnostics), fileId, diagnostics);
|
||||
|
||||
assertTrue(diagnostics.isEmpty(), "Parser should accept 'error' as callable/member name");
|
||||
final var service = assertInstanceOf(PbsAst.ServiceDecl.class, ast.topDecls().getFirst());
|
||||
assertEquals(2, service.methods().size());
|
||||
assertEquals("error", service.methods().getFirst().name());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldAcceptStructFieldTrailingComma() {
|
||||
final var source = "declare struct S(a: int,);";
|
||||
|
||||
+24
-5
@@ -81,10 +81,6 @@ class PbsInterfaceModuleSemanticsTest {
|
||||
final var source = """
|
||||
fn run() -> int { return 1; }
|
||||
|
||||
declare service Game {
|
||||
fn tick() -> int { return 1; }
|
||||
}
|
||||
|
||||
declare contract C { fn run() -> int; }
|
||||
declare struct S(v: int);
|
||||
implements C for S using s {
|
||||
@@ -98,7 +94,30 @@ class PbsInterfaceModuleSemanticsTest {
|
||||
final var nonDeclarativeCount = diagnostics.stream()
|
||||
.filter(d -> d.getCode().equals(PbsSemanticsErrors.E_SEM_INTERFACE_NON_DECLARATIVE_DECLARATION.name()))
|
||||
.count();
|
||||
assertTrue(nonDeclarativeCount >= 3);
|
||||
assertTrue(nonDeclarativeCount >= 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldAllowDeclarativeServiceFacadesInInterfaceModule() {
|
||||
final var source = """
|
||||
declare host LowLog {
|
||||
[Host(module = "log", name = "write", version = 1)]
|
||||
[Capability(name = "log")]
|
||||
fn write(level: int, message: str) -> void;
|
||||
}
|
||||
|
||||
declare service Log {
|
||||
fn trace(message: str) -> void {
|
||||
LowLog.write(0, message);
|
||||
}
|
||||
}
|
||||
""";
|
||||
final var diagnostics = DiagnosticSink.empty();
|
||||
|
||||
new PbsFrontendCompiler().compileFile(new FileId(3), source, diagnostics, SourceKind.SDK_INTERFACE);
|
||||
|
||||
assertFalse(diagnostics.stream().anyMatch(d ->
|
||||
d.getCode().equals(PbsSemanticsErrors.E_SEM_INTERFACE_NON_DECLARATIVE_DECLARATION.name())));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+84
@@ -181,6 +181,7 @@ class PBSFrontendPhaseServiceTest {
|
||||
BuildingIssueSink.empty());
|
||||
|
||||
assertTrue(diagnostics.isEmpty());
|
||||
assertEquals("frame", irBackend.getEntryPointCallableName());
|
||||
assertEquals(2, irBackend.getFunctions().size());
|
||||
}
|
||||
|
||||
@@ -783,6 +784,89 @@ class PBSFrontendPhaseServiceTest {
|
||||
assertEquals("independent", irBackend.getFunctions().getFirst().name());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldResolveImportedBuiltinTypeChainsInExpressionFlowSemantics() throws IOException {
|
||||
final var projectRoot = tempDir.resolve("project-builtin-chain");
|
||||
final var sourceRoot = projectRoot.resolve("src");
|
||||
Files.createDirectories(sourceRoot);
|
||||
|
||||
final var sourceFile = sourceRoot.resolve("main.pbs");
|
||||
final var modBarrel = sourceRoot.resolve("mod.barrel");
|
||||
Files.writeString(sourceFile, """
|
||||
import { Log } from @sdk:log;
|
||||
import { Input } from @sdk:input;
|
||||
|
||||
fn frame() -> void
|
||||
{
|
||||
if (Input.pad().a().pressed())
|
||||
{
|
||||
Log.debug("Hello World!");
|
||||
}
|
||||
}
|
||||
""");
|
||||
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("main")
|
||||
.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_INVALID_MEMBER_ACCESS.name())));
|
||||
assertTrue(diagnostics.stream().noneMatch(d ->
|
||||
d.getCode().equals(PbsSemanticsErrors.E_SEM_APPLY_NON_CALLABLE_TARGET.name())));
|
||||
final var frameExecutableOptional = irBackend.getExecutableFunctions().stream()
|
||||
.filter(function -> "frame".equals(function.callableName()))
|
||||
.findFirst();
|
||||
final var executableNames = irBackend.getExecutableFunctions().stream()
|
||||
.map(function -> function.callableName() + "@" + function.moduleKey())
|
||||
.toList();
|
||||
assertTrue(
|
||||
frameExecutableOptional.isPresent(),
|
||||
"diagnostics="
|
||||
+ diagnostics.stream().map(d -> d.getCode() + ":" + d.getMessage()).toList()
|
||||
+ " executableNames="
|
||||
+ executableNames);
|
||||
final var frameExecutable = frameExecutableOptional.orElseThrow();
|
||||
final var intrinsicCalls = frameExecutable.instructions().stream()
|
||||
.filter(instruction ->
|
||||
instruction.kind() == p.studio.compiler.models.IRBackendExecutableFunction.InstructionKind.CALL_INTRINSIC)
|
||||
.toList();
|
||||
assertTrue(intrinsicCalls.stream().anyMatch(instruction -> Integer.valueOf(1).equals(instruction.expectedArgSlots())));
|
||||
assertTrue(intrinsicCalls.stream().anyMatch(instruction ->
|
||||
instruction.intrinsicCall() != null && "input.pad".equals(instruction.intrinsicCall().canonicalName())));
|
||||
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(
|
||||
irBackend.getExecutableFunctions().stream().anyMatch(function -> "frame".equals(function.callableName())),
|
||||
"diagnostics="
|
||||
+ diagnostics.stream().map(d -> d.getCode() + ":" + d.getMessage()).toList()
|
||||
+ " executableNames="
|
||||
+ executableNames);
|
||||
}
|
||||
|
||||
private void registerFile(
|
||||
final ProjectId projectId,
|
||||
final Path projectRoot,
|
||||
|
||||
Reference in New Issue
Block a user