Refactor Value enum for Quote node

Replaces `Value::Object(Rc<dyn Object>)` for SyntaxNodes with a
dedicated `Value::Quote(Rc<SyntaxNode>)`. This provides better type
safety and clarity when dealing with AST nodes as values.
Refactor Value enum for Quote node

This commit introduces a new `Value::Quote` variant to represent quoted
AST nodes directly, replacing the generic `Value::Object` for this
purpose.

This change simplifies the handling of quoted nodes by:
- Directly storing an `Rc<SyntaxNode>` instead of relying on dynamic
  downcasting from `Rc<dyn Object>`.
- Streamlining macro expansion logic by removing the need to check for
  `SyntaxNode` within `Value::Object`.
- Improving type safety and explicitness in the `Value` enum.
This commit is contained in:
2026-03-22 20:53:30 +01:00
parent ae1d94e507
commit 09ae98728f
5 changed files with 25 additions and 48 deletions
+6 -1
View File
@@ -1,4 +1,5 @@
use crate::ast::closure::Closure;
use crate::ast::nodes::SyntaxNode;
use chrono::{TimeZone, Utc};
use std::any::Any;
use std::cell::RefCell;
@@ -263,7 +264,8 @@ pub enum Value {
FieldAccessor(Keyword),
Function(Rc<NativeFunction>),
Closure(Rc<Closure>), // Compiled function with captured upvalues
Object(Rc<dyn Object>), // For Series, Streams, SyntaxNodes, and custom extensions
Quote(Rc<SyntaxNode>), // Quoted AST node (from 'expr or macro expansion)
Object(Rc<dyn Object>), // RTL extensions: Series, Streams, and custom types
Cell(Rc<RefCell<Value>>), // Boxed value for captures
}
@@ -284,6 +286,7 @@ impl PartialEq for Value {
(Value::FieldAccessor(a), Value::FieldAccessor(b)) => a == b,
(Value::Function(a), Value::Function(b)) => Rc::ptr_eq(a, b),
(Value::Closure(a), Value::Closure(b)) => Rc::ptr_eq(a, b),
(Value::Quote(a), Value::Quote(b)) => Rc::ptr_eq(a, b),
(Value::Object(a), Value::Object(b)) => Rc::ptr_eq(a, b),
(Value::Cell(a), Value::Cell(b)) => Rc::ptr_eq(a, b),
_ => false,
@@ -625,6 +628,7 @@ impl Value {
Value::FieldAccessor(k) => StaticType::FieldAccessor(*k),
Value::Function(_) => StaticType::Any, // Dynamic function
Value::Closure(_) => StaticType::Object("closure"),
Value::Quote(_) => StaticType::Object("ast-node"),
Value::Object(o) => StaticType::Object(o.type_name()),
Value::Cell(c) => c.borrow().static_type(),
}
@@ -669,6 +673,7 @@ impl fmt::Display for Value {
Value::FieldAccessor(k) => write!(f, ".{}", k.name()),
Value::Function(f_meta) => write!(f, "<native fn, {:?}>", f_meta.purity),
Value::Closure(_) => write!(f, "<closure>"),
Value::Quote(_) => write!(f, "<ast-node>"),
Value::Object(o) => write!(f, "<{:?}>", o),
Value::Cell(c) => write!(f, "{}", c.borrow()),
}