diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-12-05 12:59:42 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-12-05 12:59:42 -0300 |
| commit | 490ecfcaa1f25fcc17f9dcb0ed7216da54a391e3 (patch) | |
| tree | 0f6c221c65ddad7b73a223c40cb6cd3e4f324102 | |
| parent | e174f43807d46a7c0a9ab5eeb3fc4434bcb0091f (diff) | |
| download | lua-490ecfcaa1f25fcc17f9dcb0ed7216da54a391e3.tar.gz lua-490ecfcaa1f25fcc17f9dcb0ed7216da54a391e3.tar.bz2 lua-490ecfcaa1f25fcc17f9dcb0ed7216da54a391e3.zip | |
Better comments about the use of 'k' in opcodes
| -rw-r--r-- | lopcodes.h | 42 | ||||
| -rw-r--r-- | lvm.c | 22 |
2 files changed, 34 insertions, 30 deletions
| @@ -217,7 +217,7 @@ OP_SETTABLE,/* A B C R[A][R[B]] := RK(C) */ | |||
| 217 | OP_SETI,/* A B C R[A][B] := RK(C) */ | 217 | OP_SETI,/* A B C R[A][B] := RK(C) */ |
| 218 | OP_SETFIELD,/* A B C R[A][K[B]:string] := RK(C) */ | 218 | OP_SETFIELD,/* A B C R[A][K[B]:string] := RK(C) */ |
| 219 | 219 | ||
| 220 | OP_NEWTABLE,/* A B C R[A] := {} */ | 220 | OP_NEWTABLE,/* A B C k R[A] := {} */ |
| 221 | 221 | ||
| 222 | OP_SELF,/* A B C R[A+1] := R[B]; R[A] := R[B][RK(C):string] */ | 222 | OP_SELF,/* A B C R[A+1] := R[B]; R[A] := R[B][RK(C):string] */ |
| 223 | 223 | ||
| @@ -253,8 +253,8 @@ OP_SHL,/* A B C R[A] := R[B] << R[C] */ | |||
| 253 | OP_SHR,/* A B C R[A] := R[B] >> R[C] */ | 253 | OP_SHR,/* A B C R[A] := R[B] >> R[C] */ |
| 254 | 254 | ||
| 255 | OP_MMBIN,/* A B C call C metamethod over R[A] and R[B] */ | 255 | OP_MMBIN,/* A B C call C metamethod over R[A] and R[B] */ |
| 256 | OP_MMBINI,/* A sB C call C metamethod over R[A] and sB */ | 256 | OP_MMBINI,/* A sB C k call C metamethod over R[A] and sB */ |
| 257 | OP_MMBINK,/* A B C call C metamethod over R[A] and K[B] */ | 257 | OP_MMBINK,/* A B C k call C metamethod over R[A] and K[B] */ |
| 258 | 258 | ||
| 259 | OP_UNM,/* A B R[A] := -R[B] */ | 259 | OP_UNM,/* A B R[A] := -R[B] */ |
| 260 | OP_BNOT,/* A B R[A] := ~R[B] */ | 260 | OP_BNOT,/* A B R[A] := ~R[B] */ |
| @@ -266,24 +266,24 @@ OP_CONCAT,/* A B R[A] := R[A].. ... ..R[A + B - 1] */ | |||
| 266 | OP_CLOSE,/* A close all upvalues >= R[A] */ | 266 | OP_CLOSE,/* A close all upvalues >= R[A] */ |
| 267 | OP_TBC,/* A mark variable A "to be closed" */ | 267 | OP_TBC,/* A mark variable A "to be closed" */ |
| 268 | OP_JMP,/* sJ pc += sJ */ | 268 | OP_JMP,/* sJ pc += sJ */ |
| 269 | OP_EQ,/* A B if ((R[A] == R[B]) ~= k) then pc++ */ | 269 | OP_EQ,/* A B k if ((R[A] == R[B]) ~= k) then pc++ */ |
| 270 | OP_LT,/* A B if ((R[A] < R[B]) ~= k) then pc++ */ | 270 | OP_LT,/* A B k if ((R[A] < R[B]) ~= k) then pc++ */ |
| 271 | OP_LE,/* A B if ((R[A] <= R[B]) ~= k) then pc++ */ | 271 | OP_LE,/* A B k if ((R[A] <= R[B]) ~= k) then pc++ */ |
| 272 | 272 | ||
| 273 | OP_EQK,/* A B if ((R[A] == K[B]) ~= k) then pc++ */ | 273 | OP_EQK,/* A B k if ((R[A] == K[B]) ~= k) then pc++ */ |
| 274 | OP_EQI,/* A sB if ((R[A] == sB) ~= k) then pc++ */ | 274 | OP_EQI,/* A sB k if ((R[A] == sB) ~= k) then pc++ */ |
| 275 | OP_LTI,/* A sB if ((R[A] < sB) ~= k) then pc++ */ | 275 | OP_LTI,/* A sB k if ((R[A] < sB) ~= k) then pc++ */ |
| 276 | OP_LEI,/* A sB if ((R[A] <= sB) ~= k) then pc++ */ | 276 | OP_LEI,/* A sB k if ((R[A] <= sB) ~= k) then pc++ */ |
| 277 | OP_GTI,/* A sB if ((R[A] > sB) ~= k) then pc++ */ | 277 | OP_GTI,/* A sB k if ((R[A] > sB) ~= k) then pc++ */ |
| 278 | OP_GEI,/* A sB if ((R[A] >= sB) ~= k) then pc++ */ | 278 | OP_GEI,/* A sB k if ((R[A] >= sB) ~= k) then pc++ */ |
| 279 | 279 | ||
| 280 | OP_TEST,/* A if (not R[A] == k) then pc++ */ | 280 | OP_TEST,/* A k if (not R[A] == k) then pc++ */ |
| 281 | OP_TESTSET,/* A B if (not R[B] == k) then pc++ else R[A] := R[B] */ | 281 | OP_TESTSET,/* A B k if (not R[B] == k) then pc++ else R[A] := R[B] */ |
| 282 | 282 | ||
| 283 | OP_CALL,/* A B C R[A], ... ,R[A+C-2] := R[A](R[A+1], ... ,R[A+B-1]) */ | 283 | OP_CALL,/* A B C R[A], ... ,R[A+C-2] := R[A](R[A+1], ... ,R[A+B-1]) */ |
| 284 | OP_TAILCALL,/* A B C return R[A](R[A+1], ... ,R[A+B-1]) */ | 284 | OP_TAILCALL,/* A B C k return R[A](R[A+1], ... ,R[A+B-1]) */ |
| 285 | 285 | ||
| 286 | OP_RETURN,/* A B C return R[A], ... ,R[A+B-2] (see note) */ | 286 | OP_RETURN,/* A B C k return R[A], ... ,R[A+B-2] (see note) */ |
| 287 | OP_RETURN0,/* return */ | 287 | OP_RETURN0,/* return */ |
| 288 | OP_RETURN1,/* A return R[A] */ | 288 | OP_RETURN1,/* A return R[A] */ |
| 289 | 289 | ||
| @@ -295,7 +295,7 @@ OP_TFORPREP,/* A Bx create upvalue for R[A + 3]; pc+=Bx */ | |||
| 295 | OP_TFORCALL,/* A C R[A+4], ... ,R[A+3+C] := R[A](R[A+1], R[A+2]); */ | 295 | OP_TFORCALL,/* A C R[A+4], ... ,R[A+3+C] := R[A](R[A+1], R[A+2]); */ |
| 296 | OP_TFORLOOP,/* A Bx if R[A+2] ~= nil then { R[A]=R[A+2]; pc -= Bx } */ | 296 | OP_TFORLOOP,/* A Bx if R[A+2] ~= nil then { R[A]=R[A+2]; pc -= Bx } */ |
| 297 | 297 | ||
| 298 | OP_SETLIST,/* A B C R[A][(C-1)*FPF+i] := R[A+i], 1 <= i <= B */ | 298 | OP_SETLIST,/* A B C k R[A][(C-1)*FPF+i] := R[A+i], 1 <= i <= B */ |
| 299 | 299 | ||
| 300 | OP_CLOSURE,/* A Bx R[A] := closure(KPROTO[Bx]) */ | 300 | OP_CLOSURE,/* A Bx R[A] := closure(KPROTO[Bx]) */ |
| 301 | 301 | ||
| @@ -323,7 +323,7 @@ OP_EXTRAARG/* Ax extra (larger) argument for previous opcode */ | |||
| 323 | (*) In OP_RETURN, if (B == 0) then return up to 'top'. | 323 | (*) In OP_RETURN, if (B == 0) then return up to 'top'. |
| 324 | 324 | ||
| 325 | (*) In OP_LOADKX and OP_NEWTABLE, the next instruction is always | 325 | (*) In OP_LOADKX and OP_NEWTABLE, the next instruction is always |
| 326 | EXTRAARG. | 326 | OP_EXTRAARG. |
| 327 | 327 | ||
| 328 | (*) In OP_SETLIST, if (B == 0) then real B = 'top'; if k, then | 328 | (*) In OP_SETLIST, if (B == 0) then real B = 'top'; if k, then |
| 329 | real C = EXTRAARG _ C (the bits of EXTRAARG concatenated with the | 329 | real C = EXTRAARG _ C (the bits of EXTRAARG concatenated with the |
| @@ -336,6 +336,9 @@ OP_EXTRAARG/* Ax extra (larger) argument for previous opcode */ | |||
| 336 | (*) For comparisons, k specifies what condition the test should accept | 336 | (*) For comparisons, k specifies what condition the test should accept |
| 337 | (true or false). | 337 | (true or false). |
| 338 | 338 | ||
| 339 | (*) In OP_MMBINI/OP_MMBINK, k means the arguments were flipped | ||
| 340 | (the constant is the first operand). | ||
| 341 | |||
| 339 | (*) All 'skips' (pc++) assume that next instruction is a jump. | 342 | (*) All 'skips' (pc++) assume that next instruction is a jump. |
| 340 | 343 | ||
| 341 | (*) In instructions OP_RETURN/OP_TAILCALL, 'k' specifies that the | 344 | (*) In instructions OP_RETURN/OP_TAILCALL, 'k' specifies that the |
| @@ -344,7 +347,8 @@ OP_EXTRAARG/* Ax extra (larger) argument for previous opcode */ | |||
| 344 | returning; in this case, (C - 1) is its number of fixed parameters. | 347 | returning; in this case, (C - 1) is its number of fixed parameters. |
| 345 | 348 | ||
| 346 | (*) In comparisons with an immediate operand, C signals whether the | 349 | (*) In comparisons with an immediate operand, C signals whether the |
| 347 | original operand was a float. | 350 | original operand was a float. (It must be corrected in case of |
| 351 | metamethods.) | ||
| 348 | 352 | ||
| 349 | ===========================================================================*/ | 353 | ===========================================================================*/ |
| 350 | 354 | ||
| @@ -890,9 +890,9 @@ void luaV_finishOp (lua_State *L) { | |||
| 890 | /* | 890 | /* |
| 891 | ** Auxiliary macro for arithmetic operations over floats and others | 891 | ** Auxiliary macro for arithmetic operations over floats and others |
| 892 | ** with immediate operand. 'fop' is the float operation; 'tm' is the | 892 | ** with immediate operand. 'fop' is the float operation; 'tm' is the |
| 893 | ** corresponding metamethod; 'flip' is true if operands were flipped. | 893 | ** corresponding metamethod. |
| 894 | */ | 894 | */ |
| 895 | #define op_arithfI_aux(L,v1,imm,fop,tm,flip) { \ | 895 | #define op_arithfI_aux(L,v1,imm,fop,tm) { \ |
| 896 | lua_Number nb; \ | 896 | lua_Number nb; \ |
| 897 | if (tonumberns(v1, nb)) { \ | 897 | if (tonumberns(v1, nb)) { \ |
| 898 | lua_Number fimm = cast_num(imm); \ | 898 | lua_Number fimm = cast_num(imm); \ |
| @@ -912,14 +912,14 @@ void luaV_finishOp (lua_State *L) { | |||
| 912 | ** Arithmetic operations with immediate operands. 'iop' is the integer | 912 | ** Arithmetic operations with immediate operands. 'iop' is the integer |
| 913 | ** operation. | 913 | ** operation. |
| 914 | */ | 914 | */ |
| 915 | #define op_arithI(L,iop,fop,tm,flip) { \ | 915 | #define op_arithI(L,iop,fop,tm) { \ |
| 916 | TValue *v1 = vRB(i); \ | 916 | TValue *v1 = vRB(i); \ |
| 917 | int imm = GETARG_sC(i); \ | 917 | int imm = GETARG_sC(i); \ |
| 918 | if (ttisinteger(v1)) { \ | 918 | if (ttisinteger(v1)) { \ |
| 919 | lua_Integer iv1 = ivalue(v1); \ | 919 | lua_Integer iv1 = ivalue(v1); \ |
| 920 | pc++; setivalue(s2v(ra), iop(L, iv1, imm)); \ | 920 | pc++; setivalue(s2v(ra), iop(L, iv1, imm)); \ |
| 921 | } \ | 921 | } \ |
| 922 | else op_arithfI_aux(L, v1, imm, fop, tm, flip); } | 922 | else op_arithfI_aux(L, v1, imm, fop, tm); } |
| 923 | 923 | ||
| 924 | 924 | ||
| 925 | /* | 925 | /* |
| @@ -958,7 +958,7 @@ void luaV_finishOp (lua_State *L) { | |||
| 958 | /* | 958 | /* |
| 959 | ** Arithmetic operations with K operands. | 959 | ** Arithmetic operations with K operands. |
| 960 | */ | 960 | */ |
| 961 | #define op_arithK(L,iop,fop,flip) { \ | 961 | #define op_arithK(L,iop,fop) { \ |
| 962 | TValue *v1 = vRB(i); \ | 962 | TValue *v1 = vRB(i); \ |
| 963 | TValue *v2 = KC(i); \ | 963 | TValue *v2 = KC(i); \ |
| 964 | if (ttisinteger(v1) && ttisinteger(v2)) { \ | 964 | if (ttisinteger(v1) && ttisinteger(v2)) { \ |
| @@ -1367,23 +1367,23 @@ void luaV_execute (lua_State *L, CallInfo *ci) { | |||
| 1367 | vmbreak; | 1367 | vmbreak; |
| 1368 | } | 1368 | } |
| 1369 | vmcase(OP_ADDI) { | 1369 | vmcase(OP_ADDI) { |
| 1370 | op_arithI(L, l_addi, luai_numadd, TM_ADD, GETARG_k(i)); | 1370 | op_arithI(L, l_addi, luai_numadd, TM_ADD); |
| 1371 | vmbreak; | 1371 | vmbreak; |
| 1372 | } | 1372 | } |
| 1373 | vmcase(OP_ADDK) { | 1373 | vmcase(OP_ADDK) { |
| 1374 | op_arithK(L, l_addi, luai_numadd, GETARG_k(i)); | 1374 | op_arithK(L, l_addi, luai_numadd); |
| 1375 | vmbreak; | 1375 | vmbreak; |
| 1376 | } | 1376 | } |
| 1377 | vmcase(OP_SUBK) { | 1377 | vmcase(OP_SUBK) { |
| 1378 | op_arithK(L, l_subi, luai_numsub, 0); | 1378 | op_arithK(L, l_subi, luai_numsub); |
| 1379 | vmbreak; | 1379 | vmbreak; |
| 1380 | } | 1380 | } |
| 1381 | vmcase(OP_MULK) { | 1381 | vmcase(OP_MULK) { |
| 1382 | op_arithK(L, l_muli, luai_nummul, GETARG_k(i)); | 1382 | op_arithK(L, l_muli, luai_nummul); |
| 1383 | vmbreak; | 1383 | vmbreak; |
| 1384 | } | 1384 | } |
| 1385 | vmcase(OP_MODK) { | 1385 | vmcase(OP_MODK) { |
| 1386 | op_arithK(L, luaV_mod, luaV_modf, 0); | 1386 | op_arithK(L, luaV_mod, luaV_modf); |
| 1387 | vmbreak; | 1387 | vmbreak; |
| 1388 | } | 1388 | } |
| 1389 | vmcase(OP_POWK) { | 1389 | vmcase(OP_POWK) { |
| @@ -1395,7 +1395,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) { | |||
| 1395 | vmbreak; | 1395 | vmbreak; |
| 1396 | } | 1396 | } |
| 1397 | vmcase(OP_IDIVK) { | 1397 | vmcase(OP_IDIVK) { |
| 1398 | op_arithK(L, luaV_idiv, luai_numidiv, 0); | 1398 | op_arithK(L, luaV_idiv, luai_numidiv); |
| 1399 | vmbreak; | 1399 | vmbreak; |
| 1400 | } | 1400 | } |
| 1401 | vmcase(OP_BANDK) { | 1401 | vmcase(OP_BANDK) { |
