diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-09-28 13:53:29 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-09-28 13:53:29 -0300 |
| commit | 722bdbe17d0192baf72978f88069d12a921e9bfb (patch) | |
| tree | 78da619d4799721e67a760bf4220b568f636cb86 | |
| parent | 1b100335839e13021b4731f0407b87e4f7544dc0 (diff) | |
| download | lua-722bdbe17d0192baf72978f88069d12a921e9bfb.tar.gz lua-722bdbe17d0192baf72978f88069d12a921e9bfb.tar.bz2 lua-722bdbe17d0192baf72978f88069d12a921e9bfb.zip | |
no more 'getBMode'-'getCMode' (imprecise + we will need more space
for op mode) + better control of op modes
| -rw-r--r-- | lcode.c | 18 | ||||
| -rw-r--r-- | lcode.h | 4 | ||||
| -rw-r--r-- | lopcodes.c | 116 | ||||
| -rw-r--r-- | lopcodes.h | 57 | ||||
| -rw-r--r-- | lparser.c | 4 | ||||
| -rw-r--r-- | lvm.c | 19 |
6 files changed, 109 insertions, 109 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lcode.c,v 2.124 2017/09/26 17:10:49 roberto Exp roberto $ | 2 | ** $Id: lcode.c,v 2.125 2017/09/26 18:14:45 roberto Exp roberto $ |
| 3 | ** Code generator for Lua | 3 | ** Code generator for Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -367,8 +367,6 @@ static int luaK_code (FuncState *fs, Instruction i) { | |||
| 367 | */ | 367 | */ |
| 368 | int luaK_codeABC (FuncState *fs, OpCode o, int a, int b, int c) { | 368 | int luaK_codeABC (FuncState *fs, OpCode o, int a, int b, int c) { |
| 369 | lua_assert(getOpMode(o) == iABC); | 369 | lua_assert(getOpMode(o) == iABC); |
| 370 | lua_assert(getBMode(o) != OpArgN || b == 0); | ||
| 371 | lua_assert(getCMode(o) != OpArgN || c == 0); | ||
| 372 | lua_assert(a <= MAXARG_A && b <= MAXARG_B && c <= MAXARG_C); | 370 | lua_assert(a <= MAXARG_A && b <= MAXARG_B && c <= MAXARG_C); |
| 373 | return luaK_code(fs, CREATE_ABC(o, a, b, c)); | 371 | return luaK_code(fs, CREATE_ABC(o, a, b, c)); |
| 374 | } | 372 | } |
| @@ -378,14 +376,24 @@ int luaK_codeABC (FuncState *fs, OpCode o, int a, int b, int c) { | |||
| 378 | ** Format and emit an 'iABx' instruction. | 376 | ** Format and emit an 'iABx' instruction. |
| 379 | */ | 377 | */ |
| 380 | int luaK_codeABx (FuncState *fs, OpCode o, int a, unsigned int bc) { | 378 | int luaK_codeABx (FuncState *fs, OpCode o, int a, unsigned int bc) { |
| 381 | lua_assert(getOpMode(o) == iABx || getOpMode(o) == iAsBx); | 379 | lua_assert(getOpMode(o) == iABx); |
| 382 | lua_assert(getCMode(o) == OpArgN); | ||
| 383 | lua_assert(a <= MAXARG_A && bc <= MAXARG_Bx); | 380 | lua_assert(a <= MAXARG_A && bc <= MAXARG_Bx); |
| 384 | return luaK_code(fs, CREATE_ABx(o, a, bc)); | 381 | return luaK_code(fs, CREATE_ABx(o, a, bc)); |
| 385 | } | 382 | } |
| 386 | 383 | ||
| 387 | 384 | ||
| 388 | /* | 385 | /* |
| 386 | ** Format and emit an 'iAsBx' instruction. | ||
| 387 | */ | ||
| 388 | int luaK_codeAsBx (FuncState *fs, OpCode o, int a, int bc) { | ||
| 389 | unsigned int b = bc + MAXARG_sBx; | ||
| 390 | lua_assert(getOpMode(o) == iAsBx); | ||
| 391 | lua_assert(a <= MAXARG_A && b <= MAXARG_Bx); | ||
| 392 | return luaK_code(fs, CREATE_ABx(o, a, b)); | ||
| 393 | } | ||
| 394 | |||
| 395 | |||
| 396 | /* | ||
| 389 | ** Emit an "extra argument" instruction (format 'iAx') | 397 | ** Emit an "extra argument" instruction (format 'iAx') |
| 390 | */ | 398 | */ |
| 391 | static int codeextraarg (FuncState *fs, int a) { | 399 | static int codeextraarg (FuncState *fs, int a) { |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lcode.h,v 1.65 2017/04/20 19:53:55 roberto Exp roberto $ | 2 | ** $Id: lcode.h,v 1.66 2017/09/13 19:50:08 roberto Exp roberto $ |
| 3 | ** Code generator for Lua | 3 | ** Code generator for Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -43,13 +43,13 @@ typedef enum UnOpr { OPR_MINUS, OPR_BNOT, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr; | |||
| 43 | /* get (pointer to) instruction of given 'expdesc' */ | 43 | /* get (pointer to) instruction of given 'expdesc' */ |
| 44 | #define getinstruction(fs,e) ((fs)->f->code[(e)->u.info]) | 44 | #define getinstruction(fs,e) ((fs)->f->code[(e)->u.info]) |
| 45 | 45 | ||
| 46 | #define luaK_codeAsBx(fs,o,A,sBx) luaK_codeABx(fs,o,A,(sBx)+MAXARG_sBx) | ||
| 47 | 46 | ||
| 48 | #define luaK_setmultret(fs,e) luaK_setreturns(fs, e, LUA_MULTRET) | 47 | #define luaK_setmultret(fs,e) luaK_setreturns(fs, e, LUA_MULTRET) |
| 49 | 48 | ||
| 50 | #define luaK_jumpto(fs,t) luaK_patchlist(fs, luaK_jump(fs), t) | 49 | #define luaK_jumpto(fs,t) luaK_patchlist(fs, luaK_jump(fs), t) |
| 51 | 50 | ||
| 52 | LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx); | 51 | LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx); |
| 52 | LUAI_FUNC int luaK_codeAsBx (FuncState *fs, OpCode o, int A, int Bx); | ||
| 53 | LUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C); | 53 | LUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C); |
| 54 | LUAI_FUNC void luaK_fixline (FuncState *fs, int line); | 54 | LUAI_FUNC void luaK_fixline (FuncState *fs, int line); |
| 55 | LUAI_FUNC void luaK_nil (FuncState *fs, int from, int n); | 55 | LUAI_FUNC void luaK_nil (FuncState *fs, int from, int n); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lopcodes.c,v 1.63 2017/09/19 18:38:14 roberto Exp roberto $ | 2 | ** $Id: lopcodes.c,v 1.64 2017/09/26 18:14:45 roberto Exp roberto $ |
| 3 | ** Opcodes for Lua virtual machine | 3 | ** Opcodes for Lua virtual machine |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -77,64 +77,62 @@ LUAI_DDEF const char *const luaP_opnames[NUM_OPCODES+1] = { | |||
| 77 | }; | 77 | }; |
| 78 | 78 | ||
| 79 | 79 | ||
| 80 | #define opmode(t,a,b,c,m) (((t)<<7) | ((a)<<6) | ((b)<<4) | ((c)<<2) | (m)) | ||
| 81 | |||
| 82 | LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = { | 80 | LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = { |
| 83 | /* T A B C mode opcode */ | 81 | /* T A mode opcode */ |
| 84 | opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_MOVE */ | 82 | opmode(0, 1, iABC) /* OP_MOVE */ |
| 85 | ,opmode(0, 1, OpArgU, OpArgN, iAsBx) /* OP_LOADI */ | 83 | ,opmode(0, 1, iAsBx) /* OP_LOADI */ |
| 86 | ,opmode(0, 1, OpArgU, OpArgN, iAsBx) /* OP_LOADF */ | 84 | ,opmode(0, 1, iAsBx) /* OP_LOADF */ |
| 87 | ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_LOADK */ | 85 | ,opmode(0, 1, iABx) /* OP_LOADK */ |
| 88 | ,opmode(0, 1, OpArgN, OpArgN, iABx) /* OP_LOADKX */ | 86 | ,opmode(0, 1, iABx) /* OP_LOADKX */ |
| 89 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_LOADBOOL */ | 87 | ,opmode(0, 1, iABC) /* OP_LOADBOOL */ |
| 90 | ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_LOADNIL */ | 88 | ,opmode(0, 1, iABC) /* OP_LOADNIL */ |
| 91 | ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_GETUPVAL */ | 89 | ,opmode(0, 1, iABC) /* OP_GETUPVAL */ |
| 92 | ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_SETUPVAL */ | 90 | ,opmode(0, 0, iABC) /* OP_SETUPVAL */ |
| 93 | ,opmode(0, 1, OpArgU, OpArgK, iABC) /* OP_GETTABUP */ | 91 | ,opmode(0, 1, iABC) /* OP_GETTABUP */ |
| 94 | ,opmode(0, 1, OpArgR, OpArgR, iABC) /* OP_GETTABLE */ | 92 | ,opmode(0, 1, iABC) /* OP_GETTABLE */ |
| 95 | ,opmode(0, 1, OpArgR, OpArgU, iABC) /* OP_GETI */ | 93 | ,opmode(0, 1, iABC) /* OP_GETI */ |
| 96 | ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_GETFIELD */ | 94 | ,opmode(0, 1, iABC) /* OP_GETFIELD */ |
| 97 | ,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_SETTABUP */ | 95 | ,opmode(0, 0, iABC) /* OP_SETTABUP */ |
| 98 | ,opmode(0, 0, OpArgR, OpArgK, iABC) /* OP_SETTABLE */ | 96 | ,opmode(0, 0, iABC) /* OP_SETTABLE */ |
| 99 | ,opmode(0, 0, OpArgU, OpArgK, iABC) /* OP_SETI */ | 97 | ,opmode(0, 0, iABC) /* OP_SETI */ |
| 100 | ,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_SETFIELD */ | 98 | ,opmode(0, 0, iABC) /* OP_SETFIELD */ |
| 101 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_NEWTABLE */ | 99 | ,opmode(0, 1, iABC) /* OP_NEWTABLE */ |
| 102 | ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_SELF */ | 100 | ,opmode(0, 1, iABC) /* OP_SELF */ |
| 103 | ,opmode(0, 1, OpArgR, OpArgU, iABC) /* OP_ADDI */ | 101 | ,opmode(0, 1, iABC) /* OP_ADDI */ |
| 104 | ,opmode(0, 1, OpArgR, OpArgR, iABC) /* OP_ADD */ | 102 | ,opmode(0, 1, iABC) /* OP_ADD */ |
| 105 | ,opmode(0, 1, OpArgR, OpArgR, iABC) /* OP_SUB */ | 103 | ,opmode(0, 1, iABC) /* OP_SUB */ |
| 106 | ,opmode(0, 1, OpArgR, OpArgR, iABC) /* OP_MUL */ | 104 | ,opmode(0, 1, iABC) /* OP_MUL */ |
| 107 | ,opmode(0, 1, OpArgR, OpArgR, iABC) /* OP_MOD */ | 105 | ,opmode(0, 1, iABC) /* OP_MOD */ |
| 108 | ,opmode(0, 1, OpArgR, OpArgR, iABC) /* OP_POW */ | 106 | ,opmode(0, 1, iABC) /* OP_POW */ |
| 109 | ,opmode(0, 1, OpArgR, OpArgR, iABC) /* OP_DIV */ | 107 | ,opmode(0, 1, iABC) /* OP_DIV */ |
| 110 | ,opmode(0, 1, OpArgR, OpArgR, iABC) /* OP_IDIV */ | 108 | ,opmode(0, 1, iABC) /* OP_IDIV */ |
| 111 | ,opmode(0, 1, OpArgR, OpArgR, iABC) /* OP_BAND */ | 109 | ,opmode(0, 1, iABC) /* OP_BAND */ |
| 112 | ,opmode(0, 1, OpArgR, OpArgR, iABC) /* OP_BOR */ | 110 | ,opmode(0, 1, iABC) /* OP_BOR */ |
| 113 | ,opmode(0, 1, OpArgR, OpArgR, iABC) /* OP_BXOR */ | 111 | ,opmode(0, 1, iABC) /* OP_BXOR */ |
| 114 | ,opmode(0, 1, OpArgR, OpArgR, iABC) /* OP_SHL */ | 112 | ,opmode(0, 1, iABC) /* OP_SHL */ |
| 115 | ,opmode(0, 1, OpArgR, OpArgR, iABC) /* OP_SHR */ | 113 | ,opmode(0, 1, iABC) /* OP_SHR */ |
| 116 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_UNM */ | 114 | ,opmode(0, 1, iABC) /* OP_UNM */ |
| 117 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_BNOT */ | 115 | ,opmode(0, 1, iABC) /* OP_BNOT */ |
| 118 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_NOT */ | 116 | ,opmode(0, 1, iABC) /* OP_NOT */ |
| 119 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_LEN */ | 117 | ,opmode(0, 1, iABC) /* OP_LEN */ |
| 120 | ,opmode(0, 1, OpArgR, OpArgR, iABC) /* OP_CONCAT */ | 118 | ,opmode(0, 1, iABC) /* OP_CONCAT */ |
| 121 | ,opmode(0, 0, OpArgN, OpArgN, iABC) /* OP_CLOSE */ | 119 | ,opmode(0, 0, iABC) /* OP_CLOSE */ |
| 122 | ,opmode(0, 0, OpArgU, OpArgN, iAsBx) /* OP_JMP */ | 120 | ,opmode(0, 0, iAsBx) /* OP_JMP */ |
| 123 | ,opmode(1, 0, OpArgR, OpArgR, iABC) /* OP_EQ */ | 121 | ,opmode(1, 0, iABC) /* OP_EQ */ |
| 124 | ,opmode(1, 0, OpArgR, OpArgR, iABC) /* OP_LT */ | 122 | ,opmode(1, 0, iABC) /* OP_LT */ |
| 125 | ,opmode(1, 0, OpArgR, OpArgR, iABC) /* OP_LE */ | 123 | ,opmode(1, 0, iABC) /* OP_LE */ |
| 126 | ,opmode(1, 0, OpArgN, OpArgU, iABC) /* OP_TEST */ | 124 | ,opmode(1, 0, iABC) /* OP_TEST */ |
| 127 | ,opmode(1, 1, OpArgR, OpArgU, iABC) /* OP_TESTSET */ | 125 | ,opmode(1, 1, iABC) /* OP_TESTSET */ |
| 128 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_CALL */ | 126 | ,opmode(0, 1, iABC) /* OP_CALL */ |
| 129 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_TAILCALL */ | 127 | ,opmode(0, 1, iABC) /* OP_TAILCALL */ |
| 130 | ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_RETURN */ | 128 | ,opmode(0, 0, iABC) /* OP_RETURN */ |
| 131 | ,opmode(0, 1, OpArgR, OpArgN, iABx) /* OP_FORLOOP */ | 129 | ,opmode(0, 1, iABx) /* OP_FORLOOP */ |
| 132 | ,opmode(0, 1, OpArgR, OpArgN, iABx) /* OP_FORPREP */ | 130 | ,opmode(0, 1, iABx) /* OP_FORPREP */ |
| 133 | ,opmode(0, 0, OpArgN, OpArgU, iABC) /* OP_TFORCALL */ | 131 | ,opmode(0, 0, iABC) /* OP_TFORCALL */ |
| 134 | ,opmode(0, 1, OpArgR, OpArgN, iABx) /* OP_TFORLOOP */ | 132 | ,opmode(0, 1, iABx) /* OP_TFORLOOP */ |
| 135 | ,opmode(0, 0, OpArgU, OpArgU, iABC) /* OP_SETLIST */ | 133 | ,opmode(0, 0, iABC) /* OP_SETLIST */ |
| 136 | ,opmode(0, 1, OpArgU, OpArgN, iABx) /* OP_CLOSURE */ | 134 | ,opmode(0, 1, iABx) /* OP_CLOSURE */ |
| 137 | ,opmode(0, 1, OpArgU, OpArgR, iABC) /* OP_VARARG */ | 135 | ,opmode(0, 1, iABC) /* OP_VARARG */ |
| 138 | ,opmode(0, 0, OpArgU, OpArgU, iAx) /* OP_EXTRAARG */ | 136 | ,opmode(0, 0, iAx) /* OP_EXTRAARG */ |
| 139 | }; | 137 | }; |
| 140 | 138 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lopcodes.h,v 1.160 2017/09/19 18:38:14 roberto Exp roberto $ | 2 | ** $Id: lopcodes.h,v 1.161 2017/09/26 18:14:45 roberto Exp roberto $ |
| 3 | ** Opcodes for Lua virtual machine | 3 | ** Opcodes for Lua virtual machine |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -89,6 +89,9 @@ enum OpMode {iABC, iABx, iAsBx, iAx}; /* basic instruction format */ | |||
| 89 | #define SET_OPCODE(i,o) ((i) = (((i)&MASK0(SIZE_OP,POS_OP)) | \ | 89 | #define SET_OPCODE(i,o) ((i) = (((i)&MASK0(SIZE_OP,POS_OP)) | \ |
| 90 | ((cast(Instruction, o)<<POS_OP)&MASK1(SIZE_OP,POS_OP)))) | 90 | ((cast(Instruction, o)<<POS_OP)&MASK1(SIZE_OP,POS_OP)))) |
| 91 | 91 | ||
| 92 | #define checkopm(i,m) (getOpMode(GET_OPCODE(i)) == m) | ||
| 93 | |||
| 94 | |||
| 92 | #define getarg(i,pos,size) (cast(int, ((i)>>(pos)) & MASK1(size,0))) | 95 | #define getarg(i,pos,size) (cast(int, ((i)>>(pos)) & MASK1(size,0))) |
| 93 | #define setarg(i,v,pos,size) ((i) = (((i)&MASK0(size,pos)) | \ | 96 | #define setarg(i,v,pos,size) ((i) = (((i)&MASK0(size,pos)) | \ |
| 94 | ((cast(Instruction, v)<<pos)&MASK1(size,pos)))) | 97 | ((cast(Instruction, v)<<pos)&MASK1(size,pos)))) |
| @@ -96,25 +99,28 @@ enum OpMode {iABC, iABx, iAsBx, iAx}; /* basic instruction format */ | |||
| 96 | #define GETARG_A(i) getarg(i, POS_A, SIZE_A) | 99 | #define GETARG_A(i) getarg(i, POS_A, SIZE_A) |
| 97 | #define SETARG_A(i,v) setarg(i, v, POS_A, SIZE_A) | 100 | #define SETARG_A(i,v) setarg(i, v, POS_A, SIZE_A) |
| 98 | 101 | ||
| 99 | #define GETARG_B(i) getarg(i, POS_B, SIZE_B) | 102 | #define GETARG_B(i) check_exp(checkopm(i, iABC), getarg(i, POS_B, SIZE_B)) |
| 100 | #define SETARG_B(i,v) setarg(i, v, POS_B, SIZE_B) | 103 | #define SETARG_B(i,v) setarg(i, v, POS_B, SIZE_B) |
| 101 | 104 | ||
| 102 | #define GETARG_Br(i) getarg(i, POS_B, SIZE_B - 1) | 105 | #define GETARG_Br(i) \ |
| 106 | check_exp(checkopm(i, iABC), getarg(i, POS_B, SIZE_B - 1)) | ||
| 103 | #define GETARG_Bk(i) getarg(i, (POS_B + SIZE_B - 1), 1) | 107 | #define GETARG_Bk(i) getarg(i, (POS_B + SIZE_B - 1), 1) |
| 104 | 108 | ||
| 105 | #define GETARG_C(i) getarg(i, POS_C, SIZE_C) | 109 | #define GETARG_C(i) check_exp(checkopm(i, iABC), getarg(i, POS_C, SIZE_C)) |
| 106 | #define SETARG_C(i,v) setarg(i, v, POS_C, SIZE_C) | 110 | #define SETARG_C(i,v) setarg(i, v, POS_C, SIZE_C) |
| 107 | 111 | ||
| 108 | #define GETARG_Cr(i) getarg(i, POS_C, SIZE_C - 1) | 112 | #define GETARG_Cr(i) \ |
| 113 | check_exp(checkopm(i, iABC), getarg(i, POS_C, SIZE_C - 1)) | ||
| 109 | #define GETARG_Ck(i) getarg(i, (POS_C + SIZE_C - 1), 1) | 114 | #define GETARG_Ck(i) getarg(i, (POS_C + SIZE_C - 1), 1) |
| 110 | 115 | ||
| 111 | #define GETARG_Bx(i) getarg(i, POS_Bx, SIZE_Bx) | 116 | #define GETARG_Bx(i) check_exp(checkopm(i, iABx), getarg(i, POS_Bx, SIZE_Bx)) |
| 112 | #define SETARG_Bx(i,v) setarg(i, v, POS_Bx, SIZE_Bx) | 117 | #define SETARG_Bx(i,v) setarg(i, v, POS_Bx, SIZE_Bx) |
| 113 | 118 | ||
| 114 | #define GETARG_Ax(i) getarg(i, POS_Ax, SIZE_Ax) | 119 | #define GETARG_Ax(i) check_exp(checkopm(i, iAx), getarg(i, POS_Ax, SIZE_Ax)) |
| 115 | #define SETARG_Ax(i,v) setarg(i, v, POS_Ax, SIZE_Ax) | 120 | #define SETARG_Ax(i,v) setarg(i, v, POS_Ax, SIZE_Ax) |
| 116 | 121 | ||
| 117 | #define GETARG_sBx(i) (GETARG_Bx(i)-MAXARG_sBx) | 122 | #define GETARG_sBx(i) \ |
| 123 | check_exp(checkopm(i, iAsBx), getarg(i, POS_Bx, SIZE_Bx) - MAXARG_sBx) | ||
| 118 | #define SETARG_sBx(i,b) SETARG_Bx((i),cast(unsigned int, (b)+MAXARG_sBx)) | 124 | #define SETARG_sBx(i,b) SETARG_Bx((i),cast(unsigned int, (b)+MAXARG_sBx)) |
| 119 | 125 | ||
| 120 | 126 | ||
| @@ -160,8 +166,8 @@ enum OpMode {iABC, iABx, iAsBx, iAx}; /* basic instruction format */ | |||
| 160 | 166 | ||
| 161 | /* | 167 | /* |
| 162 | ** R(x) - register | 168 | ** R(x) - register |
| 163 | ** Kst(x) - constant (in constant table) | 169 | ** K(x) - constant (in constant table) |
| 164 | ** RK(x) == if ISK(x) then Kst(INDEXK(x)) else R(x) | 170 | ** RK(x) == if ISK(x) then K(INDEXK(x)) else R(x) |
| 165 | */ | 171 | */ |
| 166 | 172 | ||
| 167 | 173 | ||
| @@ -176,8 +182,8 @@ name args description | |||
| 176 | OP_MOVE,/* A B R(A) := R(B) */ | 182 | OP_MOVE,/* A B R(A) := R(B) */ |
| 177 | OP_LOADI,/* A sBx R(A) := sBx */ | 183 | OP_LOADI,/* A sBx R(A) := sBx */ |
| 178 | OP_LOADF,/* A sBx R(A) := (lua_Number)sBx */ | 184 | OP_LOADF,/* A sBx R(A) := (lua_Number)sBx */ |
| 179 | OP_LOADK,/* A Bx R(A) := Kst(Bx) */ | 185 | OP_LOADK,/* A Bx R(A) := K(Bx) */ |
| 180 | OP_LOADKX,/* A R(A) := Kst(extra arg) */ | 186 | OP_LOADKX,/* A R(A) := K(extra arg) */ |
| 181 | OP_LOADBOOL,/* A B C R(A) := (Bool)B; if (C) pc++ */ | 187 | OP_LOADBOOL,/* A B C R(A) := (Bool)B; if (C) pc++ */ |
| 182 | OP_LOADNIL,/* A B R(A), R(A+1), ..., R(A+B) := nil */ | 188 | OP_LOADNIL,/* A B R(A), R(A+1), ..., R(A+B) := nil */ |
| 183 | OP_GETUPVAL,/* A B R(A) := UpValue[B] */ | 189 | OP_GETUPVAL,/* A B R(A) := UpValue[B] */ |
| @@ -186,7 +192,7 @@ OP_SETUPVAL,/* A B UpValue[B] := R(A) */ | |||
| 186 | OP_GETTABUP,/* A B C R(A) := UpValue[B][K(C):string] */ | 192 | OP_GETTABUP,/* A B C R(A) := UpValue[B][K(C):string] */ |
| 187 | OP_GETTABLE,/* A B C R(A) := R(B)[R(C)] */ | 193 | OP_GETTABLE,/* A B C R(A) := R(B)[R(C)] */ |
| 188 | OP_GETI,/* A B C R(A) := R(B)[C] */ | 194 | OP_GETI,/* A B C R(A) := R(B)[C] */ |
| 189 | OP_GETFIELD,/* A B C R(A) := R(B)[Kst(C):string] */ | 195 | OP_GETFIELD,/* A B C R(A) := R(B)[K(C):string] */ |
| 190 | 196 | ||
| 191 | OP_SETTABUP,/* A B C UpValue[A][K(B):string] := RK(C) */ | 197 | OP_SETTABUP,/* A B C UpValue[A][K(B):string] := RK(C) */ |
| 192 | OP_SETTABLE,/* A B C R(A)[R(B)] := RK(C) */ | 198 | OP_SETTABLE,/* A B C R(A)[R(B)] := RK(C) */ |
| @@ -277,27 +283,18 @@ OP_EXTRAARG/* Ax extra (larger) argument for previous opcode */ | |||
| 277 | 283 | ||
| 278 | /* | 284 | /* |
| 279 | ** masks for instruction properties. The format is: | 285 | ** masks for instruction properties. The format is: |
| 280 | ** bits 0-1: op mode | 286 | ** bits 0-2: op mode |
| 281 | ** bits 2-3: C arg mode | 287 | ** bit 3: instruction set register A |
| 282 | ** bits 4-5: B arg mode | 288 | ** bit 4: operator is a test (next instruction must be a jump) |
| 283 | ** bit 6: instruction set register A | ||
| 284 | ** bit 7: operator is a test (next instruction must be a jump) | ||
| 285 | */ | 289 | */ |
| 286 | 290 | ||
| 287 | enum OpArgMask { | ||
| 288 | OpArgN, /* argument is not used */ | ||
| 289 | OpArgU, /* argument is used */ | ||
| 290 | OpArgR, /* argument is a register or a jump offset */ | ||
| 291 | OpArgK /* argument is a constant or register/constant */ | ||
| 292 | }; | ||
| 293 | |||
| 294 | LUAI_DDEC const lu_byte luaP_opmodes[NUM_OPCODES]; | 291 | LUAI_DDEC const lu_byte luaP_opmodes[NUM_OPCODES]; |
| 295 | 292 | ||
| 296 | #define getOpMode(m) (cast(enum OpMode, luaP_opmodes[m] & 3)) | 293 | #define getOpMode(m) (cast(enum OpMode, luaP_opmodes[m] & 7)) |
| 297 | #define getBMode(m) (cast(enum OpArgMask, (luaP_opmodes[m] >> 4) & 3)) | 294 | #define testAMode(m) (luaP_opmodes[m] & (1 << 3)) |
| 298 | #define getCMode(m) (cast(enum OpArgMask, (luaP_opmodes[m] >> 2) & 3)) | 295 | #define testTMode(m) (luaP_opmodes[m] & (1 << 4)) |
| 299 | #define testAMode(m) (luaP_opmodes[m] & (1 << 6)) | 296 | |
| 300 | #define testTMode(m) (luaP_opmodes[m] & (1 << 7)) | 297 | #define opmode(t,a,m) (((t)<<4) | ((a)<<3) | (m)) |
| 301 | 298 | ||
| 302 | 299 | ||
| 303 | LUAI_DDEC const char *const luaP_opnames[NUM_OPCODES+1]; /* opcode names */ | 300 | LUAI_DDEC const char *const luaP_opnames[NUM_OPCODES+1]; /* opcode names */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lparser.c,v 2.164 2017/08/14 18:33:14 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 2.165 2017/09/13 19:50:08 roberto Exp roberto $ |
| 3 | ** Lua Parser | 3 | ** Lua Parser |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -1373,7 +1373,7 @@ static void forbody (LexState *ls, int base, int line, int nvars, int isnum) { | |||
| 1373 | luaK_patchtohere(fs, prep); | 1373 | luaK_patchtohere(fs, prep); |
| 1374 | luaK_codeABC(fs, OP_TFORCALL, base, 0, nvars); | 1374 | luaK_codeABC(fs, OP_TFORCALL, base, 0, nvars); |
| 1375 | luaK_fixline(fs, line); | 1375 | luaK_fixline(fs, line); |
| 1376 | endfor = luaK_codeAsBx(fs, OP_TFORLOOP, base + 2, NO_JUMP); | 1376 | endfor = luaK_codeABx(fs, OP_TFORLOOP, base + 2, 0); |
| 1377 | } | 1377 | } |
| 1378 | fixforjump(fs, endfor, prep + 1, 1); | 1378 | fixforjump(fs, endfor, prep + 1, 1); |
| 1379 | luaK_fixline(fs, line); | 1379 | luaK_fixline(fs, line); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lvm.c,v 2.294 2017/09/26 18:14:45 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.295 2017/09/27 18:59:08 roberto Exp roberto $ |
| 3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -733,14 +733,13 @@ void luaV_finishOp (lua_State *L) { | |||
| 733 | 733 | ||
| 734 | 734 | ||
| 735 | #define RA(i) (base+GETARG_A(i)) | 735 | #define RA(i) (base+GETARG_A(i)) |
| 736 | #define RB(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgR, base+GETARG_Br(i)) | 736 | #define RB(i) (base+GETARG_Br(i)) |
| 737 | #define vRB(i) s2v(RB(i)) | 737 | #define vRB(i) s2v(RB(i)) |
| 738 | #define KB(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgK, k+GETARG_B(i)) | 738 | #define KB(i) (k+GETARG_B(i)) |
| 739 | #define RC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgR, base+GETARG_C(i)) | 739 | #define RC(i) (base+GETARG_C(i)) |
| 740 | #define vRC(i) s2v(RC(i)) | 740 | #define vRC(i) s2v(RC(i)) |
| 741 | #define KC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgK, k+GETARG_C(i)) | 741 | #define KC(i) (k+GETARG_C(i)) |
| 742 | #define RKC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgK, \ | 742 | #define RKC(i) ((GETARG_Ck(i)) ? k + GETARG_Cr(i) : s2v(base + GETARG_Cr(i))) |
| 743 | (GETARG_Ck(i)) ? k + GETARG_Cr(i) : s2v(base + GETARG_Cr(i))) | ||
| 744 | 743 | ||
| 745 | 744 | ||
| 746 | 745 | ||
| @@ -834,8 +833,7 @@ void luaV_execute (lua_State *L) { | |||
| 834 | } | 833 | } |
| 835 | vmcase(OP_LOADKX) { | 834 | vmcase(OP_LOADKX) { |
| 836 | TValue *rb; | 835 | TValue *rb; |
| 837 | lua_assert(GET_OPCODE(*pc) == OP_EXTRAARG); | 836 | rb = k + GETARG_Ax(*pc); pc++; |
| 838 | rb = k + GETARG_Ax(*pc++); | ||
| 839 | setobj2s(L, ra, rb); | 837 | setobj2s(L, ra, rb); |
| 840 | vmbreak; | 838 | vmbreak; |
| 841 | } | 839 | } |
| @@ -1409,8 +1407,7 @@ void luaV_execute (lua_State *L) { | |||
| 1409 | Table *h; | 1407 | Table *h; |
| 1410 | if (n == 0) n = cast_int(L->top - ra) - 1; | 1408 | if (n == 0) n = cast_int(L->top - ra) - 1; |
| 1411 | if (c == 0) { | 1409 | if (c == 0) { |
| 1412 | lua_assert(GET_OPCODE(*pc) == OP_EXTRAARG); | 1410 | c = GETARG_Ax(*pc); pc++; |
| 1413 | c = GETARG_Ax(*pc++); | ||
| 1414 | } | 1411 | } |
| 1415 | h = hvalue(s2v(ra)); | 1412 | h = hvalue(s2v(ra)); |
| 1416 | last = ((c-1)*LFIELDS_PER_FLUSH) + n; | 1413 | last = ((c-1)*LFIELDS_PER_FLUSH) + n; |
