lua-users home
lua-l archive

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

I think this is very theoretical question, such optimization would not
really be necessary for practical use.

Lua is interpreter language - it has no pre-compiler like C to "strip
stupid code". (well it has this "load function producing binary code"
- this could possibly do this in some future possibly). But if a user
somehow produces "stupid code" sometimes there might even some
reasonable debug reason for this ... I really sometimes get crazy with
optimizing C compilers when debugging code ... Keil ARM CC often tends
to "optimize / strip" the code so much, that the Keil debugger itself
somehow has problems to identify the link between c and assembly code
and then sometimes even sets breakpoints to a wrong point... .

I think the const is nice to assist the user to produce secure code.
Also it is nice to indentify variables for which Lua could skip
(possibly in some future?) to use alloc / RAM ... .

On Wed, Aug 11, 2021 at 5:28 AM 重归混沌 <> wrote:
> I am more curious, why does Lua not optimize 1==1.
> Thank you.
> Hugo Musso Gualandi <> 于2021年8月2日周一 上午1:07写道:
>> Both the f and the g are being optimized in those examples. Note how
>> the f function uses the LOADK instruction instead of GETUPVAL.
>> The `local a <const> = 1` in your original program is also optimized,
>> transforming the `a == 1` into `1 == 1`. However, Lua doesn't optimize
>> the `1 == 1` as you would expect. That's a separate problem that is
>> unrelated to the constant variables.