/* ** $Id: lopcodes.h,v 1.52 2000/03/24 19:49:23 roberto Exp roberto $ ** Opcodes for Lua virtual machine ** See Copyright Notice in lua.h */ #ifndef lopcodes_h #define lopcodes_h #include "llimits.h" /*=========================================================================== We assume that instructions are unsigned numbers. All instructions have an opcode in the first 6 bits. 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 bits (called `U') type 2: 1 signed argument in the higher bits (`S') type 3: 1st unsigned argument in the higher bits (`A') 2nd unsigned argument in the middle bits (`B') The signed argument is represented in excess 2^K; that is, the number value is the usigned value minus 2^K. The size of each argument is defined in `llimits.h'. The usual is an instruction with 32 bits, U and S arguments with 26 bits (32-6), B argument with 9 bits, and A argument with 17 bits (32-6-9). For small instalations, the instruction size can be 16, so U and S have 10 bits, and A and B have 5 bits each. ===========================================================================*/ #define EXCESS_S (1<<(SIZE_S-1)) /* == 2^K */ /* creates a mask with `n' 1 bits at position `p' */ #define MASK1(n,p) ((~((~(Instruction)0)<>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) = (((i)&MASK0(SIZE_OP,0)) | (Instruction)(o))) #define SETARG_U(i,u) ((i) = (((i)&MASK0(SIZE_U,POS_U)) | \ ((Instruction)(u)<y)? PC+=s */ OP_IFGEJMP,/* J y x - (x>=y)? PC+=s */ OP_IFTJMP,/* J x - (x!=nil)? PC+=s */ OP_IFFJMP,/* J x - (x==nil)? PC+=s */ OP_ONTJMP,/* J x (x!=nil)? x : - (x!=nil)? PC+=s */ OP_ONFJMP,/* J x (x==nil)? x : - (x==nil)? PC+=s */ OP_JMP,/* J - - PC+=s */ OP_PUSHNILJMP,/* - - nil PC++; */ OP_CLOSURE,/* A B v_b-v_1 closure(KPROTO[a], v_1-v_b) */ OP_SETLINE/* U - - LINE=u */ } OpCode; #define ISJUMP(o) (OP_IFNEQJMP <= (o) && (o) <= OP_JMP) #endif