diff --git a/src/compile.rs b/src/compile.rs index fe59cee..b1575ba 100644 --- a/src/compile.rs +++ b/src/compile.rs @@ -49,13 +49,12 @@ impl<'s> Compile<'s> { let mut code = Vec::new(); for expr in expr_list { self.discover_locals(&expr); - let thunk = self.compile_expr(&expr); - code.extend(thunk.flatten()); + code.extend(self.compile_expr(&expr)); } code } - fn compile_expr(&mut self, expr: &SpExpr) -> Thunk { + fn compile_expr(&mut self, expr: &SpExpr) -> Vec { match expr.inner() { Expr::Atom(atom) => self.compile_atom(atom), // this gets compiled whenever it gets evaluated @@ -68,12 +67,12 @@ impl<'s> Compile<'s> { self.quote_table .insert(expr.span().clone(), locals, stmts.clone(), compiled); let inst = Inst::PushValue(Value::Quote(quote)); - SpInst::new(expr.span().clone(), inst).into() + vec![SpInst::new(expr.span().clone(), inst)] } } } - fn compile_atom(&mut self, atom: &SpAtom) -> Thunk { + fn compile_atom(&mut self, atom: &SpAtom) -> Vec { let inst = match atom.inner() { Atom::Float(f) => Inst::PushValue(Value::Float(*f)), Atom::Int(i) => Inst::PushValue(Value::Int(*i)), @@ -95,7 +94,7 @@ impl<'s> Compile<'s> { } Atom::Apply => Inst::Call, }; - SpInst::new(atom.span().clone(), inst).into() + vec![SpInst::new(atom.span().clone(), inst)] } /// Discovers and inserts local variables into the scope. @@ -110,25 +109,3 @@ impl<'s> Compile<'s> { } } } - -#[derive(Debug, Clone)] -enum Thunk { - Block(Vec), - List(Vec), -} - -impl From for Thunk { - fn from(inst: SpInst) -> Thunk { - Thunk::Block(vec![inst]) - } -} - -impl Thunk { - fn flatten(self) -> Vec { - use Thunk::*; - match self { - Block(block) => block, - List(list) => list.into_iter().flat_map(Thunk::flatten).collect(), - } - } -}