/* ** $Id: lopcodes.h,v 1.44 2000/03/03 18:53:17 roberto Exp roberto $ ** Opcodes for Lua virtual machine ** See Copyright Notice in lua.h */ #ifndef lopcodes_h #define lopcodes_h /*=========================================================================== We assume that instructions are unsigned numbers with 4 bytes. All instructions have an opcode in the lower byte. Moreover, an instruction can have 0, 1, or 2 arguments. There are 4 types of Instructions: type 0: no arguments type 1: 1 unsigned argument in the higher 24 bits (called `U') type 2: 1 signed argument in the higher 24 bits (`S') type 3: 1st unsigned argument in the higher 16 bits (`A') 2nd unsigned argument in the middle 8 bits (`B') The signed argument is represented in excess 2^23; that is, the real value is the usigned value minus 2^23. ===========================================================================*/ #define SIZE_OP 8 #define SIZE_U 24 #define POS_U 8 #define SIZE_S 24 #define POS_S 8 #define SIZE_A 16 #define POS_A 16 #define SIZE_B 8 #define POS_B 8 #define EXCESS_S (1<<(SIZE_S-1)) /* == 2^23 */ /* creates a mask with `n' 1 bits at position `p' */ #define MASK1(n,p) ((~((~0ul)<>POS_U)) #define GETARG_S(i) ((int)((i)>>POS_S)-EXCESS_S) #define GETARG_A(i) ((int)((i)>>POS_A)) #define GETARG_B(i) ((int)(((i)>>POS_B) & MASK1(SIZE_B,0))) #define SET_OPCODE(i,o) (((i)&MASK0(SIZE_OP,0)) | (Instruction)(o)) #define SETARG_U(i,u) (((i)&MASK0(SIZE_U,POS_U)) | ((Instruction)(u)<y)? 1 : nil */ GEOP,/* - y x (x>=y)? 1 : nil */ ADDOP,/* - y x x+y */ ADDI,/* S x x+s */ SUBOP,/* - y x x-y */ MULTOP,/* - y x x*y */ DIVOP,/* - y x x/y */ POWOP,/* - y x x^y */ CONCOP,/* U v_u-v_1 v1..-..v_u */ MINUSOP,/* - x -x */ NOTOP,/* - x (x==nil)? 1 : nil */ ONTJMP,/* J x (x!=nil)? x : - (x!=nil)? PC+=s */ ONFJMP,/* J x (x==nil)? x : - (x==nil)? PC+=s */ JMP,/* J - - PC+=s */ IFTJMP,/* J x - (x!=nil)? PC+=s */ IFFJMP,/* J x - (x==nil)? PC+=s */ CLOSURE,/* A B v_b-v_1 closure(CNST[a], v_b-v_1) */ SETLINE/* U - - LINE=u */ } OpCode; #define RFIELDS_PER_FLUSH 32 /* records (SETMAP) */ #define LFIELDS_PER_FLUSH 64 /* FPF - lists (SETLIST) (<=MAXARG_B) */ #endif