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

@@ -382,9 +382,13 @@ impl Visit for CompileBody<'_> {
})
.collect();
let code = self.visit_body(&expr.body)?
let mut code = self.visit_body(&expr.body)?
.flatten()
.to_vec();
// XXX TODO(compile)
// remove this when we get returns implemented
code.push(Inst::PushSym(crate::obj::reserved::NIL_NAME.sym));
code.push(Inst::Return);
let (hdl, _fun) = self.compile.push_const(UserFun::new_obj(code, locals));
// TODO(compile) : determine return value at the end of the body (preferably at parse-time)
@@ -397,6 +401,7 @@ impl Visit for CompileBody<'_> {
let thunk = match atom {
Atom::Ident(ident) => {
let sym = global_sym(ident.to_string());
// TODO : use "LOAD_GLOBAL" instead of "LOAD_LOCAL" when inside a user function
if let Some(local) = self.compile.lookup_local(sym) {
// get local
Inst::LoadLocal(local).into()