aboutsummaryrefslogtreecommitdiff
path: root/src/lua/lcode.c
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2021-01-05 16:48:53 +0800
committerLi Jin <dragon-fly@qq.com>2021-01-05 16:48:53 +0800
commit71b9532659abb531bd1597d88451426dcc895824 (patch)
treec9b50856b37f759c9a31e1a6e761e77b51996fa6 /src/lua/lcode.c
parente3a31f9945053d8e8d9e4ef3d2e4c9abe563cff2 (diff)
downloadyuescript-71b9532659abb531bd1597d88451426dcc895824.tar.gz
yuescript-71b9532659abb531bd1597d88451426dcc895824.tar.bz2
yuescript-71b9532659abb531bd1597d88451426dcc895824.zip
update Lua.
Diffstat (limited to 'src/lua/lcode.c')
-rw-r--r--src/lua/lcode.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/src/lua/lcode.c b/src/lua/lcode.c
index 6f241c9..d8d353f 100644
--- a/src/lua/lcode.c
+++ b/src/lua/lcode.c
@@ -545,11 +545,14 @@ static void freeexps (FuncState *fs, expdesc *e1, expdesc *e2) {
545** and try to reuse constants. Because some values should not be used 545** and try to reuse constants. Because some values should not be used
546** as keys (nil cannot be a key, integer keys can collapse with float 546** as keys (nil cannot be a key, integer keys can collapse with float
547** keys), the caller must provide a useful 'key' for indexing the cache. 547** keys), the caller must provide a useful 'key' for indexing the cache.
548** Note that all functions share the same table, so entering or exiting
549** a function can make some indices wrong.
548*/ 550*/
549static int addk (FuncState *fs, TValue *key, TValue *v) { 551static int addk (FuncState *fs, TValue *key, TValue *v) {
552 TValue val;
550 lua_State *L = fs->ls->L; 553 lua_State *L = fs->ls->L;
551 Proto *f = fs->f; 554 Proto *f = fs->f;
552 TValue *idx = luaH_set(L, fs->ls->h, key); /* index scanner table */ 555 const TValue *idx = luaH_get(fs->ls->h, key); /* query scanner table */
553 int k, oldsize; 556 int k, oldsize;
554 if (ttisinteger(idx)) { /* is there an index there? */ 557 if (ttisinteger(idx)) { /* is there an index there? */
555 k = cast_int(ivalue(idx)); 558 k = cast_int(ivalue(idx));
@@ -563,7 +566,8 @@ static int addk (FuncState *fs, TValue *key, TValue *v) {
563 k = fs->nk; 566 k = fs->nk;
564 /* numerical value does not need GC barrier; 567 /* numerical value does not need GC barrier;
565 table has no metatable, so it does not need to invalidate cache */ 568 table has no metatable, so it does not need to invalidate cache */
566 setivalue(idx, k); 569 setivalue(&val, k);
570 luaH_finishset(L, fs->ls->h, key, idx, &val);
567 luaM_growvector(L, f->k, k, f->sizek, TValue, MAXARG_Ax, "constants"); 571 luaM_growvector(L, f->k, k, f->sizek, TValue, MAXARG_Ax, "constants");
568 while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]); 572 while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]);
569 setobj(L, &f->k[k], v); 573 setobj(L, &f->k[k], v);
@@ -753,7 +757,7 @@ void luaK_setoneret (FuncState *fs, expdesc *e) {
753 757
754 758
755/* 759/*
756** Ensure that expression 'e' is not a variable (nor a constant). 760** Ensure that expression 'e' is not a variable (nor a <const>).
757** (Expression still may have jump lists.) 761** (Expression still may have jump lists.)
758*/ 762*/
759void luaK_dischargevars (FuncState *fs, expdesc *e) { 763void luaK_dischargevars (FuncState *fs, expdesc *e) {
@@ -763,7 +767,7 @@ void luaK_dischargevars (FuncState *fs, expdesc *e) {
763 break; 767 break;
764 } 768 }
765 case VLOCAL: { /* already in a register */ 769 case VLOCAL: { /* already in a register */
766 e->u.info = e->u.var.sidx; 770 e->u.info = e->u.var.ridx;
767 e->k = VNONRELOC; /* becomes a non-relocatable value */ 771 e->k = VNONRELOC; /* becomes a non-relocatable value */
768 break; 772 break;
769 } 773 }
@@ -805,8 +809,8 @@ void luaK_dischargevars (FuncState *fs, expdesc *e) {
805 809
806 810
807/* 811/*
808** Ensures expression value is in register 'reg' (and therefore 812** Ensure expression value is in register 'reg', making 'e' a
809** 'e' will become a non-relocatable expression). 813** non-relocatable expression.
810** (Expression still may have jump lists.) 814** (Expression still may have jump lists.)
811*/ 815*/
812static void discharge2reg (FuncState *fs, expdesc *e, int reg) { 816static void discharge2reg (FuncState *fs, expdesc *e, int reg) {
@@ -860,7 +864,8 @@ static void discharge2reg (FuncState *fs, expdesc *e, int reg) {
860 864
861 865
862/* 866/*
863** Ensures expression value is in any register. 867** Ensure expression value is in a register, making 'e' a
868** non-relocatable expression.
864** (Expression still may have jump lists.) 869** (Expression still may have jump lists.)
865*/ 870*/
866static void discharge2anyreg (FuncState *fs, expdesc *e) { 871static void discharge2anyreg (FuncState *fs, expdesc *e) {
@@ -946,8 +951,11 @@ int luaK_exp2anyreg (FuncState *fs, expdesc *e) {
946 exp2reg(fs, e, e->u.info); /* put final result in it */ 951 exp2reg(fs, e, e->u.info); /* put final result in it */
947 return e->u.info; 952 return e->u.info;
948 } 953 }
954 /* else expression has jumps and cannot change its register
955 to hold the jump values, because it is a local variable.
956 Go through to the default case. */
949 } 957 }
950 luaK_exp2nextreg(fs, e); /* otherwise, use next available register */ 958 luaK_exp2nextreg(fs, e); /* default: use next available register */
951 return e->u.info; 959 return e->u.info;
952} 960}
953 961
@@ -1032,7 +1040,7 @@ void luaK_storevar (FuncState *fs, expdesc *var, expdesc *ex) {
1032 switch (var->k) { 1040 switch (var->k) {
1033 case VLOCAL: { 1041 case VLOCAL: {
1034 freeexp(fs, ex); 1042 freeexp(fs, ex);
1035 exp2reg(fs, ex, var->u.var.sidx); /* compute 'ex' into proper place */ 1043 exp2reg(fs, ex, var->u.var.ridx); /* compute 'ex' into proper place */
1036 return; 1044 return;
1037 } 1045 }
1038 case VUPVAL: { 1046 case VUPVAL: {
@@ -1272,7 +1280,7 @@ void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) {
1272 } 1280 }
1273 else { 1281 else {
1274 /* register index of the table */ 1282 /* register index of the table */
1275 t->u.ind.t = (t->k == VLOCAL) ? t->u.var.sidx: t->u.info; 1283 t->u.ind.t = (t->k == VLOCAL) ? t->u.var.ridx: t->u.info;
1276 if (isKstr(fs, k)) { 1284 if (isKstr(fs, k)) {
1277 t->u.ind.idx = k->u.info; /* literal string */ 1285 t->u.ind.idx = k->u.info; /* literal string */
1278 t->k = VINDEXSTR; 1286 t->k = VINDEXSTR;