implements PR-O1.4

This commit is contained in:
2026-03-24 13:42:26 +00:00
parent 3e14c13979
commit e36c59fe26
4 changed files with 78 additions and 7 deletions
@@ -3,5 +3,6 @@ package p.studio.compiler.backend.irvm;
public enum IRVMLoweringErrorCode {
LOWER_IRVM_EMPTY_EXECUTABLE_INPUT,
LOWER_IRVM_MISSING_CALLEE,
LOWER_IRVM_CALL_ARG_SLOTS_MISMATCH,
LOWER_IRVM_CALL_RET_SLOTS_MISMATCH,
}
@@ -65,6 +65,25 @@ public class LowerToIRVMService {
IRVMLoweringErrorCode.LOWER_IRVM_MISSING_CALLEE,
"missing callee function: " + key);
}
final var calleeFunction = ordered.get(calleeId);
if (instr.expectedArgSlots() != null
&& instr.expectedArgSlots() != calleeFunction.paramSlots()) {
throw new IRVMLoweringException(
IRVMLoweringErrorCode.LOWER_IRVM_CALL_ARG_SLOTS_MISMATCH,
"call arg_slots mismatch for %s. expected=%d actual=%d".formatted(
key,
instr.expectedArgSlots(),
calleeFunction.paramSlots()));
}
if (instr.expectedRetSlots() != null
&& instr.expectedRetSlots() != calleeFunction.returnSlots()) {
throw new IRVMLoweringException(
IRVMLoweringErrorCode.LOWER_IRVM_CALL_RET_SLOTS_MISMATCH,
"call ret_slots mismatch for %s. expected=%d actual=%d".formatted(
key,
instr.expectedRetSlots(),
calleeFunction.returnSlots()));
}
instructions.add(new IRVMInstruction(IRVMOp.CALL, calleeId));
operations.add(BytecodeEmitter.Operation.callFunc(calleeId));
}
@@ -142,4 +161,3 @@ public class LowerToIRVMService {
return (moduleKey == null ? "" : moduleKey) + "::" + callableName;
}
}