implements PR-05.0.3
This commit is contained in:
+7
-5
@@ -5,6 +5,7 @@ import p.studio.compiler.backend.bytecode.BytecodeModule;
|
||||
import p.studio.compiler.models.IRBackend;
|
||||
import p.studio.compiler.models.IRBackendExecutableFunction;
|
||||
import p.studio.compiler.source.Span;
|
||||
import p.studio.compiler.source.identifiers.CallableId;
|
||||
import p.studio.utilities.structures.ReadOnlyList;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -15,7 +16,7 @@ public class LowerToIRVMService {
|
||||
private static final Comparator<IRBackendExecutableFunction> FUNCTION_ORDER = Comparator
|
||||
.comparing(IRBackendExecutableFunction::moduleKey)
|
||||
.thenComparing(IRBackendExecutableFunction::callableName)
|
||||
.thenComparingInt(IRBackendExecutableFunction::callableId)
|
||||
.thenComparingInt(function -> function.callableId().getIndex())
|
||||
.thenComparingInt(IRBackendExecutableFunction::sourceStart);
|
||||
|
||||
private final IRVMValidator validator;
|
||||
@@ -42,7 +43,7 @@ public class LowerToIRVMService {
|
||||
}
|
||||
|
||||
final var ordered = orderFunctions(backend.getExecutableFunctions());
|
||||
final var funcIdByCallableId = new HashMap<Integer, Integer>();
|
||||
final var funcIdByCallableId = new HashMap<CallableId, Integer>();
|
||||
for (var i = 0; i < ordered.size(); i++) {
|
||||
final var fn = ordered.get(i);
|
||||
if (funcIdByCallableId.putIfAbsent(fn.callableId(), i) != null) {
|
||||
@@ -127,13 +128,14 @@ public class LowerToIRVMService {
|
||||
}
|
||||
case CALL_INTRINSIC -> {
|
||||
final var intrinsic = instr.intrinsicCall();
|
||||
if (intrinsic.intrinsicId() < 0 || intrinsic.intrinsicId() >= backend.getIntrinsicPool().size()) {
|
||||
final var intrinsicIndex = intrinsic.intrinsicId().getIndex();
|
||||
if (intrinsicIndex < 0 || intrinsicIndex >= backend.getIntrinsicPool().size()) {
|
||||
throw new IRVMLoweringException(
|
||||
IRVMLoweringErrorCode.LOWER_IRVM_INVALID_INTRINSIC_ID,
|
||||
"invalid intrinsic id: " + intrinsic.intrinsicId());
|
||||
}
|
||||
instructions.add(new IRVMInstruction(IRVMOp.INTRINSIC, intrinsic.intrinsicId()));
|
||||
operations.add(BytecodeEmitter.Operation.intrinsic(intrinsic.intrinsicId(), sourceSpan));
|
||||
instructions.add(new IRVMInstruction(IRVMOp.INTRINSIC, intrinsicIndex));
|
||||
operations.add(BytecodeEmitter.Operation.intrinsic(intrinsicIndex, sourceSpan));
|
||||
functionPc += IRVMOp.INTRINSIC.immediateSize() + 2;
|
||||
}
|
||||
case LABEL -> {
|
||||
|
||||
+4
-2
@@ -6,7 +6,9 @@ import p.studio.compiler.backend.irvm.LowerToIRVMService;
|
||||
import p.studio.compiler.models.IRBackend;
|
||||
import p.studio.compiler.models.IRBackendExecutableFunction;
|
||||
import p.studio.compiler.source.Span;
|
||||
import p.studio.compiler.source.identifiers.CallableId;
|
||||
import p.studio.compiler.source.identifiers.FileId;
|
||||
import p.studio.compiler.source.identifiers.IntrinsicId;
|
||||
import p.studio.compiler.source.tables.IntrinsicReference;
|
||||
import p.studio.utilities.structures.ReadOnlyList;
|
||||
|
||||
@@ -45,7 +47,7 @@ class GoldenArtifactsTest {
|
||||
new FileId(1),
|
||||
"app/main",
|
||||
"main",
|
||||
0,
|
||||
new CallableId(0),
|
||||
0,
|
||||
20,
|
||||
0,
|
||||
@@ -66,7 +68,7 @@ class GoldenArtifactsTest {
|
||||
"",
|
||||
"",
|
||||
null,
|
||||
new IRBackendExecutableFunction.IntrinsicCallMetadata("core.color.pack", 1, 0),
|
||||
new IRBackendExecutableFunction.IntrinsicCallMetadata("core.color.pack", 1, new IntrinsicId(0)),
|
||||
Span.none()),
|
||||
new IRBackendExecutableFunction.Instruction(
|
||||
IRBackendExecutableFunction.InstructionKind.RET,
|
||||
|
||||
+6
-4
@@ -4,7 +4,9 @@ import org.junit.jupiter.api.Test;
|
||||
import p.studio.compiler.models.IRBackend;
|
||||
import p.studio.compiler.models.IRBackendExecutableFunction;
|
||||
import p.studio.compiler.source.Span;
|
||||
import p.studio.compiler.source.identifiers.CallableId;
|
||||
import p.studio.compiler.source.identifiers.FileId;
|
||||
import p.studio.compiler.source.identifiers.IntrinsicId;
|
||||
import p.studio.compiler.source.tables.IntrinsicReference;
|
||||
import p.studio.utilities.structures.ReadOnlyList;
|
||||
|
||||
@@ -137,7 +139,7 @@ class LowerToIRVMServiceTest {
|
||||
new FileId(0),
|
||||
moduleKey,
|
||||
name,
|
||||
callableId,
|
||||
new CallableId(callableId),
|
||||
0,
|
||||
10,
|
||||
0,
|
||||
@@ -166,7 +168,7 @@ class LowerToIRVMServiceTest {
|
||||
IRBackendExecutableFunction.InstructionKind.CALL_FUNC,
|
||||
moduleKey,
|
||||
name,
|
||||
calleeCallableId,
|
||||
new CallableId(calleeCallableId),
|
||||
null,
|
||||
null,
|
||||
Span.none());
|
||||
@@ -182,7 +184,7 @@ class LowerToIRVMServiceTest {
|
||||
IRBackendExecutableFunction.InstructionKind.CALL_FUNC,
|
||||
moduleKey,
|
||||
name,
|
||||
calleeCallableId,
|
||||
new CallableId(calleeCallableId),
|
||||
null,
|
||||
null,
|
||||
expectedArgSlots,
|
||||
@@ -214,7 +216,7 @@ class LowerToIRVMServiceTest {
|
||||
"",
|
||||
"",
|
||||
null,
|
||||
new IRBackendExecutableFunction.IntrinsicCallMetadata(canonicalName, canonicalVersion, intrinsicId),
|
||||
new IRBackendExecutableFunction.IntrinsicCallMetadata(canonicalName, canonicalVersion, new IntrinsicId(intrinsicId)),
|
||||
Span.none());
|
||||
}
|
||||
|
||||
|
||||
+4
-2
@@ -10,7 +10,9 @@ import p.studio.compiler.models.BuilderPipelineContext;
|
||||
import p.studio.compiler.models.IRBackend;
|
||||
import p.studio.compiler.models.IRBackendExecutableFunction;
|
||||
import p.studio.compiler.source.Span;
|
||||
import p.studio.compiler.source.identifiers.CallableId;
|
||||
import p.studio.compiler.source.identifiers.FileId;
|
||||
import p.studio.compiler.source.identifiers.IntrinsicId;
|
||||
import p.studio.compiler.source.tables.IntrinsicReference;
|
||||
import p.studio.compiler.workspaces.stages.EmitBytecodePipelineStage;
|
||||
import p.studio.compiler.workspaces.stages.LowerToIRVMPipelineStage;
|
||||
@@ -188,7 +190,7 @@ class BackendGateIIntegrationTest {
|
||||
new FileId(1),
|
||||
"app/main",
|
||||
name,
|
||||
1,
|
||||
new CallableId(1),
|
||||
0,
|
||||
10,
|
||||
0,
|
||||
@@ -233,7 +235,7 @@ class BackendGateIIntegrationTest {
|
||||
"",
|
||||
"",
|
||||
null,
|
||||
new IRBackendExecutableFunction.IntrinsicCallMetadata(canonicalName, canonicalVersion, intrinsicId),
|
||||
new IRBackendExecutableFunction.IntrinsicCallMetadata(canonicalName, canonicalVersion, new IntrinsicId(intrinsicId)),
|
||||
Span.none());
|
||||
}
|
||||
|
||||
|
||||
+4
-3
@@ -12,6 +12,7 @@ import p.studio.compiler.models.BuilderPipelineContext;
|
||||
import p.studio.compiler.models.IRBackend;
|
||||
import p.studio.compiler.models.IRBackendExecutableFunction;
|
||||
import p.studio.compiler.source.Span;
|
||||
import p.studio.compiler.source.identifiers.CallableId;
|
||||
import p.studio.compiler.source.identifiers.FileId;
|
||||
import p.studio.utilities.logs.LogAggregator;
|
||||
import p.studio.utilities.structures.ReadOnlyList;
|
||||
@@ -29,7 +30,7 @@ class BackendSafetyGateSUTest {
|
||||
new FileId(1),
|
||||
"app",
|
||||
"main",
|
||||
1,
|
||||
new CallableId(1),
|
||||
0,
|
||||
10,
|
||||
0,
|
||||
@@ -41,7 +42,7 @@ class BackendSafetyGateSUTest {
|
||||
IRBackendExecutableFunction.InstructionKind.CALL_FUNC,
|
||||
"app",
|
||||
"missing",
|
||||
99,
|
||||
new CallableId(99),
|
||||
null,
|
||||
null,
|
||||
0,
|
||||
@@ -114,7 +115,7 @@ class BackendSafetyGateSUTest {
|
||||
new FileId(1),
|
||||
"app",
|
||||
"main",
|
||||
1,
|
||||
new CallableId(1),
|
||||
0,
|
||||
10,
|
||||
0,
|
||||
|
||||
+3
-2
@@ -6,6 +6,7 @@ import p.studio.compiler.models.BuilderPipelineContext;
|
||||
import p.studio.compiler.models.IRBackend;
|
||||
import p.studio.compiler.models.IRBackendExecutableFunction;
|
||||
import p.studio.compiler.source.Span;
|
||||
import p.studio.compiler.source.identifiers.CallableId;
|
||||
import p.studio.compiler.source.identifiers.FileId;
|
||||
import p.studio.utilities.logs.LogAggregator;
|
||||
import p.studio.utilities.structures.ReadOnlyList;
|
||||
@@ -39,7 +40,7 @@ class LowerToIRVMPipelineStageTest {
|
||||
new FileId(0),
|
||||
"app",
|
||||
"main",
|
||||
1,
|
||||
new CallableId(1),
|
||||
0,
|
||||
10,
|
||||
0,
|
||||
@@ -72,7 +73,7 @@ class LowerToIRVMPipelineStageTest {
|
||||
new FileId(0),
|
||||
"app",
|
||||
"main",
|
||||
1,
|
||||
new CallableId(1),
|
||||
0,
|
||||
10,
|
||||
0,
|
||||
|
||||
Reference in New Issue
Block a user