diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-06-29 12:06:44 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-06-29 12:06:44 -0300 |
commit | f96497397addca22f22a6ba6eeabc906be43f16b (patch) | |
tree | af8d27b9af36dfe0b0b6e0f765ea90b95b110efc /lvm.c | |
parent | 5a1c8d8ef343bf0157851a4832c2c937b812b64f (diff) | |
download | lua-f96497397addca22f22a6ba6eeabc906be43f16b.tar.gz lua-f96497397addca22f22a6ba6eeabc906be43f16b.tar.bz2 lua-f96497397addca22f22a6ba6eeabc906be43f16b.zip |
new type 'StackValue' for stack elements
(we may want to put extra info there in the future)
Diffstat (limited to 'lvm.c')
-rw-r--r-- | lvm.c | 209 |
1 files changed, 107 insertions, 102 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 2.286 2017/06/01 20:22:33 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.287 2017/06/09 19:16:41 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 | */ |
@@ -172,13 +172,13 @@ void luaV_finishget (lua_State *L, const TValue *t, TValue *key, StkId val, | |||
172 | lua_assert(ttisnil(slot)); | 172 | lua_assert(ttisnil(slot)); |
173 | tm = fasttm(L, hvalue(t)->metatable, TM_INDEX); /* table's metamethod */ | 173 | tm = fasttm(L, hvalue(t)->metatable, TM_INDEX); /* table's metamethod */ |
174 | if (tm == NULL) { /* no metamethod? */ | 174 | if (tm == NULL) { /* no metamethod? */ |
175 | setnilvalue(val); /* result is nil */ | 175 | setnilvalue(s2v(val)); /* result is nil */ |
176 | return; | 176 | return; |
177 | } | 177 | } |
178 | /* else will try the metamethod */ | 178 | /* else will try the metamethod */ |
179 | } | 179 | } |
180 | if (ttisfunction(tm)) { /* is metamethod a function? */ | 180 | if (ttisfunction(tm)) { /* is metamethod a function? */ |
181 | luaT_callTM(L, tm, t, key, val, 1); /* call it */ | 181 | luaT_callTMres(L, tm, t, key, val); /* call it */ |
182 | return; | 182 | return; |
183 | } | 183 | } |
184 | t = tm; /* else try to access 'tm[key]' */ | 184 | t = tm; /* else try to access 'tm[key]' */ |
@@ -200,7 +200,7 @@ void luaV_finishget (lua_State *L, const TValue *t, TValue *key, StkId val, | |||
200 | ** would have done the job.) | 200 | ** would have done the job.) |
201 | */ | 201 | */ |
202 | void luaV_finishset (lua_State *L, const TValue *t, TValue *key, | 202 | void luaV_finishset (lua_State *L, const TValue *t, TValue *key, |
203 | StkId val, const TValue *slot) { | 203 | TValue *val, const TValue *slot) { |
204 | int loop; /* counter to avoid infinite loops */ | 204 | int loop; /* counter to avoid infinite loops */ |
205 | for (loop = 0; loop < MAXTAGLOOP; loop++) { | 205 | for (loop = 0; loop < MAXTAGLOOP; loop++) { |
206 | const TValue *tm; /* '__newindex' metamethod */ | 206 | const TValue *tm; /* '__newindex' metamethod */ |
@@ -225,7 +225,7 @@ void luaV_finishset (lua_State *L, const TValue *t, TValue *key, | |||
225 | } | 225 | } |
226 | /* try the metamethod */ | 226 | /* try the metamethod */ |
227 | if (ttisfunction(tm)) { | 227 | if (ttisfunction(tm)) { |
228 | luaT_callTM(L, tm, t, key, val, 0); | 228 | luaT_callTM(L, tm, t, key, val); |
229 | return; | 229 | return; |
230 | } | 230 | } |
231 | t = tm; /* else repeat assignment over 'tm' */ | 231 | t = tm; /* else repeat assignment over 'tm' */ |
@@ -446,8 +446,8 @@ int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) { | |||
446 | } | 446 | } |
447 | if (tm == NULL) /* no TM? */ | 447 | if (tm == NULL) /* no TM? */ |
448 | return 0; /* objects are different */ | 448 | return 0; /* objects are different */ |
449 | luaT_callTM(L, tm, t1, t2, L->top, 1); /* call TM */ | 449 | luaT_callTMres(L, tm, t1, t2, L->top); /* call TM */ |
450 | return !l_isfalse(L->top); | 450 | return !l_isfalse(s2v(L->top)); |
451 | } | 451 | } |
452 | 452 | ||
453 | 453 | ||
@@ -461,8 +461,8 @@ int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) { | |||
461 | static void copy2buff (StkId top, int n, char *buff) { | 461 | static void copy2buff (StkId top, int n, char *buff) { |
462 | size_t tl = 0; /* size already copied */ | 462 | size_t tl = 0; /* size already copied */ |
463 | do { | 463 | do { |
464 | size_t l = vslen(top - n); /* length of string being copied */ | 464 | size_t l = vslen(s2v(top - n)); /* length of string being copied */ |
465 | memcpy(buff + tl, svalue(top - n), l * sizeof(char)); | 465 | memcpy(buff + tl, svalue(s2v(top - n)), l * sizeof(char)); |
466 | tl += l; | 466 | tl += l; |
467 | } while (--n > 0); | 467 | } while (--n > 0); |
468 | } | 468 | } |
@@ -477,20 +477,21 @@ void luaV_concat (lua_State *L, int total) { | |||
477 | do { | 477 | do { |
478 | StkId top = L->top; | 478 | StkId top = L->top; |
479 | int n = 2; /* number of elements handled in this pass (at least 2) */ | 479 | int n = 2; /* number of elements handled in this pass (at least 2) */ |
480 | if (!(ttisstring(top-2) || cvt2str(top-2)) || !tostring(L, top-1)) | 480 | if (!(ttisstring(s2v(top - 2)) || cvt2str(s2v(top - 2))) || |
481 | luaT_trybinTM(L, top-2, top-1, top-2, TM_CONCAT); | 481 | !tostring(L, s2v(top - 1))) |
482 | else if (isemptystr(top - 1)) /* second operand is empty? */ | 482 | luaT_trybinTM(L, s2v(top - 2), s2v(top - 1), top - 2, TM_CONCAT); |
483 | cast_void(tostring(L, top - 2)); /* result is first operand */ | 483 | else if (isemptystr(s2v(top - 1))) /* second operand is empty? */ |
484 | else if (isemptystr(top - 2)) { /* first operand is an empty string? */ | 484 | cast_void(tostring(L, s2v(top - 2))); /* result is first operand */ |
485 | else if (isemptystr(s2v(top - 2))) { /* first operand is empty string? */ | ||
485 | setobjs2s(L, top - 2, top - 1); /* result is second op. */ | 486 | setobjs2s(L, top - 2, top - 1); /* result is second op. */ |
486 | } | 487 | } |
487 | else { | 488 | else { |
488 | /* at least two non-empty string values; get as many as possible */ | 489 | /* at least two non-empty string values; get as many as possible */ |
489 | size_t tl = vslen(top - 1); | 490 | size_t tl = vslen(s2v(top - 1)); |
490 | TString *ts; | 491 | TString *ts; |
491 | /* collect total length and number of strings */ | 492 | /* collect total length and number of strings */ |
492 | for (n = 1; n < total && tostring(L, top - n - 1); n++) { | 493 | for (n = 1; n < total && tostring(L, s2v(top - n - 1)); n++) { |
493 | size_t l = vslen(top - n - 1); | 494 | size_t l = vslen(s2v(top - n - 1)); |
494 | if (l >= (MAX_SIZE/sizeof(char)) - tl) | 495 | if (l >= (MAX_SIZE/sizeof(char)) - tl) |
495 | luaG_runerror(L, "string length overflow"); | 496 | luaG_runerror(L, "string length overflow"); |
496 | tl += l; | 497 | tl += l; |
@@ -522,15 +523,15 @@ void luaV_objlen (lua_State *L, StkId ra, const TValue *rb) { | |||
522 | Table *h = hvalue(rb); | 523 | Table *h = hvalue(rb); |
523 | tm = fasttm(L, h->metatable, TM_LEN); | 524 | tm = fasttm(L, h->metatable, TM_LEN); |
524 | if (tm) break; /* metamethod? break switch to call it */ | 525 | if (tm) break; /* metamethod? break switch to call it */ |
525 | setivalue(ra, luaH_getn(h)); /* else primitive len */ | 526 | setivalue(s2v(ra), luaH_getn(h)); /* else primitive len */ |
526 | return; | 527 | return; |
527 | } | 528 | } |
528 | case LUA_TSHRSTR: { | 529 | case LUA_TSHRSTR: { |
529 | setivalue(ra, tsvalue(rb)->shrlen); | 530 | setivalue(s2v(ra), tsvalue(rb)->shrlen); |
530 | return; | 531 | return; |
531 | } | 532 | } |
532 | case LUA_TLNGSTR: { | 533 | case LUA_TLNGSTR: { |
533 | setivalue(ra, tsvalue(rb)->u.lnglen); | 534 | setivalue(s2v(ra), tsvalue(rb)->u.lnglen); |
534 | return; | 535 | return; |
535 | } | 536 | } |
536 | default: { /* try metamethod */ | 537 | default: { /* try metamethod */ |
@@ -540,7 +541,7 @@ void luaV_objlen (lua_State *L, StkId ra, const TValue *rb) { | |||
540 | break; | 541 | break; |
541 | } | 542 | } |
542 | } | 543 | } |
543 | luaT_callTM(L, tm, rb, rb, ra, 1); | 544 | luaT_callTMres(L, tm, rb, rb, ra); |
544 | } | 545 | } |
545 | 546 | ||
546 | 547 | ||
@@ -615,7 +616,7 @@ static LClosure *getcached (Proto *p, UpVal **encup, StkId base) { | |||
615 | Upvaldesc *uv = p->upvalues; | 616 | Upvaldesc *uv = p->upvalues; |
616 | int i; | 617 | int i; |
617 | for (i = 0; i < nup; i++) { /* check whether it has right upvalues */ | 618 | for (i = 0; i < nup; i++) { /* check whether it has right upvalues */ |
618 | TValue *v = uv[i].instack ? base + uv[i].idx : encup[uv[i].idx]->v; | 619 | TValue *v = uv[i].instack ? s2v(base + uv[i].idx) : encup[uv[i].idx]->v; |
619 | if (c->upvals[i]->v != v) | 620 | if (c->upvals[i]->v != v) |
620 | return NULL; /* wrong upvalue; cannot reuse closure */ | 621 | return NULL; /* wrong upvalue; cannot reuse closure */ |
621 | } | 622 | } |
@@ -636,7 +637,7 @@ static void pushclosure (lua_State *L, Proto *p, UpVal **encup, StkId base, | |||
636 | int i; | 637 | int i; |
637 | LClosure *ncl = luaF_newLclosure(L, nup); | 638 | LClosure *ncl = luaF_newLclosure(L, nup); |
638 | ncl->p = p; | 639 | ncl->p = p; |
639 | setclLvalue(L, ra, ncl); /* anchor new closure in stack */ | 640 | setclLvalue2s(L, ra, ncl); /* anchor new closure in stack */ |
640 | for (i = 0; i < nup; i++) { /* fill in its upvalues */ | 641 | for (i = 0; i < nup; i++) { /* fill in its upvalues */ |
641 | if (uv[i].instack) /* upvalue refers to local variable? */ | 642 | if (uv[i].instack) /* upvalue refers to local variable? */ |
642 | ncl->upvals[i] = luaF_findupval(L, base + uv[i].idx); | 643 | ncl->upvals[i] = luaF_findupval(L, base + uv[i].idx); |
@@ -674,7 +675,7 @@ void luaV_finishOp (lua_State *L) { | |||
674 | break; | 675 | break; |
675 | } | 676 | } |
676 | case OP_LE: case OP_LT: case OP_EQ: { | 677 | case OP_LE: case OP_LT: case OP_EQ: { |
677 | int res = !l_isfalse(L->top - 1); | 678 | int res = !l_isfalse(s2v(L->top - 1)); |
678 | L->top--; | 679 | L->top--; |
679 | if (ci->callstatus & CIST_LEQ) { /* "<=" using "<" instead? */ | 680 | if (ci->callstatus & CIST_LEQ) { /* "<=" using "<" instead? */ |
680 | lua_assert(op == OP_LE); | 681 | lua_assert(op == OP_LE); |
@@ -734,13 +735,15 @@ void luaV_finishOp (lua_State *L) { | |||
734 | 735 | ||
735 | #define RA(i) (base+GETARG_A(i)) | 736 | #define RA(i) (base+GETARG_A(i)) |
736 | #define RB(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgR, base+GETARG_Br(i)) | 737 | #define RB(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgR, base+GETARG_Br(i)) |
738 | #define vRB(i) s2v(RB(i)) | ||
737 | #define KB(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgK, k+GETARG_B(i)) | 739 | #define KB(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgK, k+GETARG_B(i)) |
738 | #define RC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgR, base+GETARG_C(i)) | 740 | #define RC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgR, base+GETARG_C(i)) |
741 | #define vRC(i) s2v(RC(i)) | ||
739 | #define KC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgK, k+GETARG_C(i)) | 742 | #define KC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgK, k+GETARG_C(i)) |
740 | #define RKB(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgK, \ | 743 | #define RKB(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgK, \ |
741 | (GETARG_Bk(i)) ? k + GETARG_Br(i) : base + GETARG_Br(i)) | 744 | (GETARG_Bk(i)) ? k + GETARG_Br(i) : s2v(base + GETARG_Br(i))) |
742 | #define RKC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgK, \ | 745 | #define RKC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgK, \ |
743 | (GETARG_Ck(i)) ? k + GETARG_Cr(i) : base + GETARG_Cr(i)) | 746 | (GETARG_Ck(i)) ? k + GETARG_Cr(i) : s2v(base + GETARG_Cr(i))) |
744 | 747 | ||
745 | 748 | ||
746 | 749 | ||
@@ -803,7 +806,7 @@ void luaV_execute (lua_State *L) { | |||
803 | ci->callstatus |= CIST_FRESH; /* fresh invocation of 'luaV_execute" */ | 806 | ci->callstatus |= CIST_FRESH; /* fresh invocation of 'luaV_execute" */ |
804 | newframe: /* reentry point when frame changes (call/return) */ | 807 | newframe: /* reentry point when frame changes (call/return) */ |
805 | lua_assert(ci == L->ci); | 808 | lua_assert(ci == L->ci); |
806 | cl = clLvalue(ci->func); /* local reference to function's closure */ | 809 | cl = clLvalue(s2v(ci->func)); /* local reference to function's closure */ |
807 | k = cl->p->k; /* local reference to function's constant table */ | 810 | k = cl->p->k; /* local reference to function's constant table */ |
808 | updatemask(L); | 811 | updatemask(L); |
809 | base = ci->func + 1; | 812 | base = ci->func + 1; |
@@ -827,7 +830,7 @@ void luaV_execute (lua_State *L) { | |||
827 | } | 830 | } |
828 | vmcase(OP_LOADI) { | 831 | vmcase(OP_LOADI) { |
829 | lua_Integer b = GETARG_sBx(i); | 832 | lua_Integer b = GETARG_sBx(i); |
830 | setivalue(ra, b); | 833 | setivalue(s2v(ra), b); |
831 | vmbreak; | 834 | vmbreak; |
832 | } | 835 | } |
833 | vmcase(OP_LOADKX) { | 836 | vmcase(OP_LOADKX) { |
@@ -838,14 +841,14 @@ void luaV_execute (lua_State *L) { | |||
838 | vmbreak; | 841 | vmbreak; |
839 | } | 842 | } |
840 | vmcase(OP_LOADBOOL) { | 843 | vmcase(OP_LOADBOOL) { |
841 | setbvalue(ra, GETARG_B(i)); | 844 | setbvalue(s2v(ra), GETARG_B(i)); |
842 | if (GETARG_C(i)) pc++; /* skip next instruction (if C) */ | 845 | if (GETARG_C(i)) pc++; /* skip next instruction (if C) */ |
843 | vmbreak; | 846 | vmbreak; |
844 | } | 847 | } |
845 | vmcase(OP_LOADNIL) { | 848 | vmcase(OP_LOADNIL) { |
846 | int b = GETARG_B(i); | 849 | int b = GETARG_B(i); |
847 | do { | 850 | do { |
848 | setnilvalue(ra++); | 851 | setnilvalue(s2v(ra++)); |
849 | } while (b--); | 852 | } while (b--); |
850 | vmbreak; | 853 | vmbreak; |
851 | } | 854 | } |
@@ -856,8 +859,8 @@ void luaV_execute (lua_State *L) { | |||
856 | } | 859 | } |
857 | vmcase(OP_SETUPVAL) { | 860 | vmcase(OP_SETUPVAL) { |
858 | UpVal *uv = cl->upvals[GETARG_B(i)]; | 861 | UpVal *uv = cl->upvals[GETARG_B(i)]; |
859 | setobj(L, uv->v, ra); | 862 | setobj(L, uv->v, s2v(ra)); |
860 | luaC_barrier(L, uv, ra); | 863 | luaC_barrier(L, uv, s2v(ra)); |
861 | vmbreak; | 864 | vmbreak; |
862 | } | 865 | } |
863 | vmcase(OP_GETTABUP) { | 866 | vmcase(OP_GETTABUP) { |
@@ -873,8 +876,8 @@ void luaV_execute (lua_State *L) { | |||
873 | } | 876 | } |
874 | vmcase(OP_GETTABLE) { | 877 | vmcase(OP_GETTABLE) { |
875 | const TValue *slot; | 878 | const TValue *slot; |
876 | StkId rb = RB(i); | 879 | TValue *rb = vRB(i); |
877 | TValue *rc = RC(i); | 880 | TValue *rc = vRC(i); |
878 | lua_Unsigned n; | 881 | lua_Unsigned n; |
879 | if (ttisinteger(rc) /* fast track for integers? */ | 882 | if (ttisinteger(rc) /* fast track for integers? */ |
880 | ? (n = ivalue(rc), luaV_fastgeti(L, rb, n, slot)) | 883 | ? (n = ivalue(rc), luaV_fastgeti(L, rb, n, slot)) |
@@ -887,7 +890,7 @@ void luaV_execute (lua_State *L) { | |||
887 | } | 890 | } |
888 | vmcase(OP_GETI) { | 891 | vmcase(OP_GETI) { |
889 | const TValue *slot; | 892 | const TValue *slot; |
890 | StkId rb = RB(i); | 893 | TValue *rb = vRB(i); |
891 | int c = GETARG_C(i); | 894 | int c = GETARG_C(i); |
892 | if (luaV_fastgeti(L, rb, c, slot)) { | 895 | if (luaV_fastgeti(L, rb, c, slot)) { |
893 | setobj2s(L, ra, slot); | 896 | setobj2s(L, ra, slot); |
@@ -901,7 +904,7 @@ void luaV_execute (lua_State *L) { | |||
901 | } | 904 | } |
902 | vmcase(OP_GETFIELD) { | 905 | vmcase(OP_GETFIELD) { |
903 | const TValue *slot; | 906 | const TValue *slot; |
904 | StkId rb = RB(i); | 907 | TValue *rb = vRB(i); |
905 | TValue *rc = KC(i); | 908 | TValue *rc = KC(i); |
906 | TString *key = tsvalue(rc); /* key must be a string */ | 909 | TString *key = tsvalue(rc); /* key must be a string */ |
907 | if (luaV_fastget(L, rb, key, slot, luaH_getshortstr)) { | 910 | if (luaV_fastget(L, rb, key, slot, luaH_getshortstr)) { |
@@ -925,29 +928,29 @@ void luaV_execute (lua_State *L) { | |||
925 | } | 928 | } |
926 | vmcase(OP_SETTABLE) { | 929 | vmcase(OP_SETTABLE) { |
927 | const TValue *slot; | 930 | const TValue *slot; |
928 | TValue *rb = RB(i); /* key (table is in 'ra') */ | 931 | TValue *rb = vRB(i); /* key (table is in 'ra') */ |
929 | TValue *rc = RKC(i); /* value */ | 932 | TValue *rc = RKC(i); /* value */ |
930 | lua_Unsigned n; | 933 | lua_Unsigned n; |
931 | if (ttisinteger(rb) /* fast track for integers? */ | 934 | if (ttisinteger(rb) /* fast track for integers? */ |
932 | ? (n = ivalue(rb), luaV_fastgeti(L, ra, n, slot)) | 935 | ? (n = ivalue(rb), luaV_fastgeti(L, s2v(ra), n, slot)) |
933 | : luaV_fastget(L, ra, rb, slot, luaH_get)) { | 936 | : luaV_fastget(L, s2v(ra), rb, slot, luaH_get)) { |
934 | luaV_finishfastset(L, ra, slot, rc); | 937 | luaV_finishfastset(L, s2v(ra), slot, rc); |
935 | } | 938 | } |
936 | else | 939 | else |
937 | Protect(luaV_finishset(L, ra, rb, rc, slot)); | 940 | Protect(luaV_finishset(L, s2v(ra), rb, rc, slot)); |
938 | vmbreak; | 941 | vmbreak; |
939 | } | 942 | } |
940 | vmcase(OP_SETI) { | 943 | vmcase(OP_SETI) { |
941 | const TValue *slot; | 944 | const TValue *slot; |
942 | int c = GETARG_B(i); | 945 | int c = GETARG_B(i); |
943 | TValue *rc = RKC(i); | 946 | TValue *rc = RKC(i); |
944 | if (luaV_fastgeti(L, ra, c, slot)) { | 947 | if (luaV_fastgeti(L, s2v(ra), c, slot)) { |
945 | luaV_finishfastset(L, ra, slot, rc); | 948 | luaV_finishfastset(L, s2v(ra), slot, rc); |
946 | } | 949 | } |
947 | else { | 950 | else { |
948 | TValue key; | 951 | TValue key; |
949 | setivalue(&key, c); | 952 | setivalue(&key, c); |
950 | Protect(luaV_finishset(L, ra, &key, rc, slot)); | 953 | Protect(luaV_finishset(L, s2v(ra), &key, rc, slot)); |
951 | } | 954 | } |
952 | vmbreak; | 955 | vmbreak; |
953 | } | 956 | } |
@@ -956,11 +959,11 @@ void luaV_execute (lua_State *L) { | |||
956 | TValue *rb = KB(i); | 959 | TValue *rb = KB(i); |
957 | TValue *rc = RKC(i); | 960 | TValue *rc = RKC(i); |
958 | TString *key = tsvalue(rb); /* key must be a string */ | 961 | TString *key = tsvalue(rb); /* key must be a string */ |
959 | if (luaV_fastget(L, ra, key, slot, luaH_getshortstr)) { | 962 | if (luaV_fastget(L, s2v(ra), key, slot, luaH_getshortstr)) { |
960 | luaV_finishfastset(L, ra, slot, rc); | 963 | luaV_finishfastset(L, s2v(ra), slot, rc); |
961 | } | 964 | } |
962 | else | 965 | else |
963 | Protect(luaV_finishset(L, ra, rb, rc, slot)); | 966 | Protect(luaV_finishset(L, s2v(ra), rb, rc, slot)); |
964 | vmbreak; | 967 | vmbreak; |
965 | } | 968 | } |
966 | vmcase(OP_NEWTABLE) { | 969 | vmcase(OP_NEWTABLE) { |
@@ -969,7 +972,7 @@ void luaV_execute (lua_State *L) { | |||
969 | Table *t; | 972 | Table *t; |
970 | savepc(L); /* in case of allocation errors */ | 973 | savepc(L); /* in case of allocation errors */ |
971 | t = luaH_new(L); | 974 | t = luaH_new(L); |
972 | sethvalue(L, ra, t); | 975 | sethvalue2s(L, ra, t); |
973 | if (b != 0 || c != 0) | 976 | if (b != 0 || c != 0) |
974 | luaH_resize(L, t, luaO_fb2int(b), luaO_fb2int(c)); | 977 | luaH_resize(L, t, luaO_fb2int(b), luaO_fb2int(c)); |
975 | checkGC(L, ra + 1); | 978 | checkGC(L, ra + 1); |
@@ -977,10 +980,10 @@ void luaV_execute (lua_State *L) { | |||
977 | } | 980 | } |
978 | vmcase(OP_SELF) { | 981 | vmcase(OP_SELF) { |
979 | const TValue *slot; | 982 | const TValue *slot; |
980 | StkId rb = RB(i); | 983 | TValue *rb = vRB(i); |
981 | TValue *rc = RKC(i); | 984 | TValue *rc = RKC(i); |
982 | TString *key = tsvalue(rc); /* key must be a string */ | 985 | TString *key = tsvalue(rc); /* key must be a string */ |
983 | setobjs2s(L, ra + 1, rb); | 986 | setobj2s(L, ra + 1, rb); |
984 | if (luaV_fastget(L, rb, key, slot, luaH_getstr)) { | 987 | if (luaV_fastget(L, rb, key, slot, luaH_getstr)) { |
985 | setobj2s(L, ra, slot); | 988 | setobj2s(L, ra, slot); |
986 | } | 989 | } |
@@ -988,14 +991,14 @@ void luaV_execute (lua_State *L) { | |||
988 | vmbreak; | 991 | vmbreak; |
989 | } | 992 | } |
990 | vmcase(OP_ADDI) { | 993 | vmcase(OP_ADDI) { |
991 | TValue *rb = RB(i); | 994 | TValue *rb = vRB(i); |
992 | int ic = GETARG_C(i); | 995 | int ic = GETARG_C(i); |
993 | lua_Number nb; | 996 | lua_Number nb; |
994 | if (ttisinteger(rb)) { | 997 | if (ttisinteger(rb)) { |
995 | setivalue(ra, intop(+, ivalue(rb), ic)); | 998 | setivalue(s2v(ra), intop(+, ivalue(rb), ic)); |
996 | } | 999 | } |
997 | else if (tonumber(rb, &nb)) { | 1000 | else if (tonumber(rb, &nb)) { |
998 | setfltvalue(ra, luai_numadd(L, nb, cast_num(ic))); | 1001 | setfltvalue(s2v(ra), luai_numadd(L, nb, cast_num(ic))); |
999 | } | 1002 | } |
1000 | else { | 1003 | else { |
1001 | TValue aux; TValue *rc; | 1004 | TValue aux; TValue *rc; |
@@ -1014,10 +1017,10 @@ void luaV_execute (lua_State *L) { | |||
1014 | lua_Number nb; lua_Number nc; | 1017 | lua_Number nb; lua_Number nc; |
1015 | if (ttisinteger(rb) && ttisinteger(rc)) { | 1018 | if (ttisinteger(rb) && ttisinteger(rc)) { |
1016 | lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc); | 1019 | lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc); |
1017 | setivalue(ra, intop(+, ib, ic)); | 1020 | setivalue(s2v(ra), intop(+, ib, ic)); |
1018 | } | 1021 | } |
1019 | else if (tonumber(rb, &nb) && tonumber(rc, &nc)) { | 1022 | else if (tonumber(rb, &nb) && tonumber(rc, &nc)) { |
1020 | setfltvalue(ra, luai_numadd(L, nb, nc)); | 1023 | setfltvalue(s2v(ra), luai_numadd(L, nb, nc)); |
1021 | } | 1024 | } |
1022 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_ADD)); } | 1025 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_ADD)); } |
1023 | vmbreak; | 1026 | vmbreak; |
@@ -1028,10 +1031,10 @@ void luaV_execute (lua_State *L) { | |||
1028 | lua_Number nb; lua_Number nc; | 1031 | lua_Number nb; lua_Number nc; |
1029 | if (ttisinteger(rb) && ttisinteger(rc)) { | 1032 | if (ttisinteger(rb) && ttisinteger(rc)) { |
1030 | lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc); | 1033 | lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc); |
1031 | setivalue(ra, intop(-, ib, ic)); | 1034 | setivalue(s2v(ra), intop(-, ib, ic)); |
1032 | } | 1035 | } |
1033 | else if (tonumber(rb, &nb) && tonumber(rc, &nc)) { | 1036 | else if (tonumber(rb, &nb) && tonumber(rc, &nc)) { |
1034 | setfltvalue(ra, luai_numsub(L, nb, nc)); | 1037 | setfltvalue(s2v(ra), luai_numsub(L, nb, nc)); |
1035 | } | 1038 | } |
1036 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_SUB)); } | 1039 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_SUB)); } |
1037 | vmbreak; | 1040 | vmbreak; |
@@ -1042,10 +1045,10 @@ void luaV_execute (lua_State *L) { | |||
1042 | lua_Number nb; lua_Number nc; | 1045 | lua_Number nb; lua_Number nc; |
1043 | if (ttisinteger(rb) && ttisinteger(rc)) { | 1046 | if (ttisinteger(rb) && ttisinteger(rc)) { |
1044 | lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc); | 1047 | lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc); |
1045 | setivalue(ra, intop(*, ib, ic)); | 1048 | setivalue(s2v(ra), intop(*, ib, ic)); |
1046 | } | 1049 | } |
1047 | else if (tonumber(rb, &nb) && tonumber(rc, &nc)) { | 1050 | else if (tonumber(rb, &nb) && tonumber(rc, &nc)) { |
1048 | setfltvalue(ra, luai_nummul(L, nb, nc)); | 1051 | setfltvalue(s2v(ra), luai_nummul(L, nb, nc)); |
1049 | } | 1052 | } |
1050 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_MUL)); } | 1053 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_MUL)); } |
1051 | vmbreak; | 1054 | vmbreak; |
@@ -1055,7 +1058,7 @@ void luaV_execute (lua_State *L) { | |||
1055 | TValue *rc = RKC(i); | 1058 | TValue *rc = RKC(i); |
1056 | lua_Number nb; lua_Number nc; | 1059 | lua_Number nb; lua_Number nc; |
1057 | if (tonumber(rb, &nb) && tonumber(rc, &nc)) { | 1060 | if (tonumber(rb, &nb) && tonumber(rc, &nc)) { |
1058 | setfltvalue(ra, luai_numdiv(L, nb, nc)); | 1061 | setfltvalue(s2v(ra), luai_numdiv(L, nb, nc)); |
1059 | } | 1062 | } |
1060 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_DIV)); } | 1063 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_DIV)); } |
1061 | vmbreak; | 1064 | vmbreak; |
@@ -1065,7 +1068,7 @@ void luaV_execute (lua_State *L) { | |||
1065 | TValue *rc = RKC(i); | 1068 | TValue *rc = RKC(i); |
1066 | lua_Integer ib; lua_Integer ic; | 1069 | lua_Integer ib; lua_Integer ic; |
1067 | if (tointeger(rb, &ib) && tointeger(rc, &ic)) { | 1070 | if (tointeger(rb, &ib) && tointeger(rc, &ic)) { |
1068 | setivalue(ra, intop(&, ib, ic)); | 1071 | setivalue(s2v(ra), intop(&, ib, ic)); |
1069 | } | 1072 | } |
1070 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_BAND)); } | 1073 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_BAND)); } |
1071 | vmbreak; | 1074 | vmbreak; |
@@ -1075,7 +1078,7 @@ void luaV_execute (lua_State *L) { | |||
1075 | TValue *rc = RKC(i); | 1078 | TValue *rc = RKC(i); |
1076 | lua_Integer ib; lua_Integer ic; | 1079 | lua_Integer ib; lua_Integer ic; |
1077 | if (tointeger(rb, &ib) && tointeger(rc, &ic)) { | 1080 | if (tointeger(rb, &ib) && tointeger(rc, &ic)) { |
1078 | setivalue(ra, intop(|, ib, ic)); | 1081 | setivalue(s2v(ra), intop(|, ib, ic)); |
1079 | } | 1082 | } |
1080 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_BOR)); } | 1083 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_BOR)); } |
1081 | vmbreak; | 1084 | vmbreak; |
@@ -1085,7 +1088,7 @@ void luaV_execute (lua_State *L) { | |||
1085 | TValue *rc = RKC(i); | 1088 | TValue *rc = RKC(i); |
1086 | lua_Integer ib; lua_Integer ic; | 1089 | lua_Integer ib; lua_Integer ic; |
1087 | if (tointeger(rb, &ib) && tointeger(rc, &ic)) { | 1090 | if (tointeger(rb, &ib) && tointeger(rc, &ic)) { |
1088 | setivalue(ra, intop(^, ib, ic)); | 1091 | setivalue(s2v(ra), intop(^, ib, ic)); |
1089 | } | 1092 | } |
1090 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_BXOR)); } | 1093 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_BXOR)); } |
1091 | vmbreak; | 1094 | vmbreak; |
@@ -1095,7 +1098,7 @@ void luaV_execute (lua_State *L) { | |||
1095 | TValue *rc = RKC(i); | 1098 | TValue *rc = RKC(i); |
1096 | lua_Integer ib; lua_Integer ic; | 1099 | lua_Integer ib; lua_Integer ic; |
1097 | if (tointeger(rb, &ib) && tointeger(rc, &ic)) { | 1100 | if (tointeger(rb, &ib) && tointeger(rc, &ic)) { |
1098 | setivalue(ra, luaV_shiftl(ib, ic)); | 1101 | setivalue(s2v(ra), luaV_shiftl(ib, ic)); |
1099 | } | 1102 | } |
1100 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_SHL)); } | 1103 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_SHL)); } |
1101 | vmbreak; | 1104 | vmbreak; |
@@ -1105,7 +1108,7 @@ void luaV_execute (lua_State *L) { | |||
1105 | TValue *rc = RKC(i); | 1108 | TValue *rc = RKC(i); |
1106 | lua_Integer ib; lua_Integer ic; | 1109 | lua_Integer ib; lua_Integer ic; |
1107 | if (tointeger(rb, &ib) && tointeger(rc, &ic)) { | 1110 | if (tointeger(rb, &ib) && tointeger(rc, &ic)) { |
1108 | setivalue(ra, luaV_shiftl(ib, -ic)); | 1111 | setivalue(s2v(ra), luaV_shiftl(ib, -ic)); |
1109 | } | 1112 | } |
1110 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_SHR)); } | 1113 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_SHR)); } |
1111 | vmbreak; | 1114 | vmbreak; |
@@ -1116,12 +1119,12 @@ void luaV_execute (lua_State *L) { | |||
1116 | lua_Number nb; lua_Number nc; | 1119 | lua_Number nb; lua_Number nc; |
1117 | if (ttisinteger(rb) && ttisinteger(rc)) { | 1120 | if (ttisinteger(rb) && ttisinteger(rc)) { |
1118 | lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc); | 1121 | lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc); |
1119 | setivalue(ra, luaV_mod(L, ib, ic)); | 1122 | setivalue(s2v(ra), luaV_mod(L, ib, ic)); |
1120 | } | 1123 | } |
1121 | else if (tonumber(rb, &nb) && tonumber(rc, &nc)) { | 1124 | else if (tonumber(rb, &nb) && tonumber(rc, &nc)) { |
1122 | lua_Number m; | 1125 | lua_Number m; |
1123 | luai_nummod(L, nb, nc, m); | 1126 | luai_nummod(L, nb, nc, m); |
1124 | setfltvalue(ra, m); | 1127 | setfltvalue(s2v(ra), m); |
1125 | } | 1128 | } |
1126 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_MOD)); } | 1129 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_MOD)); } |
1127 | vmbreak; | 1130 | vmbreak; |
@@ -1132,10 +1135,10 @@ void luaV_execute (lua_State *L) { | |||
1132 | lua_Number nb; lua_Number nc; | 1135 | lua_Number nb; lua_Number nc; |
1133 | if (ttisinteger(rb) && ttisinteger(rc)) { | 1136 | if (ttisinteger(rb) && ttisinteger(rc)) { |
1134 | lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc); | 1137 | lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc); |
1135 | setivalue(ra, luaV_div(L, ib, ic)); | 1138 | setivalue(s2v(ra), luaV_div(L, ib, ic)); |
1136 | } | 1139 | } |
1137 | else if (tonumber(rb, &nb) && tonumber(rc, &nc)) { | 1140 | else if (tonumber(rb, &nb) && tonumber(rc, &nc)) { |
1138 | setfltvalue(ra, luai_numidiv(L, nb, nc)); | 1141 | setfltvalue(s2v(ra), luai_numidiv(L, nb, nc)); |
1139 | } | 1142 | } |
1140 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_IDIV)); } | 1143 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_IDIV)); } |
1141 | vmbreak; | 1144 | vmbreak; |
@@ -1145,20 +1148,20 @@ void luaV_execute (lua_State *L) { | |||
1145 | TValue *rc = RKC(i); | 1148 | TValue *rc = RKC(i); |
1146 | lua_Number nb; lua_Number nc; | 1149 | lua_Number nb; lua_Number nc; |
1147 | if (tonumber(rb, &nb) && tonumber(rc, &nc)) { | 1150 | if (tonumber(rb, &nb) && tonumber(rc, &nc)) { |
1148 | setfltvalue(ra, luai_numpow(L, nb, nc)); | 1151 | setfltvalue(s2v(ra), luai_numpow(L, nb, nc)); |
1149 | } | 1152 | } |
1150 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_POW)); } | 1153 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_POW)); } |
1151 | vmbreak; | 1154 | vmbreak; |
1152 | } | 1155 | } |
1153 | vmcase(OP_UNM) { | 1156 | vmcase(OP_UNM) { |
1154 | TValue *rb = RB(i); | 1157 | TValue *rb = vRB(i); |
1155 | lua_Number nb; | 1158 | lua_Number nb; |
1156 | if (ttisinteger(rb)) { | 1159 | if (ttisinteger(rb)) { |
1157 | lua_Integer ib = ivalue(rb); | 1160 | lua_Integer ib = ivalue(rb); |
1158 | setivalue(ra, intop(-, 0, ib)); | 1161 | setivalue(s2v(ra), intop(-, 0, ib)); |
1159 | } | 1162 | } |
1160 | else if (tonumber(rb, &nb)) { | 1163 | else if (tonumber(rb, &nb)) { |
1161 | setfltvalue(ra, luai_numunm(L, nb)); | 1164 | setfltvalue(s2v(ra), luai_numunm(L, nb)); |
1162 | } | 1165 | } |
1163 | else { | 1166 | else { |
1164 | Protect(luaT_trybinTM(L, rb, rb, ra, TM_UNM)); | 1167 | Protect(luaT_trybinTM(L, rb, rb, ra, TM_UNM)); |
@@ -1166,10 +1169,10 @@ void luaV_execute (lua_State *L) { | |||
1166 | vmbreak; | 1169 | vmbreak; |
1167 | } | 1170 | } |
1168 | vmcase(OP_BNOT) { | 1171 | vmcase(OP_BNOT) { |
1169 | TValue *rb = RB(i); | 1172 | TValue *rb = vRB(i); |
1170 | lua_Integer ib; | 1173 | lua_Integer ib; |
1171 | if (tointeger(rb, &ib)) { | 1174 | if (tointeger(rb, &ib)) { |
1172 | setivalue(ra, intop(^, ~l_castS2U(0), ib)); | 1175 | setivalue(s2v(ra), intop(^, ~l_castS2U(0), ib)); |
1173 | } | 1176 | } |
1174 | else { | 1177 | else { |
1175 | Protect(luaT_trybinTM(L, rb, rb, ra, TM_BNOT)); | 1178 | Protect(luaT_trybinTM(L, rb, rb, ra, TM_BNOT)); |
@@ -1177,13 +1180,13 @@ void luaV_execute (lua_State *L) { | |||
1177 | vmbreak; | 1180 | vmbreak; |
1178 | } | 1181 | } |
1179 | vmcase(OP_NOT) { | 1182 | vmcase(OP_NOT) { |
1180 | TValue *rb = RB(i); | 1183 | TValue *rb = vRB(i); |
1181 | int res = l_isfalse(rb); /* next assignment may change this value */ | 1184 | int res = l_isfalse(rb); /* next assignment may change this value */ |
1182 | setbvalue(ra, res); | 1185 | setbvalue(s2v(ra), res); |
1183 | vmbreak; | 1186 | vmbreak; |
1184 | } | 1187 | } |
1185 | vmcase(OP_LEN) { | 1188 | vmcase(OP_LEN) { |
1186 | Protect(luaV_objlen(L, ra, RB(i))); | 1189 | Protect(luaV_objlen(L, ra, vRB(i))); |
1187 | vmbreak; | 1190 | vmbreak; |
1188 | } | 1191 | } |
1189 | vmcase(OP_CONCAT) { | 1192 | vmcase(OP_CONCAT) { |
@@ -1245,18 +1248,18 @@ void luaV_execute (lua_State *L) { | |||
1245 | vmbreak; | 1248 | vmbreak; |
1246 | } | 1249 | } |
1247 | vmcase(OP_TEST) { | 1250 | vmcase(OP_TEST) { |
1248 | if (GETARG_C(i) ? l_isfalse(ra) : !l_isfalse(ra)) | 1251 | if (GETARG_C(i) ? l_isfalse(s2v(ra)) : !l_isfalse(s2v(ra))) |
1249 | pc++; | 1252 | pc++; |
1250 | else | 1253 | else |
1251 | donextjump(ci); | 1254 | donextjump(ci); |
1252 | vmbreak; | 1255 | vmbreak; |
1253 | } | 1256 | } |
1254 | vmcase(OP_TESTSET) { | 1257 | vmcase(OP_TESTSET) { |
1255 | TValue *rb = RB(i); | 1258 | TValue *rb = vRB(i); |
1256 | if (GETARG_C(i) ? l_isfalse(rb) : !l_isfalse(rb)) | 1259 | if (GETARG_C(i) ? l_isfalse(rb) : !l_isfalse(rb)) |
1257 | pc++; | 1260 | pc++; |
1258 | else { | 1261 | else { |
1259 | setobjs2s(L, ra, rb); | 1262 | setobj2s(L, ra, rb); |
1260 | donextjump(ci); | 1263 | donextjump(ci); |
1261 | } | 1264 | } |
1262 | vmbreak; | 1265 | vmbreak; |
@@ -1295,7 +1298,7 @@ void luaV_execute (lua_State *L) { | |||
1295 | StkId nfunc = nci->func; /* called function */ | 1298 | StkId nfunc = nci->func; /* called function */ |
1296 | StkId ofunc = oci->func; /* caller function */ | 1299 | StkId ofunc = oci->func; /* caller function */ |
1297 | /* last stack slot filled by 'precall' */ | 1300 | /* last stack slot filled by 'precall' */ |
1298 | StkId lim = nci->func + 1 + getproto(nfunc)->numparams; | 1301 | StkId lim = nci->func + 1 + getproto(s2v(nfunc))->numparams; |
1299 | int aux; | 1302 | int aux; |
1300 | /* close all upvalues from previous call */ | 1303 | /* close all upvalues from previous call */ |
1301 | if (cl->p->sizep > 0) luaF_close(L, oci->func + 1); | 1304 | if (cl->p->sizep > 0) luaF_close(L, oci->func + 1); |
@@ -1306,7 +1309,8 @@ void luaV_execute (lua_State *L) { | |||
1306 | oci->u.l.savedpc = nci->u.l.savedpc; | 1309 | oci->u.l.savedpc = nci->u.l.savedpc; |
1307 | oci->callstatus |= CIST_TAIL; /* function was tail called */ | 1310 | oci->callstatus |= CIST_TAIL; /* function was tail called */ |
1308 | ci = L->ci = oci; /* remove new frame */ | 1311 | ci = L->ci = oci; /* remove new frame */ |
1309 | lua_assert(L->top == oci->func + 1 + getproto(ofunc)->maxstacksize); | 1312 | lua_assert(L->top == |
1313 | oci->func + 1 + getproto(s2v(ofunc))->maxstacksize); | ||
1310 | goto newframe; /* restart luaV_execute over new Lua function */ | 1314 | goto newframe; /* restart luaV_execute over new Lua function */ |
1311 | } | 1315 | } |
1312 | vmbreak; | 1316 | vmbreak; |
@@ -1327,34 +1331,35 @@ void luaV_execute (lua_State *L) { | |||
1327 | } | 1331 | } |
1328 | } | 1332 | } |
1329 | vmcase(OP_FORLOOP) { | 1333 | vmcase(OP_FORLOOP) { |
1330 | if (ttisinteger(ra)) { /* integer loop? */ | 1334 | if (ttisinteger(s2v(ra))) { /* integer loop? */ |
1331 | lua_Integer step = ivalue(ra + 2); | 1335 | lua_Integer step = ivalue(s2v(ra + 2)); |
1332 | lua_Integer idx = intop(+, ivalue(ra), step); /* increment index */ | 1336 | lua_Integer idx = intop(+, ivalue(s2v(ra)), step); /* increment index */ |
1333 | lua_Integer limit = ivalue(ra + 1); | 1337 | lua_Integer limit = ivalue(s2v(ra + 1)); |
1334 | if ((0 < step) ? (idx <= limit) : (limit <= idx)) { | 1338 | if ((0 < step) ? (idx <= limit) : (limit <= idx)) { |
1335 | pc += GETARG_sBx(i); /* jump back */ | 1339 | pc += GETARG_sBx(i); /* jump back */ |
1336 | chgivalue(ra, idx); /* update internal index... */ | 1340 | chgivalue(s2v(ra), idx); /* update internal index... */ |
1337 | setivalue(ra + 3, idx); /* ...and external index */ | 1341 | setivalue(s2v(ra + 3), idx); /* ...and external index */ |
1338 | } | 1342 | } |
1339 | } | 1343 | } |
1340 | else { /* floating loop */ | 1344 | else { /* floating loop */ |
1341 | lua_Number step = fltvalue(ra + 2); | 1345 | lua_Number step = fltvalue(s2v(ra + 2)); |
1342 | lua_Number idx = luai_numadd(L, fltvalue(ra), step); /* inc. index */ | 1346 | lua_Number limit = fltvalue(s2v(ra + 1)); |
1343 | lua_Number limit = fltvalue(ra + 1); | 1347 | lua_Number idx = fltvalue(s2v(ra)); |
1348 | idx = luai_numadd(L, idx, step); /* inc. index */ | ||
1344 | if (luai_numlt(0, step) ? luai_numle(idx, limit) | 1349 | if (luai_numlt(0, step) ? luai_numle(idx, limit) |
1345 | : luai_numle(limit, idx)) { | 1350 | : luai_numle(limit, idx)) { |
1346 | pc += GETARG_sBx(i); /* jump back */ | 1351 | pc += GETARG_sBx(i); /* jump back */ |
1347 | chgfltvalue(ra, idx); /* update internal index... */ | 1352 | chgfltvalue(s2v(ra), idx); /* update internal index... */ |
1348 | setfltvalue(ra + 3, idx); /* ...and external index */ | 1353 | setfltvalue(s2v(ra + 3), idx); /* ...and external index */ |
1349 | } | 1354 | } |
1350 | } | 1355 | } |
1351 | updatemask(L); | 1356 | updatemask(L); |
1352 | vmbreak; | 1357 | vmbreak; |
1353 | } | 1358 | } |
1354 | vmcase(OP_FORPREP) { | 1359 | vmcase(OP_FORPREP) { |
1355 | TValue *init = ra; | 1360 | TValue *init = s2v(ra); |
1356 | TValue *plimit = ra + 1; | 1361 | TValue *plimit = s2v(ra + 1); |
1357 | TValue *pstep = ra + 2; | 1362 | TValue *pstep = s2v(ra + 2); |
1358 | lua_Integer ilimit; | 1363 | lua_Integer ilimit; |
1359 | int stopnow; | 1364 | int stopnow; |
1360 | if (ttisinteger(init) && ttisinteger(pstep) && | 1365 | if (ttisinteger(init) && ttisinteger(pstep) && |
@@ -1395,7 +1400,7 @@ void luaV_execute (lua_State *L) { | |||
1395 | } | 1400 | } |
1396 | vmcase(OP_TFORLOOP) { | 1401 | vmcase(OP_TFORLOOP) { |
1397 | l_tforloop: | 1402 | l_tforloop: |
1398 | if (!ttisnil(ra + 1)) { /* continue loop? */ | 1403 | if (!ttisnil(s2v(ra + 1))) { /* continue loop? */ |
1399 | setobjs2s(L, ra, ra + 1); /* save control variable */ | 1404 | setobjs2s(L, ra, ra + 1); /* save control variable */ |
1400 | pc += GETARG_sBx(i); /* jump back */ | 1405 | pc += GETARG_sBx(i); /* jump back */ |
1401 | } | 1406 | } |
@@ -1411,13 +1416,13 @@ void luaV_execute (lua_State *L) { | |||
1411 | lua_assert(GET_OPCODE(*pc) == OP_EXTRAARG); | 1416 | lua_assert(GET_OPCODE(*pc) == OP_EXTRAARG); |
1412 | c = GETARG_Ax(*pc++); | 1417 | c = GETARG_Ax(*pc++); |
1413 | } | 1418 | } |
1414 | h = hvalue(ra); | 1419 | h = hvalue(s2v(ra)); |
1415 | last = ((c-1)*LFIELDS_PER_FLUSH) + n; | 1420 | last = ((c-1)*LFIELDS_PER_FLUSH) + n; |
1416 | savepc(L); /* in case of allocation errors */ | 1421 | savepc(L); /* in case of allocation errors */ |
1417 | if (last > h->sizearray) /* needs more space? */ | 1422 | if (last > h->sizearray) /* needs more space? */ |
1418 | luaH_resizearray(L, h, last); /* preallocate it at once */ | 1423 | luaH_resizearray(L, h, last); /* preallocate it at once */ |
1419 | for (; n > 0; n--) { | 1424 | for (; n > 0; n--) { |
1420 | TValue *val = ra + n; | 1425 | TValue *val = s2v(ra + n); |
1421 | setobj2t(L, &h->array[last - 1], val); | 1426 | setobj2t(L, &h->array[last - 1], val); |
1422 | last--; | 1427 | last--; |
1423 | luaC_barrierback(L, h, val); | 1428 | luaC_barrierback(L, h, val); |
@@ -1433,13 +1438,13 @@ void luaV_execute (lua_State *L) { | |||
1433 | pushclosure(L, p, cl->upvals, base, ra); /* create a new one */ | 1438 | pushclosure(L, p, cl->upvals, base, ra); /* create a new one */ |
1434 | } | 1439 | } |
1435 | else | 1440 | else |
1436 | setclLvalue(L, ra, ncl); /* push cashed closure */ | 1441 | setclLvalue2s(L, ra, ncl); /* push cashed closure */ |
1437 | checkGC(L, ra + 1); | 1442 | checkGC(L, ra + 1); |
1438 | vmbreak; | 1443 | vmbreak; |
1439 | } | 1444 | } |
1440 | vmcase(OP_VARARG) { | 1445 | vmcase(OP_VARARG) { |
1441 | int b = GETARG_B(i) - 1; /* required results */ | 1446 | int b = GETARG_B(i) - 1; /* required results */ |
1442 | StkId vtab = base + cl->p->numparams - 1; /* vararg table */ | 1447 | TValue *vtab = s2v(base + cl->p->numparams - 1); /* vararg table */ |
1443 | Protect(luaT_getvarargs(L, vtab, ra, b)); | 1448 | Protect(luaT_getvarargs(L, vtab, ra, b)); |
1444 | vmbreak; | 1449 | vmbreak; |
1445 | } | 1450 | } |