[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua 5.2 wish item: Splicing
- From: "Rici Lake" <lua@...>
- Date: Tue, 14 Nov 2006 15:30:17 -0000 (GMT)
Javier Guerra wrote:
> On Tuesday 14 November 2006 8:35 am, Rici Lake wrote:
>> -- in other words, a following ',' causes normalization to one value:
>>
>> { f(); g(), h() }
>>
>> ==>
>>
>> f() and h() are fully expanded, g() is normalized to a single value
>
> looks great! and about parameter lists?
Sadly, that's much more difficult. Splicing during table construction is
possible because all the values can be flushed to the table at any time.
However, in a parameter list, the VM must know the indices of local
temporaries, which will not be known if they are on top of a variable
number of return values.
However, you can do this:
foo(unpack{f(); g(), h()})
As an example of why parameter lists are difficult, consider:
foo(f(); g(), h())
That's going to have to translate into something like:
GETGLOBAL 0, 'foo'
GETGLOBAL 1, 'f'
CALL 1, 1, 0 # 0 args, multi return
GETGLOBAL ?, 'g'
...
The value of ? is not known at compile-time, since it is 1 + (number of
return values of f). In theory, you could shuffle the return values around
somewhere, but putting them in a table and then unpacking the table is not
likely to be much less efficient.