Refactor instantiate to return Closure

The `instantiate` method in `Environment` has been refactored to return
`Result<Rc<Closure>, String>` instead of `Rc<NativeFunction>`. This
change separates the creation of a `Closure` from its execution,
allowing the caller to manage the `VM` lifecycle and choose the
appropriate execution strategy (e.g., single run vs. repeated benchmark
iterations).

The `NativeFunction` type is now exclusively used for true Rust
intrinsics. The benchmark runner has also been updated to reuse a single
`VM` across iterations, improving performance by avoiding repeated VM
allocations.
This commit is contained in:
2026-03-27 22:04:20 +01:00
parent 3d0ea094b0
commit b6dcdbde8d
4 changed files with 42 additions and 49 deletions
+2 -2
View File
@@ -18,8 +18,8 @@ fn test_closure_modification_from_source() {
.into_result()
.expect("Failed to compile");
let linked = env.link(compiled);
let func = env.instantiate(linked);
let result: Result<Value, String> = Ok((func.func)(&[]));
let closure = env.instantiate(linked).expect("Failed to instantiate");
let result = env.create_vm().run_with_args(closure, &[]);
match result {
Ok(Value::Int(20)) => (),