Add function compilation

Functions are compiled in the most naiive way right now. I want to fix
up how scope lookups are done before it becomes too much to update.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2020-09-26 18:31:23 -07:00
parent 3976b2135a
commit 4848a342f0
7 changed files with 53 additions and 21 deletions

View File

@@ -143,16 +143,16 @@ impl<'p> Vm<'p> {
fn begin_call(&mut self, caller: ObjRef, args: Vec<ObjRef>) {
// create stack frame
let stack_frame = if let Some(user_fun) = std::any::Any::downcast_ref::<UserFunRef>(&caller) {
let locals = {
let names: Names = {
read_obj!(let fun_ref = user_fun);
fun_ref.locals()
.iter()
.zip(args.into_iter())
.map(|((k, _), v)| (*k, v))
.map(|((_, v), arg)| (*v, arg.clone()))
.collect()
};
Frame::new(locals, FrameKind::User {
Frame::new(names, FrameKind::User {
last_pc: self.pc(),
stack_base: self.stack().len(),
fun: user_fun.clone(),