diff options
Diffstat (limited to 'lcode.c')
| -rw-r--r-- | lcode.c | 59 |
1 files changed, 34 insertions, 25 deletions
| @@ -390,32 +390,40 @@ int luaK_code (FuncState *fs, Instruction i) { | |||
| 390 | ** Format and emit an 'iABC' instruction. (Assertions check consistency | 390 | ** Format and emit an 'iABC' instruction. (Assertions check consistency |
| 391 | ** of parameters versus opcode.) | 391 | ** of parameters versus opcode.) |
| 392 | */ | 392 | */ |
| 393 | int luaK_codeABCk (FuncState *fs, OpCode o, int a, int b, int c, int k) { | 393 | int luaK_codeABCk (FuncState *fs, OpCode o, int A, int B, int C, int k) { |
| 394 | lua_assert(getOpMode(o) == iABC); | 394 | lua_assert(getOpMode(o) == iABC); |
| 395 | lua_assert(a <= MAXARG_A && b <= MAXARG_B && | 395 | lua_assert(A <= MAXARG_A && B <= MAXARG_B && |
| 396 | c <= MAXARG_C && (k & ~1) == 0); | 396 | C <= MAXARG_C && (k & ~1) == 0); |
| 397 | return luaK_code(fs, CREATE_ABCk(o, a, b, c, k)); | 397 | return luaK_code(fs, CREATE_ABCk(o, A, B, C, k)); |
| 398 | } | ||
| 399 | |||
| 400 | |||
| 401 | int luaK_codevABCk (FuncState *fs, OpCode o, int A, int B, int C, int k) { | ||
| 402 | lua_assert(getOpMode(o) == ivABC); | ||
| 403 | lua_assert(A <= MAXARG_A && B <= MAXARG_vB && | ||
| 404 | C <= MAXARG_vC && (k & ~1) == 0); | ||
| 405 | return luaK_code(fs, CREATE_vABCk(o, A, B, C, k)); | ||
| 398 | } | 406 | } |
| 399 | 407 | ||
| 400 | 408 | ||
| 401 | /* | 409 | /* |
| 402 | ** Format and emit an 'iABx' instruction. | 410 | ** Format and emit an 'iABx' instruction. |
| 403 | */ | 411 | */ |
| 404 | int luaK_codeABx (FuncState *fs, OpCode o, int a, unsigned int bc) { | 412 | int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bc) { |
| 405 | lua_assert(getOpMode(o) == iABx); | 413 | lua_assert(getOpMode(o) == iABx); |
| 406 | lua_assert(a <= MAXARG_A && bc <= MAXARG_Bx); | 414 | lua_assert(A <= MAXARG_A && Bc <= MAXARG_Bx); |
| 407 | return luaK_code(fs, CREATE_ABx(o, a, bc)); | 415 | return luaK_code(fs, CREATE_ABx(o, A, Bc)); |
| 408 | } | 416 | } |
| 409 | 417 | ||
| 410 | 418 | ||
| 411 | /* | 419 | /* |
| 412 | ** Format and emit an 'iAsBx' instruction. | 420 | ** Format and emit an 'iAsBx' instruction. |
| 413 | */ | 421 | */ |
| 414 | static int codeAsBx (FuncState *fs, OpCode o, int a, int bc) { | 422 | static int codeAsBx (FuncState *fs, OpCode o, int A, int Bc) { |
| 415 | unsigned int b = bc + OFFSET_sBx; | 423 | unsigned int b = cast_uint(Bc) + OFFSET_sBx; |
| 416 | lua_assert(getOpMode(o) == iAsBx); | 424 | lua_assert(getOpMode(o) == iAsBx); |
| 417 | lua_assert(a <= MAXARG_A && b <= MAXARG_Bx); | 425 | lua_assert(A <= MAXARG_A && b <= MAXARG_Bx); |
| 418 | return luaK_code(fs, CREATE_ABx(o, a, b)); | 426 | return luaK_code(fs, CREATE_ABx(o, A, b)); |
| 419 | } | 427 | } |
| 420 | 428 | ||
| 421 | 429 | ||
| @@ -423,7 +431,7 @@ static int codeAsBx (FuncState *fs, OpCode o, int a, int bc) { | |||
| 423 | ** Format and emit an 'isJ' instruction. | 431 | ** Format and emit an 'isJ' instruction. |
| 424 | */ | 432 | */ |
| 425 | static int codesJ (FuncState *fs, OpCode o, int sj, int k) { | 433 | static int codesJ (FuncState *fs, OpCode o, int sj, int k) { |
| 426 | unsigned int j = sj + OFFSET_sJ; | 434 | unsigned int j = cast_uint(sj) + OFFSET_sJ; |
| 427 | lua_assert(getOpMode(o) == isJ); | 435 | lua_assert(getOpMode(o) == isJ); |
| 428 | lua_assert(j <= MAXARG_sJ && (k & ~1) == 0); | 436 | lua_assert(j <= MAXARG_sJ && (k & ~1) == 0); |
| 429 | return luaK_code(fs, CREATE_sJ(o, j, k)); | 437 | return luaK_code(fs, CREATE_sJ(o, j, k)); |
| @@ -433,9 +441,9 @@ static int codesJ (FuncState *fs, OpCode o, int sj, int k) { | |||
| 433 | /* | 441 | /* |
| 434 | ** Emit an "extra argument" instruction (format 'iAx') | 442 | ** Emit an "extra argument" instruction (format 'iAx') |
| 435 | */ | 443 | */ |
| 436 | static int codeextraarg (FuncState *fs, int a) { | 444 | static int codeextraarg (FuncState *fs, int A) { |
| 437 | lua_assert(a <= MAXARG_Ax); | 445 | lua_assert(A <= MAXARG_Ax); |
| 438 | return luaK_code(fs, CREATE_Ax(OP_EXTRAARG, a)); | 446 | return luaK_code(fs, CREATE_Ax(OP_EXTRAARG, A)); |
| 439 | } | 447 | } |
| 440 | 448 | ||
| 441 | 449 | ||
| @@ -1032,10 +1040,10 @@ static int exp2RK (FuncState *fs, expdesc *e) { | |||
| 1032 | } | 1040 | } |
| 1033 | 1041 | ||
| 1034 | 1042 | ||
| 1035 | static void codeABRK (FuncState *fs, OpCode o, int a, int b, | 1043 | static void codeABRK (FuncState *fs, OpCode o, int A, int B, |
| 1036 | expdesc *ec) { | 1044 | expdesc *ec) { |
| 1037 | int k = exp2RK(fs, ec); | 1045 | int k = exp2RK(fs, ec); |
| 1038 | luaK_codeABCk(fs, o, a, b, ec->u.info, k); | 1046 | luaK_codeABCk(fs, o, A, B, ec->u.info, k); |
| 1039 | } | 1047 | } |
| 1040 | 1048 | ||
| 1041 | 1049 | ||
| @@ -1788,10 +1796,10 @@ void luaK_fixline (FuncState *fs, int line) { | |||
| 1788 | void luaK_settablesize (FuncState *fs, int pc, int ra, int asize, int hsize) { | 1796 | void luaK_settablesize (FuncState *fs, int pc, int ra, int asize, int hsize) { |
| 1789 | Instruction *inst = &fs->f->code[pc]; | 1797 | Instruction *inst = &fs->f->code[pc]; |
| 1790 | int rb = (hsize != 0) ? luaO_ceillog2(hsize) + 1 : 0; /* hash size */ | 1798 | int rb = (hsize != 0) ? luaO_ceillog2(hsize) + 1 : 0; /* hash size */ |
| 1791 | int extra = asize / (MAXARG_C + 1); /* higher bits of array size */ | 1799 | int extra = asize / (MAXARG_vC + 1); /* higher bits of array size */ |
| 1792 | int rc = asize % (MAXARG_C + 1); /* lower bits of array size */ | 1800 | int rc = asize % (MAXARG_vC + 1); /* lower bits of array size */ |
| 1793 | int k = (extra > 0); /* true iff needs extra argument */ | 1801 | int k = (extra > 0); /* true iff needs extra argument */ |
| 1794 | *inst = CREATE_ABCk(OP_NEWTABLE, ra, rb, rc, k); | 1802 | *inst = CREATE_vABCk(OP_NEWTABLE, ra, rb, rc, k); |
| 1795 | *(inst + 1) = CREATE_Ax(OP_EXTRAARG, extra); | 1803 | *(inst + 1) = CREATE_Ax(OP_EXTRAARG, extra); |
| 1796 | } | 1804 | } |
| 1797 | 1805 | ||
| @@ -1807,12 +1815,12 @@ void luaK_setlist (FuncState *fs, int base, int nelems, int tostore) { | |||
| 1807 | lua_assert(tostore != 0); | 1815 | lua_assert(tostore != 0); |
| 1808 | if (tostore == LUA_MULTRET) | 1816 | if (tostore == LUA_MULTRET) |
| 1809 | tostore = 0; | 1817 | tostore = 0; |
| 1810 | if (nelems <= MAXARG_C) | 1818 | if (nelems <= MAXARG_vC) |
| 1811 | luaK_codeABC(fs, OP_SETLIST, base, tostore, nelems); | 1819 | luaK_codevABCk(fs, OP_SETLIST, base, tostore, nelems, 0); |
| 1812 | else { | 1820 | else { |
| 1813 | int extra = nelems / (MAXARG_C + 1); | 1821 | int extra = nelems / (MAXARG_vC + 1); |
| 1814 | nelems %= (MAXARG_C + 1); | 1822 | nelems %= (MAXARG_vC + 1); |
| 1815 | luaK_codeABCk(fs, OP_SETLIST, base, tostore, nelems, 1); | 1823 | luaK_codevABCk(fs, OP_SETLIST, base, tostore, nelems, 1); |
| 1816 | codeextraarg(fs, extra); | 1824 | codeextraarg(fs, extra); |
| 1817 | } | 1825 | } |
| 1818 | fs->freereg = base + 1; /* free registers with list values */ | 1826 | fs->freereg = base + 1; /* free registers with list values */ |
| @@ -1839,6 +1847,7 @@ static int finaltarget (Instruction *code, int i) { | |||
| 1839 | ** Do a final pass over the code of a function, doing small peephole | 1847 | ** Do a final pass over the code of a function, doing small peephole |
| 1840 | ** optimizations and adjustments. | 1848 | ** optimizations and adjustments. |
| 1841 | */ | 1849 | */ |
| 1850 | #include "lopnames.h" | ||
| 1842 | void luaK_finish (FuncState *fs) { | 1851 | void luaK_finish (FuncState *fs) { |
| 1843 | int i; | 1852 | int i; |
| 1844 | Proto *p = fs->f; | 1853 | Proto *p = fs->f; |
