dev/pbs #8

Merged
bquarkz merged 74 commits from dev/pbs into master 2026-02-03 15:28:31 +00:00
4 changed files with 19 additions and 53 deletions
Showing only changes of commit ceaac6cab8 - Show all commits

View File

@ -242,14 +242,15 @@ mod tests {
006C GetLocal U32(1) 006C GetLocal U32(1)
0072 SetLocal U32(2) 0072 SetLocal U32(2)
0078 Nop 0078 Nop
007A LoadRef U32(0) 007A GetLocal U32(2)
0080 SetLocal U32(3) 0080 LoadRef U32(0)
0086 GetLocal U32(3) 0086 SetLocal U32(3)
008C PushConst U32(5) 008C GetLocal U32(3)
0092 Add 0092 PushConst U32(5)
0094 SetLocal U32(4) 0098 Add
009A Nop 009A SetLocal U32(4)
009C Ret 00A0 Nop
00A2 Ret
"#; "#;
assert_eq!(disasm_text, expected_disasm); assert_eq!(disasm_text, expected_disasm);

View File

@ -238,6 +238,8 @@ impl<'a> Lowerer<'a> {
// 3. Begin Operation // 3. Begin Operation
self.emit(Instr::BeginPeek { gate: ValueId(gate_slot) }); self.emit(Instr::BeginPeek { gate: ValueId(gate_slot) });
self.emit(Instr::GetLocal(gate_slot));
self.emit(Instr::LoadRef(0));
// 4. Bind view to local // 4. Bind view to local
self.local_vars.push(HashMap::new()); self.local_vars.push(HashMap::new());
@ -266,6 +268,8 @@ impl<'a> Lowerer<'a> {
// 3. Begin Operation // 3. Begin Operation
self.emit(Instr::BeginBorrow { gate: ValueId(gate_slot) }); self.emit(Instr::BeginBorrow { gate: ValueId(gate_slot) });
self.emit(Instr::GetLocal(gate_slot));
self.emit(Instr::LoadRef(0));
// 4. Bind view to local // 4. Bind view to local
self.local_vars.push(HashMap::new()); self.local_vars.push(HashMap::new());
@ -294,6 +298,8 @@ impl<'a> Lowerer<'a> {
// 3. Begin Operation // 3. Begin Operation
self.emit(Instr::BeginMutate { gate: ValueId(gate_slot) }); self.emit(Instr::BeginMutate { gate: ValueId(gate_slot) });
self.emit(Instr::GetLocal(gate_slot));
self.emit(Instr::LoadRef(0));
// 4. Bind view to local // 4. Bind view to local
self.local_vars.push(HashMap::new()); self.local_vars.push(HashMap::new());

View File

@ -75,24 +75,15 @@ pub fn lower_function(core_func: &ir_core::Function) -> Result<ir_vm::Function>
type_id: ir_vm::TypeId(ty.0), type_id: ir_vm::TypeId(ty.0),
slots: *slots slots: *slots
}, },
ir_core::Instr::BeginPeek { .. } => { ir_core::Instr::BeginPeek { .. } => ir_vm::InstrKind::GateBeginPeek,
vm_func.body.push(ir_vm::Instruction::new(ir_vm::InstrKind::GateBeginPeek, None)); ir_core::Instr::BeginBorrow { .. } => ir_vm::InstrKind::GateBeginBorrow,
ir_vm::InstrKind::GateLoad { offset: 0 } ir_core::Instr::BeginMutate { .. } => ir_vm::InstrKind::GateBeginMutate,
}
ir_core::Instr::BeginBorrow { .. } => {
vm_func.body.push(ir_vm::Instruction::new(ir_vm::InstrKind::GateBeginBorrow, None));
ir_vm::InstrKind::GateLoad { offset: 0 }
}
ir_core::Instr::BeginMutate { .. } => {
vm_func.body.push(ir_vm::Instruction::new(ir_vm::InstrKind::GateBeginMutate, None));
ir_vm::InstrKind::GateLoad { offset: 0 }
}
ir_core::Instr::EndPeek => ir_vm::InstrKind::GateEndPeek, ir_core::Instr::EndPeek => ir_vm::InstrKind::GateEndPeek,
ir_core::Instr::EndBorrow => ir_vm::InstrKind::GateEndBorrow, ir_core::Instr::EndBorrow => ir_vm::InstrKind::GateEndBorrow,
ir_core::Instr::EndMutate => ir_vm::InstrKind::GateEndMutate, ir_core::Instr::EndMutate => ir_vm::InstrKind::GateEndMutate,
ir_core::Instr::LoadRef(offset) => ir_vm::InstrKind::GateLoad { offset: *offset }, ir_core::Instr::LoadRef(offset) => ir_vm::InstrKind::GateLoad { offset: *offset },
ir_core::Instr::StoreRef(offset) => ir_vm::InstrKind::GateStore { offset: *offset }, ir_core::Instr::StoreRef(offset) => ir_vm::InstrKind::GateStore { offset: *offset },
ir_core::Instr::Free => ir_vm::InstrKind::Nop, ir_core::Instr::Free => anyhow::bail!("Instruction 'Free' cannot be represented in ir_vm v0"),
}; };
vm_func.body.push(ir_vm::Instruction::new(kind, None)); vm_func.body.push(ir_vm::Instruction::new(kind, None));
} }

View File

@ -1,35 +1,3 @@
# PR-04 — Update `core_to_vm` Lowering (Kill Placeholders)
### Goal
Make lowering the **only** integration point between Core IR and VM IR.
### Required Mapping
* `ir_core::Alloc { ty, slots }`
`ir_vm::Alloc { type_id, slots }`
* `BeginPeek / Borrow / Mutate`
`GateBegin*`
* `EndPeek / Borrow / Mutate`
`GateEnd*`
**Forbidden:**
* `LoadRef(0)`
* `Nop` as semantic replacement
### Tests
* Given a Core IR program with alloc + begin/end, VM IR must contain:
* shape-explicit `Alloc`
* correctly paired gate begin/end
* zero placeholders
---
# PR-05 — Gate-Aware Access Path (Choose One, Explicitly) # PR-05 — Gate-Aware Access Path (Choose One, Explicitly)
### Goal ### Goal