implements PR-O4.2
This commit is contained in:
+70
-2
@@ -4,6 +4,7 @@ import org.junit.jupiter.api.Test;
|
||||
import p.studio.compiler.source.Span;
|
||||
import p.studio.compiler.source.identifiers.FileId;
|
||||
import p.studio.compiler.source.tables.CallableSignatureRef;
|
||||
import p.studio.compiler.source.tables.IntrinsicReference;
|
||||
import p.studio.utilities.structures.ReadOnlyList;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
@@ -139,7 +140,8 @@ class IRBackendExecutableContractTest {
|
||||
Span.none())),
|
||||
Span.none())),
|
||||
IRReservedMetadata.empty(),
|
||||
ReadOnlyList.from(new CallableSignatureRef("app/main", "entry", 0, "() -> unit")));
|
||||
ReadOnlyList.from(new CallableSignatureRef("app/main", "entry", 0, "() -> unit")),
|
||||
ReadOnlyList.empty());
|
||||
final var fileB = new IRBackendFile(
|
||||
new FileId(2),
|
||||
ReadOnlyList.empty(),
|
||||
@@ -164,7 +166,8 @@ class IRBackendExecutableContractTest {
|
||||
Span.none())),
|
||||
Span.none())),
|
||||
IRReservedMetadata.empty(),
|
||||
ReadOnlyList.from(new CallableSignatureRef("app/main", "aux", 0, "() -> unit")));
|
||||
ReadOnlyList.from(new CallableSignatureRef("app/main", "aux", 0, "() -> unit")),
|
||||
ReadOnlyList.empty());
|
||||
|
||||
final var aggregator = IRBackend.aggregator();
|
||||
aggregator.merge(fileA);
|
||||
@@ -176,4 +179,69 @@ class IRBackendExecutableContractTest {
|
||||
assertEquals("aux", backend.getExecutableFunctions().get(1).callableName());
|
||||
assertEquals(2, backend.getCallableSignatures().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aggregatorMustReindexIntrinsicsToBuildGlobalPool() {
|
||||
final var fileA = new IRBackendFile(
|
||||
new FileId(1),
|
||||
ReadOnlyList.empty(),
|
||||
ReadOnlyList.from(new IRBackendExecutableFunction(
|
||||
new FileId(1),
|
||||
"app/main",
|
||||
"entry",
|
||||
0,
|
||||
0,
|
||||
10,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
ReadOnlyList.from(new IRBackendExecutableFunction.Instruction(
|
||||
IRBackendExecutableFunction.InstructionKind.CALL_INTRINSIC,
|
||||
"",
|
||||
"",
|
||||
null,
|
||||
new IRBackendExecutableFunction.IntrinsicCallMetadata("core.color.pack", 1, 0),
|
||||
Span.none())),
|
||||
Span.none())),
|
||||
IRReservedMetadata.empty(),
|
||||
ReadOnlyList.from(new CallableSignatureRef("app/main", "entry", 0, "() -> unit")),
|
||||
ReadOnlyList.from(new IntrinsicReference("core.color.pack", 1)));
|
||||
final var fileB = new IRBackendFile(
|
||||
new FileId(2),
|
||||
ReadOnlyList.empty(),
|
||||
ReadOnlyList.from(new IRBackendExecutableFunction(
|
||||
new FileId(2),
|
||||
"app/main",
|
||||
"aux",
|
||||
0,
|
||||
11,
|
||||
20,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
ReadOnlyList.from(new IRBackendExecutableFunction.Instruction(
|
||||
IRBackendExecutableFunction.InstructionKind.CALL_INTRINSIC,
|
||||
"",
|
||||
"",
|
||||
null,
|
||||
new IRBackendExecutableFunction.IntrinsicCallMetadata("core.color.pack", 1, 0),
|
||||
Span.none())),
|
||||
Span.none())),
|
||||
IRReservedMetadata.empty(),
|
||||
ReadOnlyList.from(new CallableSignatureRef("app/main", "aux", 0, "() -> unit")),
|
||||
ReadOnlyList.from(new IntrinsicReference("core.color.pack", 1)));
|
||||
|
||||
final var aggregator = IRBackend.aggregator();
|
||||
aggregator.merge(fileA);
|
||||
aggregator.merge(fileB);
|
||||
final var backend = aggregator.emit();
|
||||
|
||||
final var firstIntrinsicId = backend.getExecutableFunctions().get(0).instructions().getFirst().intrinsicCall().intrinsicId();
|
||||
final var secondIntrinsicId = backend.getExecutableFunctions().get(1).instructions().getFirst().intrinsicCall().intrinsicId();
|
||||
assertEquals(1, backend.getIntrinsicPool().size());
|
||||
assertEquals(firstIntrinsicId, secondIntrinsicId);
|
||||
assertEquals("core.color.pack", backend.getIntrinsicPool().getFirst().canonicalName());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user