Refactor Purity enum and NativeFunction struct

Move `Purity` enum definition from `optimizer.rs` to `types.rs` and
create a `NativeFunction` struct to hold the function and its purity.
Update `Value::Function` to store `Rc<NativeFunction>` and
`Value::make_function`
helper to simplify creation.

This change allows tracking the purity of native functions, which is
useful
for optimization and static analysis.
This commit is contained in:
Michael Schimmel
2026-02-22 10:50:37 +01:00
parent b54a449369
commit a726b79d8a
9 changed files with 111 additions and 83 deletions
+2 -2
View File
@@ -194,14 +194,14 @@ macro_rules! dispatch_eval {
if $node.ty.is_tail {
match func_val {
Value::Object(obj) => return Ok(Value::TailCallRequest(Box::new((obj, arg_vals)))),
Value::Function(f) => return Ok(f(arg_vals)),
Value::Function(f) => return Ok((f.func)(arg_vals)),
_ => return Err(format!("Tail call target is not a function: {}", func_val)),
}
}
loop {
match func_val {
Value::Function(f) => break Ok(f(arg_vals)),
Value::Function(f) => break Ok((f.func)(arg_vals)),
Value::Object(obj) => {
if let Some(closure) = obj.as_any().downcast_ref::<Closure>() {
let old_stack_top = $self.stack.len();