lua-users home
lua-l archive

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


On 11 December 2015 at 23:06, Dibyendu Majumdar <mobile@majumdar.org.uk> wrote:
> Ravi = SOL in unexpected ways :-)
>
> On 9 November 2015 at 22:00, Dibyendu Majumdar <mobile@majumdar.org.uk> wrote:
>> As I progress with Ravi I often wish there was a way to perform type
>> assertion or coercion in the language. For example:
>>
>> local t = { 1 }
>> local i: integer = t[1]
>>
>> Above fails in Ravi as the compiler cannot know that the value
>> returned from t[1] is an integer.
>>

function x()
  local t = { 1 }
  local i: integer = @integer(t[1])
  return I
end
ravi.dumplua(x)

function <stdin:1,5> (8 instructions at 0000025159A747A0)
0 params, 2 slots, 0 upvalues, 2 locals, 1 constant, 0 functions
        1       [2]     NEWTABLE        0 1 0
        2       [2]     LOADK           1 -1    ; 1
        3       [2]     SETLIST         0 1 1   ; 1
        4       [3]     GETTABLE        1 0 -1  ; 1
        5       [3]     TOINT           1
        6       [3]     MOVE            0 1
        7       [4]     RETURN          1 2
        8       [5]     RETURN          0 1
constants (1) for 0000025159A747A0:
        1       1
locals (2) for 0000025159A747A0:
        0       t       4       9
        1       i       7       9
upvalues (0) for 0000025159A747A0:

x()
1