Refactor native function registration and instantiation
Introduces `register_native` for direct registration of `NativeFunction` and `register_native_fn` for convenience from closures. The `Environment::run` method is removed, and its functionality is now handled by `Environment::instantiate`, which packages the linked AST into an invokable `NativeFunction`. This streamlines the execution path and better separates compilation/linking from runtime execution.
This commit is contained in:
+2
-1
@@ -123,10 +123,11 @@ pub fn run_benchmarks(update: bool) -> Vec<BenchmarkResult> {
|
||||
let env = Environment::new();
|
||||
// Link once per sample
|
||||
let linked = env.link(node.clone());
|
||||
let func = env.instantiate(linked);
|
||||
let mut total = Duration::ZERO;
|
||||
for _ in 0..n {
|
||||
let start = Instant::now();
|
||||
let _ = env.run(&linked)?;
|
||||
let _ = (func.func)(vec![]);
|
||||
total += start.elapsed();
|
||||
}
|
||||
Ok(total)
|
||||
|
||||
Reference in New Issue
Block a user