Sam Ruby wrote:

First, a few things to note: the semantics of "add" vary from language to language. In particular, add is not guaranteed to be commutative in Python (think string addition).

Yes, of course.

As my proposal is primarily focused on where the logic is placed in the system, not how it works, I'll like to use your proposal <http://xrl.us/egvp> as a starting point. Just to make sure that I don't mischaracterize your proposal, can you take a look at the attached and either agree that it represents a reasonable first approximation of what you had in mind, or modify it so that it is?

It's a reasonable respresentation, yes. Finding the right functions is more complex, though, as described in my proposal.


I'd just outline the functionality of the "add" opcode like this:

  inline op add (out PMC, in PMC, in PMC) :base_core {
      PRESERVE_CONTEXT;
      add_func = mmd_find("__add"...) // via VTABLE_find_method
      REG_PMC(5) = $2;
      REG_PMC(6) = $3;
      VTABLE_invoke(interp, add_func, 0);
      res = REG_PMC(5);
      RESTORE_CONTEXT;
      $1 = res;
  }

the basics are:
* the destination PMC $1 is created by the opcode
* no other registers are changed, nor the context
* finding the "__add" method uses VTABLE_find_method to
  find all possible "__add" methods and a distance
  function to get the best match
* the best matching function is invoked

Once that's done, I'll sketch out all of the changes required to enable Perl and Python to each have their own separate semantics for this operation, and yet be able to have meaningful interop when it comes to adding a PerlInt and a PyInt, or vice versa.

Great, thanks.

- Sam Ruby

leo



Reply via email to