diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2023-05-15 10:07:25 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2023-05-15 10:07:25 -0300 |
| commit | 934e77a286aeb97ca02badf56956ccc78217e9d0 (patch) | |
| tree | 6994a5bc3d625d1d37156895a5b21bebb46f36a8 | |
| parent | 6443185167c77adcc8552a3fee7edab7895db1a9 (diff) | |
| download | lua-934e77a286aeb97ca02badf56956ccc78217e9d0.tar.gz lua-934e77a286aeb97ca02badf56956ccc78217e9d0.tar.bz2 lua-934e77a286aeb97ca02badf56956ccc78217e9d0.zip | |
Details
- Better comments about short strings in opcodes.
- luaH_newkey made static.
| -rw-r--r-- | lcode.c | 7 | ||||
| -rw-r--r-- | lopcodes.h | 8 | ||||
| -rw-r--r-- | ltable.c | 3 | ||||
| -rw-r--r-- | ltable.h | 2 | ||||
| -rw-r--r-- | lvm.c | 8 |
5 files changed, 14 insertions, 14 deletions
| @@ -1215,7 +1215,7 @@ static void codenot (FuncState *fs, expdesc *e) { | |||
| 1215 | 1215 | ||
| 1216 | 1216 | ||
| 1217 | /* | 1217 | /* |
| 1218 | ** Check whether expression 'e' is a small literal string | 1218 | ** Check whether expression 'e' is a short literal string |
| 1219 | */ | 1219 | */ |
| 1220 | static int isKstr (FuncState *fs, expdesc *e) { | 1220 | static int isKstr (FuncState *fs, expdesc *e) { |
| 1221 | return (e->k == VK && !hasjumps(e) && e->u.info <= MAXARG_B && | 1221 | return (e->k == VK && !hasjumps(e) && e->u.info <= MAXARG_B && |
| @@ -1283,15 +1283,16 @@ void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) { | |||
| 1283 | if (t->k == VUPVAL && !isKstr(fs, k)) /* upvalue indexed by non 'Kstr'? */ | 1283 | if (t->k == VUPVAL && !isKstr(fs, k)) /* upvalue indexed by non 'Kstr'? */ |
| 1284 | luaK_exp2anyreg(fs, t); /* put it in a register */ | 1284 | luaK_exp2anyreg(fs, t); /* put it in a register */ |
| 1285 | if (t->k == VUPVAL) { | 1285 | if (t->k == VUPVAL) { |
| 1286 | lua_assert(isKstr(fs, k)); | ||
| 1286 | t->u.ind.t = t->u.info; /* upvalue index */ | 1287 | t->u.ind.t = t->u.info; /* upvalue index */ |
| 1287 | t->u.ind.idx = k->u.info; /* literal string */ | 1288 | t->u.ind.idx = k->u.info; /* literal short string */ |
| 1288 | t->k = VINDEXUP; | 1289 | t->k = VINDEXUP; |
| 1289 | } | 1290 | } |
| 1290 | else { | 1291 | else { |
| 1291 | /* register index of the table */ | 1292 | /* register index of the table */ |
| 1292 | t->u.ind.t = (t->k == VLOCAL) ? t->u.var.ridx: t->u.info; | 1293 | t->u.ind.t = (t->k == VLOCAL) ? t->u.var.ridx: t->u.info; |
| 1293 | if (isKstr(fs, k)) { | 1294 | if (isKstr(fs, k)) { |
| 1294 | t->u.ind.idx = k->u.info; /* literal string */ | 1295 | t->u.ind.idx = k->u.info; /* literal short string */ |
| 1295 | t->k = VINDEXSTR; | 1296 | t->k = VINDEXSTR; |
| 1296 | } | 1297 | } |
| 1297 | else if (isCint(k)) { | 1298 | else if (isCint(k)) { |
| @@ -210,15 +210,15 @@ OP_LOADNIL,/* A B R[A], R[A+1], ..., R[A+B] := nil */ | |||
| 210 | OP_GETUPVAL,/* A B R[A] := UpValue[B] */ | 210 | OP_GETUPVAL,/* A B R[A] := UpValue[B] */ |
| 211 | OP_SETUPVAL,/* A B UpValue[B] := R[A] */ | 211 | OP_SETUPVAL,/* A B UpValue[B] := R[A] */ |
| 212 | 212 | ||
| 213 | OP_GETTABUP,/* A B C R[A] := UpValue[B][K[C]:string] */ | 213 | OP_GETTABUP,/* A B C R[A] := UpValue[B][K[C]:shortstring] */ |
| 214 | OP_GETTABLE,/* A B C R[A] := R[B][R[C]] */ | 214 | OP_GETTABLE,/* A B C R[A] := R[B][R[C]] */ |
| 215 | OP_GETI,/* A B C R[A] := R[B][C] */ | 215 | OP_GETI,/* A B C R[A] := R[B][C] */ |
| 216 | OP_GETFIELD,/* A B C R[A] := R[B][K[C]:string] */ | 216 | OP_GETFIELD,/* A B C R[A] := R[B][K[C]:shortstring] */ |
| 217 | 217 | ||
| 218 | OP_SETTABUP,/* A B C UpValue[A][K[B]:string] := RK(C) */ | 218 | OP_SETTABUP,/* A B C UpValue[A][K[B]:shortstring] := RK(C) */ |
| 219 | OP_SETTABLE,/* A B C R[A][R[B]] := RK(C) */ | 219 | OP_SETTABLE,/* A B C R[A][R[B]] := RK(C) */ |
| 220 | OP_SETI,/* A B C R[A][B] := RK(C) */ | 220 | OP_SETI,/* A B C R[A][B] := RK(C) */ |
| 221 | OP_SETFIELD,/* A B C R[A][K[B]:string] := RK(C) */ | 221 | OP_SETFIELD,/* A B C R[A][K[B]:shortstring] := RK(C) */ |
| 222 | 222 | ||
| 223 | OP_NEWTABLE,/* A B C k R[A] := {} */ | 223 | OP_NEWTABLE,/* A B C k R[A] := {} */ |
| 224 | 224 | ||
| @@ -662,7 +662,8 @@ static Node *getfreepos (Table *t) { | |||
| 662 | ** put new key in its main position; otherwise (colliding node is in its main | 662 | ** put new key in its main position; otherwise (colliding node is in its main |
| 663 | ** position), new key goes to an empty position. | 663 | ** position), new key goes to an empty position. |
| 664 | */ | 664 | */ |
| 665 | void luaH_newkey (lua_State *L, Table *t, const TValue *key, TValue *value) { | 665 | static void luaH_newkey (lua_State *L, Table *t, const TValue *key, |
| 666 | TValue *value) { | ||
| 666 | Node *mp; | 667 | Node *mp; |
| 667 | TValue aux; | 668 | TValue aux; |
| 668 | if (l_unlikely(ttisnil(key))) | 669 | if (l_unlikely(ttisnil(key))) |
| @@ -41,8 +41,6 @@ LUAI_FUNC void luaH_setint (lua_State *L, Table *t, lua_Integer key, | |||
| 41 | LUAI_FUNC const TValue *luaH_getshortstr (Table *t, TString *key); | 41 | LUAI_FUNC const TValue *luaH_getshortstr (Table *t, TString *key); |
| 42 | LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key); | 42 | LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key); |
| 43 | LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key); | 43 | LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key); |
| 44 | LUAI_FUNC void luaH_newkey (lua_State *L, Table *t, const TValue *key, | ||
| 45 | TValue *value); | ||
| 46 | LUAI_FUNC void luaH_set (lua_State *L, Table *t, const TValue *key, | 44 | LUAI_FUNC void luaH_set (lua_State *L, Table *t, const TValue *key, |
| 47 | TValue *value); | 45 | TValue *value); |
| 48 | LUAI_FUNC void luaH_finishset (lua_State *L, Table *t, const TValue *key, | 46 | LUAI_FUNC void luaH_finishset (lua_State *L, Table *t, const TValue *key, |
| @@ -1253,7 +1253,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) { | |||
| 1253 | const TValue *slot; | 1253 | const TValue *slot; |
| 1254 | TValue *upval = cl->upvals[GETARG_B(i)]->v.p; | 1254 | TValue *upval = cl->upvals[GETARG_B(i)]->v.p; |
| 1255 | TValue *rc = KC(i); | 1255 | TValue *rc = KC(i); |
| 1256 | TString *key = tsvalue(rc); /* key must be a string */ | 1256 | TString *key = tsvalue(rc); /* key must be a short string */ |
| 1257 | if (luaV_fastget(L, upval, key, slot, luaH_getshortstr)) { | 1257 | if (luaV_fastget(L, upval, key, slot, luaH_getshortstr)) { |
| 1258 | setobj2s(L, ra, slot); | 1258 | setobj2s(L, ra, slot); |
| 1259 | } | 1259 | } |
| @@ -1296,7 +1296,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) { | |||
| 1296 | const TValue *slot; | 1296 | const TValue *slot; |
| 1297 | TValue *rb = vRB(i); | 1297 | TValue *rb = vRB(i); |
| 1298 | TValue *rc = KC(i); | 1298 | TValue *rc = KC(i); |
| 1299 | TString *key = tsvalue(rc); /* key must be a string */ | 1299 | TString *key = tsvalue(rc); /* key must be a short string */ |
| 1300 | if (luaV_fastget(L, rb, key, slot, luaH_getshortstr)) { | 1300 | if (luaV_fastget(L, rb, key, slot, luaH_getshortstr)) { |
| 1301 | setobj2s(L, ra, slot); | 1301 | setobj2s(L, ra, slot); |
| 1302 | } | 1302 | } |
| @@ -1309,7 +1309,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) { | |||
| 1309 | TValue *upval = cl->upvals[GETARG_A(i)]->v.p; | 1309 | TValue *upval = cl->upvals[GETARG_A(i)]->v.p; |
| 1310 | TValue *rb = KB(i); | 1310 | TValue *rb = KB(i); |
| 1311 | TValue *rc = RKC(i); | 1311 | TValue *rc = RKC(i); |
| 1312 | TString *key = tsvalue(rb); /* key must be a string */ | 1312 | TString *key = tsvalue(rb); /* key must be a short string */ |
| 1313 | if (luaV_fastget(L, upval, key, slot, luaH_getshortstr)) { | 1313 | if (luaV_fastget(L, upval, key, slot, luaH_getshortstr)) { |
| 1314 | luaV_finishfastset(L, upval, slot, rc); | 1314 | luaV_finishfastset(L, upval, slot, rc); |
| 1315 | } | 1315 | } |
| @@ -1352,7 +1352,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) { | |||
| 1352 | const TValue *slot; | 1352 | const TValue *slot; |
| 1353 | TValue *rb = KB(i); | 1353 | TValue *rb = KB(i); |
| 1354 | TValue *rc = RKC(i); | 1354 | TValue *rc = RKC(i); |
| 1355 | TString *key = tsvalue(rb); /* key must be a string */ | 1355 | TString *key = tsvalue(rb); /* key must be a short string */ |
| 1356 | if (luaV_fastget(L, s2v(ra), key, slot, luaH_getshortstr)) { | 1356 | if (luaV_fastget(L, s2v(ra), key, slot, luaH_getshortstr)) { |
| 1357 | luaV_finishfastset(L, s2v(ra), slot, rc); | 1357 | luaV_finishfastset(L, s2v(ra), slot, rc); |
| 1358 | } | 1358 | } |
