cmp VTABLE & MULTI

François Perrad francois.perrad at gadz.org
Mon Oct 13 06:41:44 UTC 2008


In Lua :
     print(nil < nil)        --> attempt to compare two nil values

So basically, in PIR :
     .HLL 'Lua', 'lua_group'

     .sub 'main'
         $P0 = new 'LuaNil'
         $I1 = islt $P0, $P0
         say $I1
     .end

In default.pmc, there is a shortcut then the two pointers are equals :
     VTABLE INTVAL cmp(PMC *value) {
         INTVAL retval;

         /* Don't multidispatch if you've got two pointers to the same 

            PMC. They * are equal. */
         if (SELF == value)
             return 0;

         Parrot_mmd_multi_dispatch_from_c_args(interp,
                 "cmp", "PP->I", SELF, value, &retval);

         return retval;
     }

Since ppd27mmd merge, this shortcut removes the ability to call the
specific Lua code (with the expected exception generation).

Since r31890, it's fixed.
The VTABLE 'cmp' is overloaded in LuaNil PMC without the shortcut
presents in Default PMC. But it isn't the right place, I want overload
VTABLE 'cmp' in LuaAny, the abstract PMC of all Lua types. LuaAny PMC
contains some MULTI 'cmp' and it seems not possible (with current tool)
to define VTABLE and MULTI in the same file.
I think the tool/generator must be improved.

The shortcut in Default PMC looks like a premature optimization.
I suggest a VTABLE 'cmp' without the shortcut in Default PMC and
with the shortcut in Scalar PMC.

François.




More information about the parrot-dev mailing list