lua-users home
lua-l archive

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


It was thus said that the Great Sergey Zakharchenko once stated:
> Hello list,

  Hello.

> One of Lua's greatest strengths is its hackability. It's possible to
> add custom opcodes and operators representing them, but in doing so,
> we break source-level compatibility. What if we could have a universal
> and familiar syntax representing the operations? Here's what I have on
> my mind:
> 
> ------------------------------------------------------------
> In BNF: edit
> 
> prefixexp ::= var | functioncall | ( exp )
> 
> to read
> 
> prefixexp ::= var | functioncall | ( exp ) | ` ( exp )
> 
> In expression documentation, add:
> 
> `(exp) is equivalent to exp, but possibly optimized in an
> implementation-specific manner.
> ------------------------------------------------------------
> 
> E.g. print(`(fn())) would be equivalent to print(fn()) (and, in
> particular, NOT to print((fn()))).
> 
> The no-op implementation of the above should be trivial. Actual
> optimization-capable implementations could be larger, require larger
> lookahead, etc. but could encode typical operations as
> implementation-specific opcodes with no need to expose them on the
> source level. Therefore, such implementations would be
> source-level-compatible.

  So if I understand the proposal, it's an indication to the Lua parser that
if it understands an expression, it should optimize it?  For example, if
this had been in Lua 5.2, and I wrote:

	x = `(bit32.band(a,b))

then in theory, if an extension to Lua added the '&' operator, then it could
be rewritten (by the parser) as:

	x = a & b

  Am I close here?

> In general, such optimizations could be questionable, e.g.
> `(type(a)=="number")) needs 'type' to be accessible and point to the
> real 'type', which may not be the case (you never know what's in that
> _ENV). Therefore, they need to be explicitly enabled at load (parse)
> time, by conditional compilation, or something like:

  Or is it a way to prevent side effects from potential monkey patching? 
Can you give an example of some code and how it would be expected to work?

  -spc