Update how visitors work, add NameId type
* Visitors are now defined on a per-type level, allowing for greater flexibility in combining and re-using behavior * NameId is used for namespaces, which are used to index locally scoped variables. Syms are used for free namespaces, specifically in objects. All NameIDs are symbols, while not all symbols are NameIDs. Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
use crate::{
|
||||
compile::Ctx,
|
||||
obj::Sym,
|
||||
syn::span::*,
|
||||
};
|
||||
@@ -14,7 +13,7 @@ pub enum Stmt {
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Lhs {
|
||||
Sym(Sym),
|
||||
Name(Sym),
|
||||
Complex(Expr),
|
||||
}
|
||||
|
||||
@@ -29,7 +28,7 @@ pub enum BaseExprKind {
|
||||
Num(i64),
|
||||
Str(String),
|
||||
Sym(Sym),
|
||||
Ident(String),
|
||||
Ident(Sym),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@@ -37,23 +36,3 @@ pub struct BaseExpr {
|
||||
pub kind: BaseExprKind,
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
// FromAst and IntoAst are just so we can use .into_ast(ctx, text)
|
||||
// some impls may not need ctx &mut ref - but probably needed for symbol resolution
|
||||
|
||||
pub trait FromAst<A> {
|
||||
fn from_ast(other: A, ctx: &mut Ctx, text: &str) -> Self;
|
||||
}
|
||||
|
||||
pub trait IntoIr<I> {
|
||||
fn into_ir(self, ctx: &mut Ctx, text: &str) -> I;
|
||||
}
|
||||
|
||||
impl<A, I> IntoIr<I> for A
|
||||
where
|
||||
I: FromAst<A>,
|
||||
{
|
||||
fn into_ir(self, ctx: &mut Ctx, text: &str) -> I {
|
||||
FromAst::from_ast(self, ctx, text)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user