On Wed Nov 21 07:45:53 2007, [EMAIL PROTECTED] wrote: > Setting the :vtable pragma on a sub should enable the 'self' shortcut > for the current invocant. As in the following code example where a > method is called from within a vtable override: > > .sub main :main > $P1 = newclass "Foo" > $P2 = new "Foo" > $S1 = $P2 > print $S1 > .end > > .namespace [ "Foo" ] > > .sub get_string :vtable > self.'bar'() > .return ("stringy thingy\n") > .end > > .sub bar :method > print "called bar\n" > .end > > (Pulled from rejected ticket #42430.) > > Allison
Attached is a patch that does almost the right thing. It allows "self" to be used in functions marked :vtable, not just functions marked :method or ":vtable :method". However, the example above does not work. The call to self.'bar'() triggers a "null PMC access in find_method()" error. Without that method invocation, there is no error, and the function works as expected (prints "stringy thingy"). I assume the :method invocation changes the PMC type of the self parameter, or adds some kind of class field to it that isn't there otherwise. I don't know enough about PCC internals to fix this part of the problem, although I will keep looking at it. --Andrew Whitworth
Index: compilers/imcc/imcc.l =================================================================== --- compilers/imcc/imcc.l (revision 28866) +++ compilers/imcc/imcc.l (working copy) @@ -557,7 +557,8 @@ (r = IMCC_INFO(interp)->cur_unit->instructions->symregs[0]) && r->pcc_sub) { - if ((r->pcc_sub->pragma & P_METHOD) && + if (((r->pcc_sub->pragma & P_METHOD) || + (IMCC_INFO(interp)->cur_unit->is_vtable_method)) && !strcmp(yytext, "self")) { valp->sr = mk_ident(interp, "self", 'P'); IMCC_INFO(interp)->cur_unit->type |= IMC_HAS_SELF;