Skip to content

Commit

Permalink
Fix bug where "this" got mangled on pass()
Browse files Browse the repository at this point in the history
  • Loading branch information
rdaum committed Jul 23, 2023
1 parent b7d2362 commit 628a52e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
12 changes: 0 additions & 12 deletions moor-lib/src/vm/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,19 +432,7 @@ impl VM {
this: Objid,
verb: String,
args: &[Var],
do_pass: bool,
) -> Result<ExecutionResult, anyhow::Error> {
let this = if do_pass {
let valid_definer = state.valid(self.top().verb_definer())?;

if !valid_definer {
return self.push_error(E_INVIND);
}
state.parent_of(this)?
} else {
this
};

let self_valid = state.valid(this)?;
if !self_valid {
return self.push_error(E_INVIND);
Expand Down
16 changes: 9 additions & 7 deletions moor-lib/src/vm/vm_execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl VM {
.next_op()
.expect("Unexpected program termination; opcode stream should end with RETURN or DONE");

trace!("exec: {:?} stack: {:?}", op, self.top().valstack);
trace!("exec: {:?} this: {:?} player: {:?} stack: {:?}", op, self.top().this, self.top().player, self.top().valstack);
match op {
Op::If(label) | Op::Eif(label) | Op::IfQues(label) | Op::While(label) => {
let cond = self.pop();
Expand Down Expand Up @@ -456,24 +456,26 @@ impl VM {
return self.push_error(E_TYPE);
};
// get parent of verb definer object & current verb name.
let this = self.top().verb_info.attrs.definer.unwrap();
let parent = state.parent_of(this)?;
// TODO probably need verb definer right on Activation, this is gross.
let definer = self.top().verb_info.attrs.definer.unwrap();
let parent = state.parent_of(definer)?;
let verb = self.top().verb_name().to_string();

// call verb on parent, but with our current 'this'
let task_id = self.top().task_id;
trace!(
"Pass: task_id: {:?} verb: {:?} this: {:?}",
"Pass: task_id: {:?} verb: {:?} definer: {:?} parent: {:?}",
task_id,
verb,
this
definer,
parent
);
self.do_method_verb(
task_id,
state,
parent,
verb.as_str(),
this,
self.top().this,
self.top().player,
self.top().player_flags,
&args,
Expand All @@ -489,7 +491,7 @@ impl VM {
};
// TODO: check obj for validity, return E_INVIND if not

return self.call_verb(state, *obj, verb.clone(), args, false);
return self.call_verb(state, *obj, verb.clone(), args);
}
Op::Return => {
let ret_val = self.pop();
Expand Down

0 comments on commit 628a52e

Please sign in to comment.