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:
2020-05-20 14:41:12 -04:00
parent 3ce7384f15
commit 32591f5e29
15 changed files with 306 additions and 206 deletions

View File

@@ -1,6 +1,69 @@
use crate::compile::ir::Body;
use crate::{
syn::{ast::*, op::BinOp, span::*},
compile::{
Ctx,
error::*,
ir,
visit::*,
},
};
// basic block
pub enum Block {
Body(Body),
Body(ir::Body),
}
pub struct TranslateAst<'c, 't> {
ctx: &'c mut Ctx,
text: &'t str,
}
impl<'c, 't> TranslateAst<'c, 't> {
pub fn new(ctx: &'c mut Ctx, text: &'t str) -> Self {
TranslateAst {
ctx,
text,
}
}
pub fn translate(&mut self, ast: &Vec<Stmt>) -> Result<ir::Body> {
todo!()
}
fn visit_lhs_expr(&mut self, expr: &Expr) -> Result<ir::Lhs> {
match expr {
Expr::Bin(b) if b.op == BinOp::Dot => todo!(),
Expr::Base(BaseExpr { kind: BaseExprKind::Ident, .. }) => {
let name = expr.text_at(self.text);
//let name_id = self.ctx.
todo!()
//Ok(ir::Lhs::Name(
}
_ => todo!()
}
}
}
impl Visit<Stmt> for TranslateAst<'_, '_> {
type Out = Result<ir::Stmt>;
fn visit(&mut self, stmt: &Stmt) -> Self::Out {
todo!()
}
}
impl Visit<AssignStmt> for TranslateAst<'_, '_> {
type Out = Result<ir::Stmt>;
fn visit(&mut self, stmt: &AssignStmt) -> Self::Out {
todo!()
}
}
impl Visit<Expr> for TranslateAst<'_, '_> {
type Out = Result<ir::Expr>;
fn visit(&mut self, expr: &Expr) -> Self::Out {
todo!()
}
}