lua-users home
lua-l archive

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


>  Every function has its own pool of constants.

From the point of view of garbage collection, this has the benefit that if a large string constant is only used inside a single function, then if the function becomes garbage then we can also free the large string constant.

In other programming languages, it might also be reasonable to have a constant table per "program", instead of one per function. However, in Lua the unit of compilation is the function, so one constant table per function is definitely the way to go.

> Version 5.4 created several different opcodes, mainly to avoid the tests you mentioned in item 1.

These would be the various opcodes with "I" in the name, such as LOADI, ADDI, EQI, etc. In these opcodes, the second operand is always a small integer that is stored in the instruction itself instead of in the constant table.

One thing that confused me at first is that the "I" actually stands for "immediate operand", not "integer". The resulting operation may or may not be an integer operation, depending on the type of the first operand.

-- Hugo