diff options
| author | chai <chaifix@163.com> | 2020-07-20 09:42:30 +0800 |
|---|---|---|
| committer | chai <chaifix@163.com> | 2020-07-20 09:42:30 +0800 |
| commit | 77ac95b9985f5669d6659bfb54728786d28c2ef0 (patch) | |
| tree | ab42f7da14ffbd9ba72f503baff71b44298b113a /src/lua51/lopcodes.h | |
| parent | c5d9668a1b7092262b7132679e961a5297da2f75 (diff) | |
*misc
Diffstat (limited to 'src/lua51/lopcodes.h')
| -rw-r--r-- | src/lua51/lopcodes.h | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/src/lua51/lopcodes.h b/src/lua51/lopcodes.h index 41224d6..8c0d1a8 100644 --- a/src/lua51/lopcodes.h +++ b/src/lua51/lopcodes.h @@ -34,13 +34,24 @@ enum OpMode {iABC, iABx, iAsBx}; /* basic instruction format */ /* ** size and position of opcode arguments. */ -#define SIZE_C 9 -#define SIZE_B 9 -#define SIZE_Bx (SIZE_C + SIZE_B) -#define SIZE_A 8 +/* +三种指令的格式 +iABC B:9 C:9 A:8 Opcode:6 +iABx Bx:18 A:8 Opcode:6 +iAsBx sBx:18 A:8 Opcode:6 +注:sBx是signed BX +寄存器就是相对于callinfo和lua_state的当前调用的base的某个偏移(即ABC值) +*/ +//c 单个指令Instruction的每部分的大小 +// 9 + 9 + 8 + 6 = 32 bits +#define SIZE_B 9 +#define SIZE_C 9 +#define SIZE_Bx (SIZE_C + SIZE_B) +#define SIZE_A 8 #define SIZE_OP 6 +//c 每个部分在Instruction中的偏移量,从低位到高位 #define POS_OP 0 #define POS_A (POS_OP + SIZE_OP) #define POS_C (POS_A + SIZE_A) @@ -76,7 +87,7 @@ enum OpMode {iABC, iABx, iAsBx}; /* basic instruction format */ /* ** the following macros help to manipulate instructions */ - +//c 获取和设置Instruction中的某个部分 #define GET_OPCODE(i) (cast(OpCode, ((i)>>POS_OP) & MASK1(SIZE_OP,0))) #define SET_OPCODE(i,o) ((i) = (((i)&MASK0(SIZE_OP,POS_OP)) | \ ((cast(Instruction, o)<<POS_OP)&MASK1(SIZE_OP,POS_OP)))) @@ -115,9 +126,11 @@ enum OpMode {iABC, iABx, iAsBx}; /* basic instruction format */ ** Macros to operate RK indices */ +//c 高位为1时代表常数 /* this bit 1 means constant (0 means register) */ #define BITRK (1 << (SIZE_B - 1)) +//c 检查x是不是常量,规定高位是1的话就是常量,去常量表里查,而不是寄存器 /* test whether value is a constant */ #define ISK(x) ((x) & BITRK) @@ -241,12 +254,12 @@ OP_VARARG/* A B R(A), R(A+1), ..., R(A+B-1) = vararg */ ** bit 6: instruction set register A ** bit 7: operator is a test */ - +//c 指令的参数格式 enum OpArgMask { - OpArgN, /* argument is not used */ - OpArgU, /* argument is used */ - OpArgR, /* argument is a register or a jump offset */ - OpArgK /* argument is a constant or register/constant */ + OpArgN, /* argument is not used */ // 未使用(没有座位R()和RK()的参数使用) + OpArgU, /* argument is used */ // 使用的 + OpArgR, /* argument is a register or a jump offset */ // 寄存器、跳转偏移 + OpArgK /* argument is a constant or register/constant */ // 寄存器、常量 }; LUAI_DATA const lu_byte luaP_opmodes[NUM_OPCODES]; |
