00001
00002
00003
00004
00005
00006
00007 #ifndef lopcodes_h
00008 #define lopcodes_h
00009
00010 #include "llimits.h"
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 enum OpMode {iABC, iABx, iAsBx};
00032
00033
00034
00035
00036
00037 #define SIZE_C 9
00038 #define SIZE_B 9
00039 #define SIZE_Bx (SIZE_C + SIZE_B)
00040 #define SIZE_A 8
00041
00042 #define SIZE_OP 6
00043
00044 #define POS_C SIZE_OP
00045 #define POS_B (POS_C + SIZE_C)
00046 #define POS_Bx POS_C
00047 #define POS_A (POS_B + SIZE_B)
00048
00049
00050
00051
00052
00053
00054
00055 #if SIZE_Bx < BITS_INT-1
00056 #define MAXARG_Bx ((1<<SIZE_Bx)-1)
00057 #define MAXARG_sBx (MAXARG_Bx>>1)
00058 #else
00059 #define MAXARG_Bx MAX_INT
00060 #define MAXARG_sBx MAX_INT
00061 #endif
00062
00063
00064 #define MAXARG_A ((1<<SIZE_A)-1)
00065 #define MAXARG_B ((1<<SIZE_B)-1)
00066 #define MAXARG_C ((1<<SIZE_C)-1)
00067
00068
00069
00070 #define MASK1(n,p) ((~((~(Instruction)0)<<n))<<p)
00071
00072
00073 #define MASK0(n,p) (~MASK1(n,p))
00074
00075
00076
00077
00078
00079 #define GET_OPCODE(i) (cast(OpCode, (i)&MASK1(SIZE_OP,0)))
00080 #define SET_OPCODE(i,o) ((i) = (((i)&MASK0(SIZE_OP,0)) | cast(Instruction, o)))
00081
00082 #define GETARG_A(i) (cast(int, (i)>>POS_A))
00083 #define SETARG_A(i,u) ((i) = (((i)&MASK0(SIZE_A,POS_A)) | \
00084 ((cast(Instruction, u)<<POS_A)&MASK1(SIZE_A,POS_A))))
00085
00086 #define GETARG_B(i) (cast(int, ((i)>>POS_B) & MASK1(SIZE_B,0)))
00087 #define SETARG_B(i,b) ((i) = (((i)&MASK0(SIZE_B,POS_B)) | \
00088 ((cast(Instruction, b)<<POS_B)&MASK1(SIZE_B,POS_B))))
00089
00090 #define GETARG_C(i) (cast(int, ((i)>>POS_C) & MASK1(SIZE_C,0)))
00091 #define SETARG_C(i,b) ((i) = (((i)&MASK0(SIZE_C,POS_C)) | \
00092 ((cast(Instruction, b)<<POS_C)&MASK1(SIZE_C,POS_C))))
00093
00094 #define GETARG_Bx(i) (cast(int, ((i)>>POS_Bx) & MASK1(SIZE_Bx,0)))
00095 #define SETARG_Bx(i,b) ((i) = (((i)&MASK0(SIZE_Bx,POS_Bx)) | \
00096 ((cast(Instruction, b)<<POS_Bx)&MASK1(SIZE_Bx,POS_Bx))))
00097
00098 #define GETARG_sBx(i) (GETARG_Bx(i)-MAXARG_sBx)
00099 #define SETARG_sBx(i,b) SETARG_Bx((i),cast(unsigned int, (b)+MAXARG_sBx))
00100
00101
00102 #define CREATE_ABC(o,a,b,c) (cast(Instruction, o) \
00103 | (cast(Instruction, a)<<POS_A) \
00104 | (cast(Instruction, b)<<POS_B) \
00105 | (cast(Instruction, c)<<POS_C))
00106
00107 #define CREATE_ABx(o,a,bc) (cast(Instruction, o) \
00108 | (cast(Instruction, a)<<POS_A) \
00109 | (cast(Instruction, bc)<<POS_Bx))
00110
00111
00112
00113
00114
00115
00116
00117 #define NO_REG MAXARG_A
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131 typedef enum {
00132
00133
00134
00135 OP_MOVE,
00136 OP_LOADK,
00137 OP_LOADBOOL,
00138 OP_LOADNIL,
00139 OP_GETUPVAL,
00140
00141 OP_GETGLOBAL,
00142 OP_GETTABLE,
00143
00144 OP_SETGLOBAL,
00145 OP_SETUPVAL,
00146 OP_SETTABLE,
00147
00148 OP_NEWTABLE,
00149
00150 OP_SELF,
00151
00152 OP_ADD,
00153 OP_SUB,
00154 OP_MUL,
00155 OP_DIV,
00156 OP_POW,
00157 OP_UNM,
00158 OP_NOT,
00159
00160 OP_CONCAT,
00161
00162 OP_JMP,
00163
00164 OP_EQ,
00165 OP_LT,
00166 OP_LE,
00167
00168 OP_TEST,
00169
00170 OP_CALL,
00171 OP_TAILCALL,
00172 OP_RETURN,
00173
00174 OP_FORLOOP,
00175
00176 OP_TFORLOOP,
00177
00178 OP_TFORPREP,
00179
00180
00181 OP_SETLIST,
00182 OP_SETLISTO,
00183
00184 OP_CLOSE,
00185 OP_CLOSURE
00186 } OpCode;
00187
00188
00189 #define NUM_OPCODES (cast(int, OP_CLOSURE+1))
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210 enum OpModeMask {
00211 OpModeBreg = 2,
00212 OpModeBrk,
00213 OpModeCrk,
00214 OpModesetA,
00215 OpModeK,
00216 OpModeT
00217
00218 };
00219
00220
00221
00222 extern const lu_byte luaP_opmodes[NUM_OPCODES];
00223
00224 #define getOpMode(m) (cast(enum OpMode, luaP_opmodes[m] & 3))
00225 #define testOpMode(m, b) (luaP_opmodes[m] & (1 << (b)))
00226
00227
00228 #ifdef LUA_OPNAMES
00229 extern const char *const luaP_opnames[];
00230 #endif
00231
00232
00233
00234
00235
00236 #define LFIELDS_PER_FLUSH 32
00237
00238
00239 #endif