[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Bytecode hacks
- From: Roberto Ierusalimschy <roberto@...>
- Date: Fri, 23 May 2014 16:57:31 -0300
> On 5/21/2014 8:27 PM, Luiz Henrique de Figueiredo wrote:
> >>I think there are patchs around for the t:[var]() syntax.
> >Actually, this one seems simple. A quick hack is to just change
> >suffixedexp in lparser.c (from Lua 5.2.3):
> >
> > case ':': { /* `:' NAME funcargs */
> > expdesc key;
> > luaX_next(ls);
> >- checkname(ls, &key);
> >+ if (ls->t.token=='[') {
> >+ luaK_exp2anyregup(fs, v);
> >+ yindex(ls, &key);
> >+ }
> >+ else
> >+ checkname(ls, &key);
> > luaK_self(fs, v, &key);
> > funcargs(ls, v, line);
> > break;
> > [...]
(Thanks for the debugging!)
> The luac listing of these cases are all of this form:
> 22 [10] CALL 3 0 2
> 23 [10] SELF 4 0 3
> 24 [10] LOADK 5 -10 ; 3
> 25 [10] LOADK 6 -11 ; 32
> 26 [10] LOADK 7 -12 ; 33
> 27 [10] CALL 4 4 1
>
> The C argument of SELF is always a register, the same register as
> the the A argument of the previous CALL.
> Correct bytecode for the case above should be like this:
> 22 [10] CALL 3 0 2
> 23 [10] SELF 4 0 3
> 24 [10] LOADK 6 -10 ; 3
> 25 [10] LOADK 7 -11 ; 32
> 26 [10] LOADK 8 -12 ; 33
> 27 [10] CALL 4 5 1
The problem is related to 'luaK_reserveregs' (done in 'luaK_self'). The
opcode OP_SELF needs ra + 1 as a temporary, so nothing can go there. In
the correct code, register 5 (the next after 'ra' in SELF) is left free,
so that SELF can use it.
To fix this bug, I think the patch cannot call 'yindex'. Instead, it
must do what 'yindex' does but without calling 'luaK_exp2val'. (This
is a wild guess ;)
-- Roberto