lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Ok -- sorry for the spam, but, I think I've got the register thing more or less figured out.  This version of inc_assignment seems pretty safe:

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

On Fri, Sep 7, 2012 at 12:51 PM, Matthew Wild <mwild1@gmail.com> wrote:
On 7 September 2012 20:14, Jeff Smith <spammealot1@live.co.uk> wrote:
> Hi
>
> I found the link eventually, I think this is it
>
> https://github.com/idmillington/lua/tree/mutation-operators

Yep, original post: http://lua-users.org/lists/lua-l/2011-06/msg01223.html

I'm curious about how it disappeared from PowerPatches...

Regards,
Matthew