lua-users home
lua-l archive

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


Hello !

I've updated the repositories with fixes for compound operators on upvalues and also added pre/pos increment operators "++/--".

Cheers !

On 24/11/2018 05:29, Felipe Tavares wrote:
Hey Domingo, I took a look and the solution in there is indeed a bit better than mine!

Instead of changing the source code to not free the registers, we reserve a new register before parsing (lparser.c, assign_compound()):


/* store compound results in a new register (needed for nested tables) */
luaK_reserveregs(fs, 1);

/* parse right-hand _expression_ */
nexps = explist(ls, &rh);
check_condition(ls, nexps == 1, "syntax error in right hand _expression_ in compound assignment");

infix = lh->v;
luaK_infix(fs,op,&infix);

luaK_posfix(fs, op, &infix, &rh, line);
luaK_storevar(fs, &(lh->v), &infix);

`++` and `--` are pretty easy! I think prefix is easier to start because you can stuff the mod in the code that does unary operations for stuff like `-1`. For suffix, it think it would go after the code for indexing. The implementation itself is easy, you just have to construct a `expdesc` for the value of 1, sum it with the variable and store it back, it should be mostly reusing the code for compound assignment.

Thanks a lot for this repos, they're gold!

On Nov 23 2018, at 10:41 am, Domingo Alvarez Duarte <mingodad@gmail.com> wrote:

Hello Felipe !

Look at this https://github.com/mingodad/ljs where I've got ideas and
https://github.com/sajonoso/jual and fixed the code for "+= -= *= /= %="
to work with indexed variables.

See the table-decl.ljs .

There is a program to translate ".lua" to ".ljs" on folder lua2ljs it
uses lemon and re2c to parse lua files and convert to ljs (lua with
C/C++/Java/_javascript_ syntax, there is no reason for the extensions to
also work with the original lua syntax.

I also have it done for luajit but it's not yet published.

If anyone want to help I'm now looking for how to implement pre/post
increment/decrement "++"/"--" operators and a class system.

Cheers !
Open Tracking