lua-users home
lua-l archive

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


> My questions are:
> a) What does luaK_dischargevars() do?

Code generation for several kinds of expressions is delayed until Lua
knows what it will do with that expression. (For instance, an access
to an upvalue does not immediately create a OP_GETUPVAL instruction,
because table access can use OP_GETTABUP directly.)

So, there are a family of functions in 'lcode.c' to make sure that
expressions are restricted to some specific forms. In particular,
'luaK_dischargevars' makes sure that the result of an expression is not
in a non-local variable (upvalue or table field).


> b) What does discharge2anyreg() do? It seems to also call luaK_dischargevars().

This one restricts even more the expression, getting rid of constants
and ensuring that the expression's value is in a register.


> c) I find that if I call freeexp() below it causes bad code generation
> - presumably because the register gets freed?
> [...]
>     case VNONRELOC: {
>       discharge2anyreg(fs, e);
>       /* freeexp(fs, e); */

Yes. 'freeexp' means "free occasional register being used by 'e'".

-- Roberto