Remove Thunks for now.
Since we don't do any language-level indirection, thunks are probably not necessary for now. Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -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<SpInst> {
|
||||
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<SpInst> {
|
||||
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<SpInst>),
|
||||
List(Vec<Thunk>),
|
||||
}
|
||||
|
||||
impl From<SpInst> for Thunk {
|
||||
fn from(inst: SpInst) -> Thunk {
|
||||
Thunk::Block(vec![inst])
|
||||
}
|
||||
}
|
||||
|
||||
impl Thunk {
|
||||
fn flatten(self) -> Vec<SpInst> {
|
||||
use Thunk::*;
|
||||
match self {
|
||||
Block(block) => block,
|
||||
List(list) => list.into_iter().flat_map(Thunk::flatten).collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user