From 63cb4fbbb961da133c68865845eaf22d9b876700 Mon Sep 17 00:00:00 2001 From: chai Date: Sun, 27 Sep 2020 20:31:53 +0800 Subject: *misc --- src/lua51/lopcodes.h | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'src/lua51/lopcodes.h') 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)<=) 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)) -- cgit v1.1-26-g67d0