Refactor: Use new NodeKind and clean up Binder definitions
The Binder and related types have been refactored to use the new `NodeKind` enum instead of the previous `BoundKind`. This commit updates all references to use the new structure, ensuring consistency across the compiler's AST representation. Key changes include: - Replacing `BoundKind` with `NodeKind` in the Binder's `bind` and `visit` methods. - Updating pattern matching and field access to reflect the new enum variants (e.g., `NodeKind::Def` instead of `BoundKind::Define`). - Adjusting identifier bindings to use the new `IdentifierBinding` enum. - Reflecting changes in `DefBinding`, `AssignBinding`, and `LambdaBinding` structures. - Ensuring all newly created nodes use `NodeKind` and the appropriate metadata.
This commit is contained in:
+19
-18
@@ -10,8 +10,8 @@ use std::path::{Path, PathBuf};
|
||||
use std::rc::Rc;
|
||||
|
||||
use crate::ast::compiler::bound_nodes::{
|
||||
Address, AnalyzedNode, BoundKind, ExecNode, GlobalAnalyzedRegistry, GlobalFunctionRegistry, GlobalIdx,
|
||||
Node, VirtualId,
|
||||
Address, AnalyzedNode, ExecNode, GlobalAnalyzedRegistry, GlobalFunctionRegistry, GlobalIdx,
|
||||
LambdaBinding, Node, NodeKind, VirtualId,
|
||||
};
|
||||
use crate::ast::compiler::dumper::Dumper;
|
||||
use crate::ast::compiler::lambda_collector::LambdaCollector;
|
||||
@@ -117,7 +117,7 @@ impl MacroEvaluator for RuntimeMacroEvaluator {
|
||||
node: &SyntaxNode,
|
||||
bindings: &HashMap<Rc<str>, SyntaxNode>,
|
||||
) -> Result<Value, String> {
|
||||
if let SyntaxKind::Identifier(sym) = &node.kind
|
||||
if let SyntaxKind::Identifier { symbol: sym, .. } = &node.kind
|
||||
&& let Some(arg_node) = bindings.get(&sym.name)
|
||||
{
|
||||
return Ok(Value::Object(Rc::new(arg_node.clone()) as Rc<dyn Object>));
|
||||
@@ -390,8 +390,8 @@ impl Environment {
|
||||
|
||||
fn discover_globals(&self, node: &SyntaxNode) {
|
||||
match &node.kind {
|
||||
SyntaxKind::Def { target, .. } => {
|
||||
if let SyntaxKind::Identifier(sym) = &target.kind {
|
||||
SyntaxKind::Def { pattern, .. } => {
|
||||
if let SyntaxKind::Identifier { symbol: sym, .. } = &pattern.kind {
|
||||
let mut root_scopes = self.root_scopes.borrow_mut();
|
||||
let last_idx = root_scopes.len() - 1;
|
||||
let current_scope = &mut root_scopes[last_idx];
|
||||
@@ -417,9 +417,9 @@ impl Environment {
|
||||
|
||||
fn extract_names(node: &SyntaxNode) -> Vec<Rc<str>> {
|
||||
match &node.kind {
|
||||
SyntaxKind::Identifier(sym) => vec![sym.name.clone()],
|
||||
SyntaxKind::Identifier { symbol: sym, .. } => vec![sym.name.clone()],
|
||||
SyntaxKind::Tuple { elements } => {
|
||||
elements.iter().flat_map(extract_names).collect()
|
||||
elements.iter().flat_map(|e| extract_names(e)).collect()
|
||||
}
|
||||
_ => vec![],
|
||||
}
|
||||
@@ -476,20 +476,22 @@ impl Environment {
|
||||
LambdaCollector::collect(&bound_ast, &mut self.function_registry.borrow_mut());
|
||||
|
||||
let checker = TypeChecker::new(self.root_types.clone());
|
||||
let wrapped_ast = if let BoundKind::Lambda { .. } = bound_ast.kind {
|
||||
let wrapped_ast = if let NodeKind::Lambda { .. } = bound_ast.kind {
|
||||
bound_ast
|
||||
} else {
|
||||
Node {
|
||||
identity: bound_ast.identity.clone(),
|
||||
kind: BoundKind::Lambda {
|
||||
kind: NodeKind::Lambda {
|
||||
params: std::rc::Rc::new(Node {
|
||||
identity: bound_ast.identity.clone(),
|
||||
kind: BoundKind::Tuple { elements: vec![] },
|
||||
kind: NodeKind::Tuple { elements: vec![] },
|
||||
ty: (),
|
||||
}),
|
||||
upvalues: vec![],
|
||||
body: std::rc::Rc::new(bound_ast),
|
||||
positional_count: Some(0),
|
||||
info: LambdaBinding {
|
||||
upvalues: vec![],
|
||||
positional_count: Some(0),
|
||||
},
|
||||
},
|
||||
ty: (),
|
||||
}
|
||||
@@ -650,20 +652,19 @@ impl Environment {
|
||||
|
||||
pub fn instantiate(&self, node: ExecNode) -> Rc<crate::ast::types::NativeFunction> {
|
||||
let root_values = self.root_values.clone();
|
||||
if let BoundKind::Lambda {
|
||||
if let NodeKind::Lambda {
|
||||
params,
|
||||
upvalues,
|
||||
body,
|
||||
positional_count,
|
||||
info,
|
||||
} = &node.kind
|
||||
&& upvalues.is_empty()
|
||||
&& info.upvalues.is_empty()
|
||||
{
|
||||
let closure = Rc::new(crate::ast::vm::Closure::new(
|
||||
params.clone(),
|
||||
body.ty.original.clone(),
|
||||
body.ty.original.clone(),
|
||||
body.clone(),
|
||||
Vec::new(),
|
||||
*positional_count,
|
||||
info.positional_count,
|
||||
node.ty.stack_size,
|
||||
));
|
||||
let closure_obj: Rc<dyn crate::ast::types::Object> = closure;
|
||||
|
||||
Reference in New Issue
Block a user