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
00032 enum OpMode {iABC, iABx, iAsBx, iAx};
00033
00034
00035
00036
00037
00038 #define SIZE_C 9
00039 #define SIZE_B 9
00040 #define SIZE_Bx (SIZE_C + SIZE_B)
00041 #define SIZE_A 8
00042 #define SIZE_Ax (SIZE_C + SIZE_B + SIZE_A)
00043
00044 #define SIZE_OP 6
00045
00046 #define POS_OP 0
00047 #define POS_A (POS_OP + SIZE_OP)
00048 #define POS_C (POS_A + SIZE_A)
00049 #define POS_B (POS_C + SIZE_C)
00050 #define POS_Bx POS_C
00051 #define POS_Ax POS_A
00052
00053
00054
00055
00056
00057
00058
00059 #if SIZE_Bx < LUAI_BITSINT-1
00060 #define MAXARG_Bx ((1<<SIZE_Bx)-1)
00061 #define MAXARG_sBx (MAXARG_Bx>>1)
00062 #else
00063 #define MAXARG_Bx MAX_INT
00064 #define MAXARG_sBx MAX_INT
00065 #endif
00066
00067 #if SIZE_Ax < LUAI_BITSINT-1
00068 #define MAXARG_Ax ((1<<SIZE_Ax)-1)
00069 #else
00070 #define MAXARG_Ax MAX_INT
00071 #endif
00072
00073
00074 #define MAXARG_A ((1<<SIZE_A)-1)
00075 #define MAXARG_B ((1<<SIZE_B)-1)
00076 #define MAXARG_C ((1<<SIZE_C)-1)
00077
00078
00079
00080 #define MASK1(n,p) ((~((~(Instruction)0)<<(n)))<<(p))
00081
00082
00083 #define MASK0(n,p) (~MASK1(n,p))
00084
00085
00086
00087
00088
00089 #define GET_OPCODE(i) (cast(OpCode, ((i)>>POS_OP) & MASK1(SIZE_OP,0)))
00090 #define SET_OPCODE(i,o) ((i) = (((i)&MASK0(SIZE_OP,POS_OP)) | \
00091 ((cast(Instruction, o)<<POS_OP)&MASK1(SIZE_OP,POS_OP))))
00092
00093 #define getarg(i,pos,size) (cast(int, ((i)>>pos) & MASK1(size,0)))
00094 #define setarg(i,v,pos,size) ((i) = (((i)&MASK0(size,pos)) | \
00095 ((cast(Instruction, v)<<pos)&MASK1(size,pos))))
00096
00097 #define GETARG_A(i) getarg(i, POS_A, SIZE_A)
00098 #define SETARG_A(i,v) setarg(i, v, POS_A, SIZE_A)
00099
00100 #define GETARG_B(i) getarg(i, POS_B, SIZE_B)
00101 #define SETARG_B(i,v) setarg(i, v, POS_B, SIZE_B)
00102
00103 #define GETARG_C(i) getarg(i, POS_C, SIZE_C)
00104 #define SETARG_C(i,v) setarg(i, v, POS_C, SIZE_C)
00105
00106 #define GETARG_Bx(i) getarg(i, POS_Bx, SIZE_Bx)
00107 #define SETARG_Bx(i,v) setarg(i, v, POS_Bx, SIZE_Bx)
00108
00109 #define GETARG_Ax(i) getarg(i, POS_Ax, SIZE_Ax)
00110 #define SETARG_Ax(i,v) setarg(i, v, POS_Ax, SIZE_Ax)
00111
00112 #define GETARG_sBx(i) (GETARG_Bx(i)-MAXARG_sBx)
00113 #define SETARG_sBx(i,b) SETARG_Bx((i),cast(unsigned int, (b)+MAXARG_sBx))
00114
00115
00116 #define CREATE_ABC(o,a,b,c) ((cast(Instruction, o)<<POS_OP) \
00117 | (cast(Instruction, a)<<POS_A) \
00118 | (cast(Instruction, b)<<POS_B) \
00119 | (cast(Instruction, c)<<POS_C))
00120
00121 #define CREATE_ABx(o,a,bc) ((cast(Instruction, o)<<POS_OP) \
00122 | (cast(Instruction, a)<<POS_A) \
00123 | (cast(Instruction, bc)<<POS_Bx))
00124
00125 #define CREATE_Ax(o,a) ((cast(Instruction, o)<<POS_OP) \
00126 | (cast(Instruction, a)<<POS_Ax))
00127
00128
00129
00130
00131
00132
00133
00134 #define BITRK (1 << (SIZE_B - 1))
00135
00136
00137 #define ISK(x) ((x) & BITRK)
00138
00139
00140 #define INDEXK(r) ((int)(r) & ~BITRK)
00141
00142 #define MAXINDEXRK (BITRK - 1)
00143
00144
00145 #define RKASK(x) ((x) | BITRK)
00146
00147
00148
00149
00150
00151 #define NO_REG MAXARG_A
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165 typedef enum {
00166
00167
00168
00169 OP_MOVE,
00170 OP_LOADK,
00171 OP_LOADKX,
00172 OP_LOADBOOL,
00173 OP_LOADNIL,
00174 OP_GETUPVAL,
00175
00176 OP_GETTABUP,
00177 OP_GETTABLE,
00178
00179 OP_SETTABUP,
00180 OP_SETUPVAL,
00181 OP_SETTABLE,
00182
00183 OP_NEWTABLE,
00184
00185 OP_SELF,
00186
00187 OP_ADD,
00188 OP_SUB,
00189 OP_MUL,
00190 OP_DIV,
00191 OP_MOD,
00192 OP_POW,
00193 OP_UNM,
00194 OP_NOT,
00195 OP_LEN,
00196
00197 OP_CONCAT,
00198
00199 OP_JMP,
00200 OP_EQ,
00201 OP_LT,
00202 OP_LE,
00203
00204 OP_TEST,
00205 OP_TESTSET,
00206
00207 OP_CALL,
00208 OP_TAILCALL,
00209 OP_RETURN,
00210
00211 OP_FORLOOP,
00212
00213 OP_FORPREP,
00214
00215 OP_TFORCALL,
00216 OP_TFORLOOP,
00217
00218 OP_SETLIST,
00219
00220 OP_CLOSURE,
00221
00222 OP_VARARG,
00223
00224 OP_EXTRAARG
00225 } OpCode;
00226
00227
00228 #define NUM_OPCODES (cast(int, OP_EXTRAARG) + 1)
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265 enum OpArgMask {
00266 OpArgN,
00267 OpArgU,
00268 OpArgR,
00269 OpArgK
00270 };
00271
00272 LUAI_DDEC const lu_byte luaP_opmodes[NUM_OPCODES];
00273
00274 #define getOpMode(m) (cast(enum OpMode, luaP_opmodes[m] & 3))
00275 #define getBMode(m) (cast(enum OpArgMask, (luaP_opmodes[m] >> 4) & 3))
00276 #define getCMode(m) (cast(enum OpArgMask, (luaP_opmodes[m] >> 2) & 3))
00277 #define testAMode(m) (luaP_opmodes[m] & (1 << 6))
00278 #define testTMode(m) (luaP_opmodes[m] & (1 << 7))
00279
00280
00281 LUAI_DDEC const char *const luaP_opnames[NUM_OPCODES+1];
00282
00283
00284
00285 #define LFIELDS_PER_FLUSH 50
00286
00287
00288 #endif