lua-users home
lua-l archive

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





> On Mar 7, 2015, at 5:01 PM, Dibyendu Majumdar <mobile@majumdar.org.uk> wrote:
> 
>> On 7 March 2015 at 21:16, Dirk Laurie <dirk.laurie@gmail.com> wrote:
>> Some strongly-typed languages have identifiers that signal
>> type. Fortran with the IJKLMN => integer convention and
>> IMPLICIT statement. Perl with those ugly suffixes.
>> 
>> Would efficiency and/ore user-friendliness be improved with
>> that kind of thing?
> 
> Hi Dirk,
> 
> Thanks - this is very relevant.
> 
> I am already using optional typing to make the code more efficient.
> This is helped by the fact that Lua 5.3 distinguishes between integer
> and floating points.
> The optional typing helps the compiler to generate floating point or
> integer operations without having to check this at runtime. So for
> example in standard Lua 5.3 an addition always requires a type check.
> The first test is to see if the values are integers, then if they are
> floats, and finally if user defined operation is available. Whereas by
> using type annotation I can avoid all that and directly perform
> integer or floating point addition.
> 
> I like the idea that if you don't specify types then it defaults to
> standard Lua behaviour.
> 
> I think more optimization is possible though. For instance - could I
> avoid setting the types if the compiler knows they are
> integer/floating? I thought I could but I found an issue.
> Types can be preset for locals so those are fine.
> But when expressions are evaluated using temporary registers then if
> the type is not set what happens is that any operation that uses the
> temporary value gets the wrong type. Perhaps the compiler could be
> clever enough to set the type at the end of the expression evaluation
> rather than at every step. I will look into this more at some point.

Wouldn't the solution to this be to have typed temporaries?


> Thanks and Regards
> Dibyendu
>