Add prelude and while macro
This commit introduces a new prelude file that defines the `while` macro and registers it during environment bootstrapping. The `again` macro has been updated to accept multiple arguments for its recursive call, and several examples have been adjusted to reflect this change. Additionally, the `MacroRegistry` in the compiler is now cloneable and can be moved out of the `MacroExpander`.
This commit is contained in:
@@ -22,6 +22,7 @@ struct ExpansionState<'a> {
|
||||
type MacroMap = HashMap<Rc<str>, (Vec<Rc<str>>, Node<UntypedKind>)>;
|
||||
|
||||
/// A registry for macro declarations.
|
||||
#[derive(Clone)]
|
||||
pub struct MacroRegistry {
|
||||
scopes: Vec<MacroMap>,
|
||||
}
|
||||
@@ -78,6 +79,10 @@ impl<E: MacroEvaluator> MacroExpander<E> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn into_registry(self) -> MacroRegistry {
|
||||
self.registry
|
||||
}
|
||||
|
||||
pub fn expand(&mut self, node: Node<UntypedKind>) -> Result<Node<UntypedKind>, String> {
|
||||
self.expand_recursive(node)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user