implements one-shot PBS boot guard in published wrapper lowering

This commit is contained in:
2026-03-26 20:05:27 +00:00
parent 64762ca227
commit ce55cf6405
9 changed files with 268 additions and 12 deletions
@@ -86,8 +86,13 @@ class LowerToIRVMServiceTest {
fn("boot", "app", 10, ReadOnlyList.from(ret())),
fn("frame", "app", 20, ReadOnlyList.from(ret())),
fn("__pbs.frame_wrapper$m0", "app", 40, ReadOnlyList.from(
getGlobal(0),
jmpIfTrue("bootstrap_done"),
callFunc("app", "__pbs.module_init$m0", 31),
callFunc("app", "__pbs.project_init$m0", 32),
pushBool(true),
setGlobal(0),
label("bootstrap_done"),
callFunc("app", "frame", 20),
ret()))))
.build();
@@ -95,10 +100,14 @@ class LowerToIRVMServiceTest {
final var lowered = new LowerToIRVMService().lower(backend);
assertEquals("__pbs.frame_wrapper$m0", lowered.module().functions().get(0).name());
assertEquals(IRVMOp.CALL, lowered.module().functions().get(0).instructions().get(0).op());
assertEquals(IRVMOp.CALL, lowered.module().functions().get(0).instructions().get(1).op());
assertEquals(IRVMOp.GET_GLOBAL, lowered.module().functions().get(0).instructions().get(0).op());
assertEquals(IRVMOp.JMP_IF_TRUE, lowered.module().functions().get(0).instructions().get(1).op());
assertEquals(IRVMOp.CALL, lowered.module().functions().get(0).instructions().get(2).op());
assertEquals(IRVMOp.RET, lowered.module().functions().get(0).instructions().get(3).op());
assertEquals(IRVMOp.CALL, lowered.module().functions().get(0).instructions().get(3).op());
assertEquals(IRVMOp.PUSH_BOOL, lowered.module().functions().get(0).instructions().get(4).op());
assertEquals(IRVMOp.SET_GLOBAL, lowered.module().functions().get(0).instructions().get(5).op());
assertEquals(IRVMOp.CALL, lowered.module().functions().get(0).instructions().get(6).op());
assertEquals(IRVMOp.RET, lowered.module().functions().get(0).instructions().get(7).op());
assertEquals(IRVMOp.RET, lowered.module().functions().stream()
.filter(function -> "frame".equals(function.name()))
.findFirst()
@@ -583,4 +592,57 @@ class LowerToIRVMServiceTest {
null,
Span.none());
}
private static IRBackendExecutableFunction.Instruction jmpIfTrue(final String target) {
return new IRBackendExecutableFunction.Instruction(
IRBackendExecutableFunction.InstructionKind.JMP_IF_TRUE,
ModuleId.none(),
"",
null,
null,
null,
"",
target,
null,
null,
Span.none());
}
private static IRBackendExecutableFunction.Instruction getGlobal(final int slot) {
return new IRBackendExecutableFunction.Instruction(
IRBackendExecutableFunction.InstructionKind.GET_GLOBAL,
"",
null,
null,
null,
slot,
null,
Span.none());
}
private static IRBackendExecutableFunction.Instruction setGlobal(final int slot) {
return new IRBackendExecutableFunction.Instruction(
IRBackendExecutableFunction.InstructionKind.SET_GLOBAL,
"",
null,
null,
null,
slot,
null,
Span.none());
}
private static IRBackendExecutableFunction.Instruction pushBool(final boolean value) {
return new IRBackendExecutableFunction.Instruction(
IRBackendExecutableFunction.InstructionKind.PUSH_BOOL,
"",
null,
null,
null,
value ? "true" : "false",
null,
null,
null,
Span.none());
}
}