diff --git a/src/ast/compiler/captures.rs b/src/ast/compiler/captures.rs index a815762..f3cdcaa 100644 --- a/src/ast/compiler/captures.rs +++ b/src/ast/compiler/captures.rs @@ -70,6 +70,13 @@ impl CapturePass { .collect(), }, + NodeKind::Program { exprs } => NodeKind::Program { + exprs: exprs + .into_iter() + .map(|e| Rc::new(Self::transform(e.as_ref().clone(), capture_map))) + .collect(), + }, + NodeKind::Tuple { elements } => NodeKind::Tuple { elements: elements .into_iter() diff --git a/src/ast/environment.rs b/src/ast/environment.rs index 8ea961f..90f285a 100644 --- a/src/ast/environment.rs +++ b/src/ast/environment.rs @@ -390,9 +390,15 @@ impl Environment { } /// Expands macros in a syntax AST. + /// Any macro declarations encountered during expansion are persisted back + /// into the environment's registry so subsequent compilations can use them. fn expand(&self, syntax_ast: SyntaxNode, diagnostics: &mut Diagnostics) -> Option { - match self.get_expander().expand(syntax_ast) { - Ok(ast) => Some(ast), + let mut expander = self.get_expander(); + match expander.expand(syntax_ast) { + Ok(ast) => { + *self.macro_registry.borrow_mut() = expander.into_registry(); + Some(ast) + } Err(e) => { diagnostics.push_error(e, None); None