lua-users home
lua-l archive

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


> I feel this is a bit unsatisfactory as really luaV_execute() should
> always do the right thing. But I think the issue stems from the fact
> that 'L->top' is being used to convey information as you have
> described above.
> 
> Is it possible to consider an implementation where L->top is strictly
> the top of the stack, and not used for a dual purpose? Or am I missing
> a point here?

It is not only L->top that has a dual purpose; the stack has a dual
usage, due to the way that Lua uses a register-based VM. While inside
a Lua function, Lua preallocates in the stack all "registers" that the
function will eventually need. So, while running VM instructions in
one function, L->top points to the end of its activation record (stack
frame). When Lua enters or re-enters a Lua function, L->top must be
corrected to this frame, except when multiple returns are involved.
In that case, it is true that L->top is used to pass information
strictly between two consecutive VM instructions. (From either
OP_CALL/OP_VARARG to one of OP_CALL/OP_RETURN/OP_SETLIST.)

Maybe we could use a local variable inside luaV_execute for that task?

-- Roberto