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:
Michael Schimmel
2026-02-22 11:56:46 +01:00
parent a726b79d8a
commit cb94f20c0b
7 changed files with 143 additions and 65 deletions
+2 -1
View File
@@ -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)