implements PR-038
This commit is contained in:
+90
@@ -0,0 +1,90 @@
|
||||
package p.studio.compiler.models;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import p.studio.compiler.source.Span;
|
||||
import p.studio.compiler.source.identifiers.FileId;
|
||||
import p.studio.utilities.structures.ReadOnlyList;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
class IRBackendExecutableContractTest {
|
||||
|
||||
@Test
|
||||
void callInstructionMustRequireCategorySpecificMetadata() {
|
||||
assertThrows(IllegalArgumentException.class, () -> new IRBackendExecutableFunction.Instruction(
|
||||
IRBackendExecutableFunction.InstructionKind.CALL_HOST,
|
||||
"",
|
||||
"",
|
||||
null,
|
||||
null,
|
||||
Span.none()));
|
||||
|
||||
final var callFunc = new IRBackendExecutableFunction.Instruction(
|
||||
IRBackendExecutableFunction.InstructionKind.CALL_FUNC,
|
||||
"app/main",
|
||||
"foo",
|
||||
null,
|
||||
null,
|
||||
Span.none());
|
||||
assertEquals(IRBackendExecutableFunction.InstructionKind.CALL_FUNC, callFunc.kind());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aggregatorMustPreserveExecutableFunctionOrderDeterministically() {
|
||||
final var fileA = new IRBackendFile(
|
||||
new FileId(1),
|
||||
ReadOnlyList.empty(),
|
||||
ReadOnlyList.from(new IRBackendExecutableFunction(
|
||||
new FileId(1),
|
||||
"app/main",
|
||||
"entry",
|
||||
0,
|
||||
10,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
ReadOnlyList.from(new IRBackendExecutableFunction.Instruction(
|
||||
IRBackendExecutableFunction.InstructionKind.HALT,
|
||||
"",
|
||||
"",
|
||||
null,
|
||||
null,
|
||||
Span.none())),
|
||||
Span.none())),
|
||||
IRReservedMetadata.empty());
|
||||
final var fileB = new IRBackendFile(
|
||||
new FileId(2),
|
||||
ReadOnlyList.empty(),
|
||||
ReadOnlyList.from(new IRBackendExecutableFunction(
|
||||
new FileId(2),
|
||||
"app/main",
|
||||
"aux",
|
||||
11,
|
||||
20,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
ReadOnlyList.from(new IRBackendExecutableFunction.Instruction(
|
||||
IRBackendExecutableFunction.InstructionKind.RET,
|
||||
"",
|
||||
"",
|
||||
null,
|
||||
null,
|
||||
Span.none())),
|
||||
Span.none())),
|
||||
IRReservedMetadata.empty());
|
||||
|
||||
final var aggregator = IRBackend.aggregator();
|
||||
aggregator.merge(fileA);
|
||||
aggregator.merge(fileB);
|
||||
final var backend = aggregator.emit();
|
||||
|
||||
assertEquals(2, backend.getExecutableFunctions().size());
|
||||
assertEquals("entry", backend.getExecutableFunctions().get(0).callableName());
|
||||
assertEquals("aux", backend.getExecutableFunctions().get(1).callableName());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user