separate compile steps in demo
This commit is contained in:
parent
ea9614a903
commit
167c0956b1
|
@ -276,13 +276,27 @@ impl FakeStack<'_> {
|
||||||
/// * Keeps track of its own shared stack (contains vars that higher functions access)
|
/// * Keeps track of its own shared stack (contains vars that higher functions access)
|
||||||
/// * Keeps track of its own local stack (vars only used locally)
|
/// * Keeps track of its own local stack (vars only used locally)
|
||||||
struct FuncBuild<'a> {
|
struct FuncBuild<'a> {
|
||||||
parent: Option<&'a FuncBuild<'a>>,
|
|
||||||
insts: Vec<Inst>,
|
insts: Vec<Inst>,
|
||||||
shared: FakeStack<'a>,
|
shared: FakeStack<'a>,
|
||||||
local: 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) {
|
fn translate(&mut self, bb: &mut BlockBuild, e: &Expr) {
|
||||||
match e {
|
match e {
|
||||||
_ => unimplemented!(),
|
_ => 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 fs = FuncStat::default();
|
||||||
let mut scope = Scope::with_parent(None);
|
let mut scope = Scope::with_parent(None);
|
||||||
analyze(&fs, &mut scope, e);
|
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);
|
||||||
}
|
}
|
||||||
|
|
11
src/main.rs
11
src/main.rs
|
@ -10,18 +10,21 @@ mod parser;
|
||||||
fn main() {
|
fn main() {
|
||||||
let script = std::fs::read_to_string("./start.lf").unwrap();
|
let script = std::fs::read_to_string("./start.lf").unwrap();
|
||||||
let lexer = Lexer::new(script.chars());
|
let lexer = Lexer::new(script.chars());
|
||||||
|
|
||||||
let mut parser = Parser::new(lexer.map(Result::unwrap));
|
let mut parser = Parser::new(lexer.map(Result::unwrap));
|
||||||
|
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
let block = parser.parse().unwrap();
|
let block = parser.parse().unwrap();
|
||||||
println!("Parse took {:?}", start.elapsed());
|
println!("Parse took {:?}", start.elapsed());
|
||||||
|
|
||||||
let mut e = parser::Expr::Block(block);
|
let mut e = parser::Expr::Block(block);
|
||||||
parser::util::display(&e);
|
parser::util::display(&e);
|
||||||
|
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
compiler::compile(&mut e);
|
compiler::analysis_demo(&mut e);
|
||||||
|
|
||||||
println!("Analysis took {:?}", start.elapsed());
|
println!("Analysis took {:?}", start.elapsed());
|
||||||
parser::util::display(&e);
|
parser::util::display(&e);
|
||||||
|
|
||||||
|
let start = Instant::now();
|
||||||
|
compiler::translation_demo(&mut e);
|
||||||
|
println!("Translation took {:?}", start.elapsed());
|
||||||
|
parser::util::display(&e);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue