diff options
| author | chai <chaifix@163.com> | 2020-09-27 20:31:53 +0800 |
|---|---|---|
| committer | chai <chaifix@163.com> | 2020-09-27 20:31:53 +0800 |
| commit | 63cb4fbbb961da133c68865845eaf22d9b876700 (patch) | |
| tree | 42be163db598df2cf1c11d329c3e5843db4faa0c /src/lua51/lopcodes.h | |
| parent | 2dfa15a926f06137f2ba6afcce2e3c1d23300100 (diff) | |
*misc
Diffstat (limited to 'src/lua51/lopcodes.h')
| -rw-r--r-- | src/lua51/lopcodes.h | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/lua51/lopcodes.h b/src/lua51/lopcodes.h index 8c0d1a8..f9a9828 100644 --- a/src/lua51/lopcodes.h +++ b/src/lua51/lopcodes.h @@ -27,13 +27,6 @@ unsigned argument. ===========================================================================*/ - -enum OpMode {iABC, iABx, iAsBx}; /* basic instruction format */ - - -/* -** size and position of opcode arguments. -*/ /* 三种指令的格式 iABC B:9 C:9 A:8 Opcode:6 @@ -42,6 +35,12 @@ iAsBx sBx:18 A:8 Opcode:6 注:sBx是signed BX 寄存器就是相对于callinfo和lua_state的当前调用的base的某个偏移(即ABC值) */ +enum OpMode {iABC, iABx, iAsBx}; /* basic instruction format */ + + +/* +** size and position of opcode arguments. +*/ //c 单个指令Instruction的每部分的大小 // 9 + 9 + 8 + 6 = 32 bits @@ -87,7 +86,7 @@ iAsBx sBx:18 A:8 Opcode:6 /* ** the following macros help to manipulate instructions */ -//c 获取和设置Instruction中的某个部分 +//c 获取和设置指令中的某个部分 #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)))) @@ -212,7 +211,9 @@ OP_FORPREP,/* A sBx R(A)-=R(A+2); pc+=sBx */ OP_TFORLOOP,/* A C R(A+3), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2)); if R(A+3) ~= nil then R(A+2)=R(A+3) else pc++ */ -OP_SETLIST,/* A B C R(A)[(C-1)*FPF+i] := R(A+i), 1 <= i <= B */ +OP_SETLIST,/* A B C R(A)[(C-1)*FPF+i] := R(A+i), 1 <= i <= B */ + //setlist有一个优化,当初始化的数量每超过LFIELDS_PER_FLUSH个时,flush一次,这样能够减少 + // 比如初始化时元素个数是3个,那么参数C就是1,只需要flush 1次 OP_CLOSE,/* A close all variables in the stack up to (>=) R(A)*/ OP_CLOSURE,/* A Bx R(A) := closure(KPROTO[Bx], R(A), ... ,R(A+n)) */ @@ -254,7 +255,7 @@ 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 指令的参数格式 +//c 指令的参数格式,在luaP_opmodes用到 enum OpArgMask { OpArgN, /* argument is not used */ // 未使用(没有座位R()和RK()的参数使用) OpArgU, /* argument is used */ // 使用的 @@ -262,6 +263,8 @@ enum OpArgMask { OpArgK /* argument is a constant or register/constant */ // 寄存器、常量 }; +//c 限制每个指令的具体格式,用来后续判断,起到分类统一处理指令的作用 +//c 即lvm.c 中 RA(i)等宏中的check_exp,不过这个检查是可以跳过的,在llimits.h中定义 LUAI_DATA const lu_byte luaP_opmodes[NUM_OPCODES]; #define getOpMode(m) (cast(enum OpMode, luaP_opmodes[m] & 3)) |
