static int inc_assignment(LexState *ls, struct LHS_assign *lh) {
int line;
BinOpr op = getbinopr(ls->t.token);
FuncState * fs=ls->fs;
luaK_reserveregs(fs,fs->freereg-fs->nactvar); /* reserve all registers needed by the lvalue */
luaX_next(ls);
checknext(ls, '=');
line=ls->linenumber;
enterlevel(ls);
expdesc e = lh->v;
luaK_infix(fs,op,&e);
expdesc v2;
expr(ls,&v2); /* we only match one expr(), so "a+=2,2" will be a parse error. */
luaK_posfix(fs, op, &e, &v2, line);
leavelevel(ls);
luaK_exp2nextreg(fs,&e);
luaK_setoneret(ls->fs, &e);
luaK_storevar(ls->fs, &lh->v, &e);
return 0;
}
On Fri, Sep 7, 2012 at 1:19 PM, Sven Olsen
<sven2718@gmail.com> wrote:
(Looks like it is possible to replace my original kludge with an even uglier one, fixing the bug. More specifically, if I keep track of the top of the stack prior to reading the lvalue, I can use it to figure out how many registers to reserve, thus avoiding register overwriting problems when I construct the rvalue. I have only the fuzziest understanding of why this approach works though.)
On Fri, Sep 7, 2012 at 1:00 PM, Sven Olsen
<sven2718@gmail.com> wrote:
Hrm, well, I've found a bug in my own patch, so, maybe porting Ian's code to 5.2 would be a better option.
It's possible to create situations where my register kludge fails, for example:
local t={a="b"}
local r={a={b=2}}
r.a[t.a]+=2
-Sven