lua-users home
lua-l archive

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




On Friday, 18 December 2015, Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
> @number[] is a unary operator - the call to constructor may or may not
> happen inside the subexpr() that follows, so am not sure above is
> possible. But I do find that when the unary operator is processed, the
> current 'pc' is on OP_NEWTABLE instruction in the example above.

What does '@number[]' do?? Why does it need to access OP_NEWTABLE (given
that there may not exist one)?


@number[] does two things:
If applied to a table constructor it converts the table to number[] which is a specialisation of the table. This is done by changing the op code from OP_NEWTABLE to OP_RAVI_NEWARRAYF. 
If applied to an _expression_ that is not a constructor it generates a OP_RAVI_TOARRAYF instruction which will assert at runtime that the _expression_ is of type number[].
 

> Is it always the case that a unary operator applies to the previous
> bytecode instruction?

No. Even the notion of "previous" is messy. What is previous to minus
in _expression_ '-(a or b)'?

        1       [1]     TESTSET         2 0 1
        2       [1]     JMP             0 1     ; to 4
        3       [1]     MOVE            2 1
        4       [1]     UNM             2 2


I must have looked incorrectly also as the table constructor sequence is OP_NEWTABLE, OP_LOADK, OP_SETLIST, so the current instruction can't be pointing to the OP_NEWTABLE.

Regards