This commit is contained in:
2026-03-24 13:40:42 +00:00
parent 78ed7a8253
commit 6950f2bef0
22 changed files with 428 additions and 289 deletions
@@ -1,21 +1,28 @@
use prometeu_bytecode::Value;
use prometeu_vm::Heap;
use prometeu_vm::VirtualMachine;
use prometeu_vm::{HostContext, HostReturn, NativeInterface, SyscallId};
use prometeu_hal::vm_fault::VmFault;
#[test]
fn gc_collects_unreachable_closure_but_keeps_marked() {
let mut heap = Heap::new();
// Black-box check: a fresh VM with no program initializes and can run a zero-budget slice.
// The GC behavior is covered by unit tests inside the VM crate; this layer test remains
// as a smoke-test for public API stability.
struct NoopNative;
impl NativeInterface for NoopNative {
fn syscall(
&mut self,
_id: SyscallId,
_args: &[prometeu_bytecode::Value],
_ret: &mut HostReturn,
_ctx: &mut HostContext,
) -> Result<(), VmFault> {
Ok(())
}
}
// Allocate two closures with small environments
let rooted = heap.alloc_closure(1, &[Value::Int32(10)]);
let unreachable = heap.alloc_closure(2, &[Value::Int32(20)]);
// Mark only the rooted one, then sweep.
heap.mark_from_roots([rooted]);
heap.sweep();
assert!(heap.is_valid(rooted), "rooted object must remain alive after sweep");
assert!(
!heap.is_valid(unreachable),
"unreachable object must be reclaimed by GC"
);
let mut vm = VirtualMachine::default();
let mut native = NoopNative;
let mut ctx = HostContext::new(None);
let res = vm.run_budget(0, &mut native, &mut ctx);
assert!(res.is_ok());
}