lua-users home
lua-l archive

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




On 2017-09-11 10:25 AM, Roberto Ierusalimschy wrote:
SELF takes 2 inputs and produces 2 outputs, so why's it 1 1 3 and not 1 1 2?
See its description in lopcodes.h:

OP_SELF,/*      A B C   R(A+1) := R(B); R(A) := R(B)[RK(C):string]      */

The outputs go to A,(A+1). It produces output (A+1) before consuming
input C, so "1 1 2" would erase the input before using it. (The other
option would be a slower implementation, using an extra temporary and an
extra move. Changing the order of the assignments would destroy A before
using B, so A and B would need to be different and the instruction would
need three registers anyway.)

Put it in the C stack :P

Jokes aside, thanks for correcting me.


-- Roberto


--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.