[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Ternary operator patch
- From: David Manura <dm.lua@...>
- Date: Sat, 18 Sep 2010 16:41:29 -0400
On Sun, Sep 12, 2010 at 7:19 PM, Drake Wilson <drake@begriffli.ch> wrote:
> In a Lua variant I have sitting
> around locally, I use a preprocessor that includes n-ary conditional
> operator with equivalent syntax to the if/then/elseif/then/else/end
> statement but with expressions instead of statements. It converts the
> expression as:
>
> if a then b elseif c then d else e end
> ==> _PP.expr_if((( a ) and _PP.expr_then( b ))
> or (( c ) and _PP.expr_then( d ))
> or (_PP.expr_then( e )) or nil)
The run-time overhead that that adds can be avoided. It is possible
to mechanically translate expression ifs into their statement format.
Something related to that was done in [1] -- i.e. first rewrite it in
terms of an anonymous function and then inline the function. To some
extent you can also preserve line numbers across the translation to
lesson the impact on debugging info, but it might not be perfect [2],
and I haven't tried. Overall it's not the simplest thing to do
though.
[1] http://lua-users.org/wiki/SourceOptimizer
[2] http://lua-users.org/lists/lua-l/2010-06/msg00311.html
- References:
- Re: Ternary operator patch, David Kastrup
- Re: Ternary operator patch, Miles Bader
- Re: Ternary operator patch, David Kastrup
- Re: Ternary operator patch, Jonathan Castello
- Re: Ternary operator patch, Roberto Ierusalimschy
- Re: Ternary operator patch, Enrico Tassi
- Re: Ternary operator patch, Doug Rogers
- Re: Ternary operator patch, HyperHacker
- Re: Ternary operator patch, GrayFace
- Re: Ternary operator patch, Jonathan Castello
- Re: Ternary operator patch, Drake Wilson