Add Method type for objects

* Methods are wrappers created with an owner and a function, which
  passes the owner as the first argument when the function is called.
* Fix a small bug in the VM where the pc was being set at the wrong
  time

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2020-10-08 16:10:10 -07:00
parent c3121a176c
commit c738c52455
4 changed files with 90 additions and 15 deletions

View File

@@ -149,9 +149,11 @@ impl<'c> Vm<'c> {
let frame = callee_obj.as_fun()
.expect("callable function")
.create_frame(callee.clone(), self, args);
// Jump to the first address of the new function call if it's a user function
if let Frame::User(_) = &frame {
self.set_pc(0);
}
self.frames_mut().push(frame);
// Jump to the first address of the new function call
self.set_pc(0);
}
Signal::Return => {
// 1. pop return value