diff --git a/src/compiler.rs b/src/compiler.rs index 5404e41..2a48e96 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -276,13 +276,27 @@ impl FakeStack<'_> { /// * Keeps track of its own shared stack (contains vars that higher functions access) /// * Keeps track of its own local stack (vars only used locally) struct FuncBuild<'a> { - parent: Option<&'a FuncBuild<'a>>, insts: Vec, shared: FakeStack<'a>, local: FakeStack<'a>, } -impl FuncBuild<'_> { +impl<'a> FuncBuild<'a> { + fn new_root() -> Self { + FuncBuild { + insts: Vec::new(), + shared: FakeStack::with_parent(None), + local: FakeStack::with_parent(None), + } + } + fn with_parent(parent: &'a FuncBuild<'a>) -> Self { + FuncBuild { + insts: Vec::new(), + shared: FakeStack::with_parent(Some(&parent.shared)), + local: FakeStack::with_parent(None), + } + } + fn translate(&mut self, bb: &mut BlockBuild, e: &Expr) { match e { _ => unimplemented!(), @@ -290,10 +304,15 @@ impl FuncBuild<'_> { } } -pub fn compile(e: &mut Expr) { +pub fn analysis_demo(e: &mut Expr) { + // analysis pass let fs = FuncStat::default(); let mut scope = Scope::with_parent(None); analyze(&fs, &mut scope, e); - // let mut fg = FuncGen::default(); - // fg.translate(&e); +} +pub fn translation_demo(e: &Expr) { + // translation pass + let mut fb = FuncBuild::new_root(); + let mut bb = BlockBuild {}; + fb.translate(&mut bb, e); } diff --git a/src/main.rs b/src/main.rs index f41d60d..ca17fa9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,18 +10,21 @@ mod parser; fn main() { let script = std::fs::read_to_string("./start.lf").unwrap(); let lexer = Lexer::new(script.chars()); - let mut parser = Parser::new(lexer.map(Result::unwrap)); + let start = Instant::now(); let block = parser.parse().unwrap(); println!("Parse took {:?}", start.elapsed()); - let mut e = parser::Expr::Block(block); parser::util::display(&e); let start = Instant::now(); - compiler::compile(&mut e); - + compiler::analysis_demo(&mut e); println!("Analysis took {:?}", start.elapsed()); parser::util::display(&e); + + let start = Instant::now(); + compiler::translation_demo(&mut e); + println!("Translation took {:?}", start.elapsed()); + parser::util::display(&e); }