implements PR-05.5

This commit is contained in:
2026-03-24 13:42:30 +00:00
parent 6a7cd6a40a
commit 48ce448203
12 changed files with 196 additions and 13 deletions
@@ -69,6 +69,8 @@ class GoldenArtifactsTest {
"",
null,
new IRBackendExecutableFunction.IntrinsicCallMetadata("core.color.pack", 1, new IntrinsicId(0)),
0,
0,
Span.none()),
new IRBackendExecutableFunction.Instruction(
IRBackendExecutableFunction.InstructionKind.RET,
@@ -1,6 +1,8 @@
package p.studio.compiler.backend.irvm;
import org.junit.jupiter.api.Test;
import p.studio.compiler.backend.bytecode.BytecodeEmitter;
import p.studio.compiler.backend.bytecode.BytecodeModule;
import p.studio.utilities.structures.ReadOnlyList;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -122,4 +124,71 @@ class IRVMValidatorTest {
assertDoesNotThrow(() -> validator.validate(module, false));
}
@Test
void validateProgramMustRejectIntrinsicWithoutSignatureMetadata() {
final var module = new IRVMModule(
"core-v1",
ReadOnlyList.from(new IRVMFunction(
"main",
0,
0,
0,
1,
ReadOnlyList.from(
new IRVMInstruction(IRVMOp.INTRINSIC, 0),
new IRVMInstruction(IRVMOp.RET, null)))));
final var plan = new BytecodeEmitter.EmissionPlan(
0,
ReadOnlyList.empty(),
ReadOnlyList.empty(),
ReadOnlyList.from(new BytecodeEmitter.FunctionPlan(
"main",
0,
0,
0,
1,
ReadOnlyList.from(
BytecodeEmitter.Operation.intrinsic(0, null),
BytecodeEmitter.Operation.ret()))));
final var program = new IRVMProgram(module, plan);
final var thrown = assertThrows(IRVMValidationException.class, () -> validator.validate(program, false));
assertEquals(IRVMValidationErrorCode.MARSHAL_VERIFY_PRECHECK_INTRINSIC_SIGNATURE_MISSING, thrown.code());
}
@Test
void validateProgramMustApplyHostcallStackEffectsFromMetadata() {
final var module = new IRVMModule(
"core-v1",
ReadOnlyList.from(new IRVMFunction(
"main",
0,
0,
0,
1,
ReadOnlyList.from(
new IRVMInstruction(IRVMOp.HOSTCALL, 0),
new IRVMInstruction(IRVMOp.RET, null)))));
final var plan = new BytecodeEmitter.EmissionPlan(
0,
ReadOnlyList.empty(),
ReadOnlyList.empty(),
ReadOnlyList.from(new BytecodeEmitter.FunctionPlan(
"main",
0,
0,
0,
1,
ReadOnlyList.from(
BytecodeEmitter.Operation.hostcall(
new BytecodeModule.SyscallDecl("gfx", "draw_pixel", 1, 1, 0),
1,
0),
BytecodeEmitter.Operation.ret()))));
final var program = new IRVMProgram(module, plan);
final var thrown = assertThrows(IRVMValidationException.class, () -> validator.validate(program, false));
assertEquals(IRVMValidationErrorCode.MARSHAL_VERIFY_PRECHECK_STACK_UNDERFLOW, thrown.code());
}
}
@@ -41,7 +41,7 @@ class LowerToIRVMServiceTest {
final var backend = IRBackend.builder()
.executableFunctions(ReadOnlyList.from(
fn("main", "app", 10, ReadOnlyList.from(
callHost("gfx", "draw_pixel", 1, 2, 0),
callHost("gfx", "draw_pixel", 1, 0, 0),
callIntrinsic("core.color.pack", 1, 0),
ret()))))
.intrinsicPool(ReadOnlyList.from(new IntrinsicReference("core.color.pack", 1)))
@@ -240,6 +240,8 @@ class LowerToIRVMServiceTest {
"",
null,
new IRBackendExecutableFunction.IntrinsicCallMetadata(canonicalName, canonicalVersion, new IntrinsicId(intrinsicId)),
0,
0,
Span.none());
}
@@ -48,7 +48,7 @@ class BackendGateIIntegrationTest {
void gateI_validHostcallPath() {
final var module = emitFromBackend(backendWithSingleFunction(
fn("main", ReadOnlyList.from(
callHost("gfx", "draw_pixel", 1, 2, 0),
callHost("gfx", "draw_pixel", 1, 0, 0),
ret()))));
final var check = compatibilityAdapter.check(module);
@@ -131,7 +131,7 @@ class BackendGateIIntegrationTest {
void gateI_rejectMissingCapability() {
final var module = emitFromBackend(backendWithSingleFunction(
fn("main", ReadOnlyList.from(
callHost("gfx", "draw_pixel", 1, 2, 0),
callHost("gfx", "draw_pixel", 1, 0, 0),
ret()))));
final var caps = Set.of("input");
@@ -236,6 +236,8 @@ class BackendGateIIntegrationTest {
"",
null,
new IRBackendExecutableFunction.IntrinsicCallMetadata(canonicalName, canonicalVersion, new IntrinsicId(intrinsicId)),
0,
0,
Span.none());
}