Edwin Steiner wrote:
> 
> Dan Sugalski wrote:
> [snip]
> > That's OK, since my example was wrong. (D'oh! Chalk it up to remnants of
> > the martian death flu, along with too much blood in my caffeine stream) The
> > example
> >
> >   $foo{bar} = $baz + $xyzzy[42];
> >
> > turns into
> >
> >    baz->vtable->add[NATIVE](foo, baz, xyzzy, key);
> 
> Why does the bytecode compiler know it should generate NATIVE int addition?
> Are you assuming 'use integer'? (see also next comment)
[snip]

I thought about it once more. Maybe I was confused by the *constant* NATIVE.
Are you suggesting a kind of multiple dispatch (first operand selects
the vtable, second operand selects the slot in the vtable)?

So
    $dest = $first + $second
becomes
    first->vtable->add[second->vtable->type(second)](dest,first,second,key);
?

or maybe
    first->vtable->add[second->vtable->slot_select](dest,first,second,key);
which saves a call by directly reading an integer from the vtable of <second>.

(BTW, this is also how overloading with respect to the second argument
could be handled (should it be decided on the language level to do that):
There could be a slot like add[ARCANE_MAGIC] selected by
second->vtable->slot_select
which does all kinds of complicated checks and branches without any cost
for the vfunctions in the other slots.)

Such a multiple dispatch seems to me like the only solution which avoids
the following (eg. in Python):
    'first + second' becomes
        1. call virtual function 'add' on <first>
        2. inside first->add do lots of checks about type of <second>

-Edwin

Reply via email to