lua-users home
lua-l archive

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


On 9 November 2015 at 23:09, Dibyendu Majumdar <mobile@majumdar.org.uk> wrote:
> On 9 November 2015 at 22:15, Coda Highland <chighland@gmail.com> wrote:
>>> Now here is a hypothetical question - if Lua had been statically typed
>>> language - what would the ideal expression be for this kind of type
>>> coercion?
>>>
>> Personally I'd go with asinteger() (or perhaps cast.integer(), to
>> limit the namespace pollution to a single keyword) so that the grammar
>> doesn't need modified, and then special-case the function invocation
>> as some kind of intrinsic instead of an actual function call.
>>
>
> I have been thinking about the idea of intrinsics that the VM is aware
> of. Agree that doing it this way means that it behaves no different
> than if there were some functions that did the same thing.
>


Come to think of it actually it could be a noop function - i.e. the
function call would cause the code generator to insert type coercion
operations but then the VM would recognise the noop function and do
nothing. So I can imagine a function called cast() which is this magic
noop function.

local i: integer = cast(x[1])

Would cause the code generator to emit TOINT opcode after calling the
function cast(). But the VM would not call any function at all as it
would recognize 'cast()' as noop.

Does this sound crazy?

Regards