Leopold Toetsch wrote:

Sam Ruby wrote:

Leopold Toetsch wrote:

A few things to note: "foo" is a PMC. It therefore is an object. It can have state (properties, attributes, etc). It can "know" how many arguments are involved in multiple dispatch.

The MMD information can't hang off the Sub PMCs. How do you find the correct "foo" Sub then?

[snip]

Well, I don't know how the Perl6 compiler will translate:

   foo($a, $b, $c)

If there is more then one "foo" Sub PMC around, the call syntax still must have the number of invocants attached to it, so that MMD can happen.

A "foo" PMC could represent an entire row in a two dimensional MMD, or an entire plane in a three dimensional MMD, ... etc.


A Perl6 compiler could translate the above to:

    87 find_lex P5, "a"
    90 find_lex P6, "b"
    93 find_lex P7, "c"
    96 find_global P0, "foo"
   108 set I0, 1
   111 set I1, 0
   114 set I2, 0
   117 set I3, 3
   120 set I4, 0
   126 invokecc

The "foo" PMC could know how many of the arguments are relevant for MMD dispatch. Should only the first two arguments be relevant, this code could be as simple as:

void* invoke(void* next) {
...
if (cache->type == (Py->vtable->base_type << 16|Pz->vtable->base_type)
return VTABLE_invoke( cache->function );
...
}


[snip]

That code will execute just as fast if placed inside the "invoke" logic of a "MMD PMC".

Where does this hypothetical MMD PMC come from? Where is it created? The opcode is just:


  add Px, Py, Pz

Py or Pz can be plain PyInts or Integers. Where does that MMD PMC come from?

Once MMD is solved connecting it up to the PerlScalar PMC (for example) would be rather straightforward. Syntax like the following would result in an appropriate entry being added to the MMD dispatch table:


  multi sub infix:+ (Us $us, Us $ustoo) {...}

The Parrot_PerlScalar_add function (which would revert back to being a vanilla vtable) would know about the portion of the MMD dispatch table that is relevant to Perl scalar add operations, and invoke it.

(Note: one thing that hasn't been discussed to date is how registers will be handled. The current add opcode doesn't have any side effects)

- Sam Ruby

Reply via email to