Calling convention says that before a sub/method is invoked:

- P0 Holds the object representing the subroutine.

- P1 Holds the continuation for the caller, assuming this sub was called
with callcc. Otherwise NULL.

- P2 Holds the object the sub was called on. (For method calls)

Or put another way P2 is the receiver object. So I guess this was a typo;
the continuation should be stashed in P1.

While I am at it, here is an **untested** implementation of the call_method
op. I don't want to send a patch since I am not sure how to test this yet
(since no PMCs respond to find_method).

op call_method(in STR) {
  opcode_t *dest;
  /* assumes receiver object is in P2 */
  PMC* receiver = interpreter->ctx.pmc_reg.registers[2];
  PMC* method = receiver->vtable->find_method(interpreter, receiver, $1);

  /* calling convention says that method should be in P0 and name in S0 */
  interpreter->ctx.pmc_reg.registers[0] = method;
  interpreted->ctx.string_reg.registers[0] = $1;

  dest = (opcode_t *)method->vtable->invoke(interpreter, method, expr
NEXT());
  goto ADDRESS(dest);
}

op call_method(in PMC, in STR) {
  opcode_t *dest;
  PMC* method = $1->vtable->find_method(interpreter, $1, $2);

  /* calling convention says that receiver should be in P2 and method in P0
*/
  interpreter->ctx.pmc_reg.registers[0] = method;
  interpreter->ctx.pmc_reg.registers[2] = $1;
  interpreted->ctx.string_reg.registers[0] = $2;

  dest = (opcode_t *)method->vtable->invoke(interpreter, method, expr
NEXT());
  goto ADDRESS(dest);
}

--
Jonathan Sillito

> -----Original Message-----
> From: Nicholas Clark [mailto:[EMAIL PROTECTED] Behalf Of Nicholas
> Clark
>
> I'm not sure if I'm asking a stupid question here, but:
>
> On Fri, May 30, 2003 at 08:12:34AM -0400, Dan Sugalski wrote:
>
> > We add three ops, findmeth, callmeth and callmethcc. (The latter just
> > automatically takes a continuation for the following op and stashes
> > it in P2, while the former assumes one has been put in P2 already)
>
> You say P2 is a continuation
>
> > They all find a method PMC based on the object and method name
> > already loaded. The call ops then call
> >   that PMC's invoke vtable entry, which acts as normal.
> >
> > So the sequence is:
> >
> >     P0 = P2->find_method(interpreter, P2);
>
> But you seem to be using P2 like it's the object
> I'm confused.
> Surely there are 3 things to play with - object, method name and
> continuation to "return" to? If so, are they P0, P1 and P2 before these
> ops?
>
> Nicholas Clark
>

Reply via email to