Move MethodInst stack mangling to MethodInst::call
When a MethodInst is called as a function in the VM, it needs to push its `self_binding` member to the stack. Previously, we were downcasting (if possible) to MethodInst in the VM, but really, we are calling `MethodInst::call` anyway, so it makes more sense to do MethodInst-specific stuff in the MethodInst-specific function. Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
10
src/obj.rs
10
src/obj.rs
@@ -1079,10 +1079,16 @@ impl Display for MethodInst {
|
||||
|
||||
impl Obj for MethodInst {
|
||||
fn arity(&self) -> Option<Argc> {
|
||||
self.function.borrow().arity()
|
||||
// Subtract one from the arity - this is because the VM uses arity() to check against the
|
||||
// number of arguments passed.
|
||||
self.function.borrow().arity().map(|arity| arity - 1)
|
||||
}
|
||||
|
||||
fn call(&self, vm: &mut Vm, argc: Argc) {
|
||||
fn call(&self, vm: &mut Vm, mut argc: Argc) {
|
||||
let self_pos = vm.stack().len() - (argc as usize);
|
||||
vm.stack_mut().insert(self_pos, self.self_binding.clone());
|
||||
argc += 1;
|
||||
|
||||
self.function.borrow().call(vm, argc)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user