[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: OP_CLOSURE in 5.2
- From: Dirk Laurie <dirk.laurie@...>
- Date: Wed, 6 Feb 2013 07:30:06 +0200
2013/2/6 YuanLin <yuanlin2008@hotmail.com>:
>> > ===============
>> > local a;
>> > a = function() end;
>> > ===============
>> > The code generated was:
>> > ===============
>> > 1 [1] LOADNIL 0 0
>> > 2 [2] CLOSURE 1 0 ; 0x80049078
>> > 3 [2] MOVE 0 1
>> > 4 [2] RETURN 0 1
>> > ===============
>>
> Perhaps I didn't describe my question clearly. I knew the relationship
> between register and local var. What I want to know is the code generation
> policy at lparser.c line 520. I think that we can eliminate the "MOVE"
> instruction by removing this "luaK_exp2nextreg" call, and let
> "luaK_storevar" function to fill register 0 to "CLOSURE" instruction
> directly.
Sure you can, but only if you change the Lua source. That is the code for:
local a = function() end
At the stage that the parser does "local a" it notices that the statement
is complete; its job is now done. The code generation routine gets that
statement only. It does not know an assigment to "a" follows immediately.
You can't expect Lua to generate -O3 style optimized code, and it is
something to be grateful for. What you write in Lua, you get in bytecode,
plain and simple.