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
+19
View File
@@ -361,6 +361,25 @@ impl VM {
dispatch_eval!(self, node, eval)
}
/// Resolves potential tail call requests iteratively until a final value is reached.
pub fn resolve_tail_calls(&mut self, mut result: Value) -> Value {
while let Value::TailCallRequest(payload) = result {
let (next_obj, next_args) = *payload;
if let Some(closure) = next_obj.as_any().downcast_ref::<Closure>() {
result = match self.run_with_args(closure, next_args) {
Ok(v) => v,
Err(e) => panic!("Myc Runtime Error (TailCall): {}", e),
};
} else {
panic!(
"Tail call target is not a closure: {}",
next_obj.type_name()
);
}
}
result
}
fn eval_observed<O: VMObserver>(
&mut self,
observer: &mut O,