I've updated the repositories with fixes for compound operators
on upvalues and also added pre/pos increment operators "++/--".
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) */ |
/*
parse right-hand _expression_ */ |
nexps = explist(ls,
&rh); |
check_condition(ls,
nexps == 1, "syntax error
in right hand _expression_ in compound assignment"); |
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!
Hello Felipe !
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 !