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:
+2
-2
@@ -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)) => (),
|
||||
|
||||
Reference in New Issue
Block a user