Luke Palmer <[EMAIL PROTECTED]> wrote:
> Leopold Toetsch writes:

>> All infix operators are multi subs. I can't imagine that we want to pay
>> the penalty for simple operations like:
>>
>>   $a = $b + $c
>>
>> to inspect the values of operands, constraints, rules and what not.

> Having written several multi dispatch systems, I know that this is easy
> to optimize.  If nobody has defined + on any fancy subtypes, then we can
> quickly fall back to a bitset-intersection dispatch algorithm on the
> types (or even, eew, direct lookup).

The Plan for implementing MMD is currently (given above add statement):

1) the assembler converts the '+' into something like:

  infix "__add", Pa, Pb, Pc     # which is basically the same as
  Pa = Pb."__add"(Pb, Pc)

2) during predereferncing (once per call site := PBC location):

  .) do a fully dynamic MMD lookup
  .) depending on the found function:
    if its a NCI (C-function, builtin)
       .) convert the opcode to the PIC version:

          cache = cur_opcode[1]
          b = cur_opcode[3]
          c = cur_opcode[4]
          if (cache.types == (b.type | c.type << 16))
              cur_opcode[2] = (cache.c.function)(b,c)
          else
            # ... test more chache entries

     if its an assembly function (user code, overloaded)
        .) convert opcode to a function call
          ...
          if (cache.types == (b.type | c.type << 16))
             VTABLE_invoke(cache.pasm.function)
          ...
        .) add an internal opcode that processes return results and
           restores registers

3) this assumes that the Perl6 compiler or Parrot can detect, when the
infix:<+> operation is overloaded or that another multi variant of that
operations is added. In that case the cache for the involved classes has
to be invalidated.

This works of course only, if the dispatch is on types only.

> ... If + has been defined on fancy
> subtypes, then we compile the quickest way to figure out whether none of
> the arguments are one of them, and fall back.  This is a little tricky,
> but some elementary graph theory gets us there.

This means that the Perl6 compiler emits code to check the constraints
on all possible MMD candidates?

> But we always have enough knowledge to optimize the hell out of this,
> and they're not not handwavy "we can probably" optimizations.  They're
> real, and they're pretty darn easy.

What happens if  C< eval 'infix:<+>(A $a, B $b) {...}' > is done?

> Luke

leo

Reply via email to