lua-users home
lua-l archive

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


On 17 December 2015 at 17:59, Roberto Ierusalimschy
<roberto@inf.puc-rio.br> wrote:
>> Now I have a more involved question.
>>
>> Using type assertion I want to be able to do following:
>>
>> @number[] { 1,2,3 }
>>
>> I would like to change the OP_NEWTABLE instruction generated above to
>> a specialized opcode that creates number[] instead. The problem is
>> that when the parser sees the expression @number[] exp - the exp is
>> already VNONRELOC, so the information regarding the OP_NEWTABLE
>> instruction is no longer present. To solve this I would like to add a
>> new field in the exp structure to hold the last u.info value when
>> exp.k was VRELOCABLE. Because then I can get back to the OP_NEWTABLE
>> instruction and change it.
>>
>
> It seems more complicated than necessary. Can't the @number[] handler
> just grab the next 'pc' before calling 'constructor'? (There is where
> the OP_NEWTABLE will be.) Or couldn't 'constructor' return that
> position?
>

@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.

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

Regards
Dibyendu