Finish up function call implementation, it appears to be working

Functions are downcasted to a `Fun` trait, which will construct the
appropriate stack frame.

A few other things have been shifted around that affect internal APIs
while things are still under construction.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2020-10-07 15:48:24 -07:00
parent 0ca8dc64b2
commit dd7cd04b39
9 changed files with 286 additions and 164 deletions

View File

@@ -23,10 +23,14 @@ impl Compile {
/// Compiles the given AST body.
pub fn compile(mut self, body: &Body) -> error::Result<(ConstPool, UserFunRef)> {
self.push_scope_layer();
let main = thunk::CompileBody::new(&mut self)
let mut main = thunk::CompileBody::new(&mut self)
.compile(body)?
.flatten()
.to_vec();
// XXX TODO(compile)
// remove this when we get returns implemented
main.push(crate::vm::inst::Inst::PushSym(crate::obj::reserved::NIL_NAME.sym));
main.push(crate::vm::inst::Inst::Return);
let globals_syms: std::collections::BTreeMap<_, _> = self.pop_scope_layer().unwrap()
.into_iter()
.map(|(sym, name)| (name, sym))