|
On Wed, Aug 12, 2009 at 10:17 PM, Doug Currie<doug.currie@gmail.com> wrote: > > On Aug 12, 2009, at 10:14 AM, Doug Rogers wrote: >> >> And I think { get_items()..., "no more" } is a clever solution. Being an >> ellipsis, the ... token has a relatively clear meaning in this context. > > I agree. It looks clear to me, too. Being unsupported syntax now means > there's little risk in adding it: existing code won't break. > >> So I encourage you, Duncan, to try it out and share any results. Even if >> it doesn't work out, you (and we) will learn from it. > To get the ball rolling with some code, I've attached a diff which allows "..." after an expression in an expression list and after a list value in a table constructor, along with a file which has a few tests / examples in it. My knowledge of the Lua source code is not overly great, so the patch may be rather rough in places. This patch is implemented in two parts. Firstly, there is the table constructor part, which involves a major change to the SETLIST opcode. Instead of the SETLIST specifying where to insert the values, each Table structure remembers where SETLIST should insert values. This conveniently does away with the SETLIST with c == 0 edge condition, which can simplify the bytecode verifier. The downsides are an extra int field in every table, and lack of bytecode compatibility. The second part is for expanding expressions in expression lists. In terms of pseudo code, this transforms expression lists like "e1, e2 ..., e3, ..." into "e1, detuple(tuple(e2), e3, ...)", though tuple and detuple are VM opcodes rather than functions. The TUPLE opcode takes 2 or more stack values, copies them to a new tuple data array area of a lua_State, and replaces them with a single value which points to the new position of the values in the tuple array. The DETUPLE opcode expands zero or more tuples back into the stack.
Attachment:
expvar.diff
Description: Binary data
Attachment:
tuples.lua
Description: Binary data