lua-users home
lua-l archive

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

I personally also favorize a non keyword based goto statement handling.
I mainly want to use goto statements for compiler generated code and
I have choosen per coincidence the same syntax for labels like
Roberto Ierusamlimschy used in the Beta release. I've just gone one step
further to also avoid a goto keyword at all. To have a full environment to
implement a METALUA like enhancement completely in Lua itself without
a cloned code generator, I've patched the following extensions in
Lua-5.2.0-alpha some weeks ago:

@@            stands for '@' (who knows for what this might be good for.
@string@   -> TK_NAME alas Lua identifier (this is useful for compiler generated identifiers
                      like @125.comment@ guaranteed not to interfere with user
                      choosen identifiers.
@123\n          The often missed line directive for compiler generated code.
                      The next line would be line number 123 of the original file.
                      A proposal to rearange compiler generated code with gotos to fit the
                      original line numbers is not feasible, because sometimes the same line number
                      can be used several times for subconstructs. This solution is also more clean IMHO.
@name:         The label statement (same semantics like the one in the beta release, jumps
                      are only allowed inside one function out of nested blocks and not crossing local
                      variable declarations from above. This is really sufficient even for compiler generated code
                      and I would not like to be trapped by non initialized local variables.
                      Label names have it's own namespace.
@name>        Means the same as "goto name" in the Beta release. On the one hand this is more
                     symmetric in my eyes, because both extensions use an '@' sign and I think it is a
                     good idea to have labels and gotos stich out of the code a bit. Note that the lexer fetches the ':' and
                     the '>'. Therefore there is no conflict with the standard operator '>' or the method call token ':'.
@[ statements @| expression @]    is a block like 'do' ... 'end', but returns an expression instead.
                    These statement expressions are quite nice in compiler generated code, because they
                    avoid a slower construct like "(function () ... return expr)()".

So in the end I used the '@' sign to introduce a couple of extensions to Lua mainly to supply compiler generated
code. On the lexical level they are all implemented in the 'llex.c' module very compactly giving new tokens
TK_NAME, TK_GOTO, TK_LABEL, TK_STATBEG, TK_STATEXPR, TK_STATEND ( the line directive is handled by the lexer
similar as comments are treated but changing the line number variable of course).
I was aware of the naming conflict (using an '@' sign as the first symbol in a chunk file), but I
don't bother. I think it would be appropriate to change the 'load()' procedures to use another symbol for that,
because the '@' sign is quite handy for extensions like the proposed ones or to leave just a space or so if the
first statement of a file chunk is an '@' extension like Roberto suggested earlier in this thread.

I already made some implementation tests for a Metalua and these entensions seem to be sufficient for this task.

If there is personal interest in these patches (of course under the same MIT license like Lua), send me an e-mail,
but I don't want to clobber this mailing list with patch files again.


Michael Rose
Schon gehört? WEB.DE hat einen genialen Phishing-Filter in die
Toolbar eingebaut!