aboutsummaryrefslogtreecommitdiff
path: root/lcode.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lcode.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/lcode.c b/lcode.c
index 8c04d8ab..7ca895f1 100644
--- a/lcode.c
+++ b/lcode.c
@@ -40,7 +40,10 @@ static int codesJ (FuncState *fs, OpCode o, int sj, int k);
40 40
41 41
42/* semantic error */ 42/* semantic error */
43l_noret luaK_semerror (LexState *ls, const char *msg) { 43l_noret luaK_semerror (LexState *ls, const char *fmt, ...) {
44 const char *msg;
45 va_list argp;
46 pushvfstring(ls->L, argp, fmt, msg);
44 ls->t.token = 0; /* remove "near <token>" from final message */ 47 ls->t.token = 0; /* remove "near <token>" from final message */
45 luaX_syntaxerror(ls, msg); 48 luaX_syntaxerror(ls, msg);
46} 49}
@@ -750,10 +753,11 @@ void luaK_setreturns (FuncState *fs, expdesc *e, int nresults) {
750/* 753/*
751** Convert a VKSTR to a VK 754** Convert a VKSTR to a VK
752*/ 755*/
753static void str2K (FuncState *fs, expdesc *e) { 756static int str2K (FuncState *fs, expdesc *e) {
754 lua_assert(e->k == VKSTR); 757 lua_assert(e->k == VKSTR);
755 e->u.info = stringK(fs, e->u.strval); 758 e->u.info = stringK(fs, e->u.strval);
756 e->k = VK; 759 e->k = VK;
760 return e->u.info;
757} 761}
758 762
759 763
@@ -1304,35 +1308,38 @@ void luaK_self (FuncState *fs, expdesc *e, expdesc *key) {
1304** values in registers. 1308** values in registers.
1305*/ 1309*/
1306void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) { 1310void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) {
1311 int keystr = -1;
1307 if (k->k == VKSTR) 1312 if (k->k == VKSTR)
1308 str2K(fs, k); 1313 keystr = str2K(fs, k);
1309 lua_assert(!hasjumps(t) && 1314 lua_assert(!hasjumps(t) &&
1310 (t->k == VLOCAL || t->k == VNONRELOC || t->k == VUPVAL)); 1315 (t->k == VLOCAL || t->k == VNONRELOC || t->k == VUPVAL));
1311 if (t->k == VUPVAL && !isKstr(fs, k)) /* upvalue indexed by non 'Kstr'? */ 1316 if (t->k == VUPVAL && !isKstr(fs, k)) /* upvalue indexed by non 'Kstr'? */
1312 luaK_exp2anyreg(fs, t); /* put it in a register */ 1317 luaK_exp2anyreg(fs, t); /* put it in a register */
1313 if (t->k == VUPVAL) { 1318 if (t->k == VUPVAL) {
1314 lu_byte temp = cast_byte(t->u.info); /* upvalue index */ 1319 lu_byte temp = cast_byte(t->u.info); /* upvalue index */
1315 lua_assert(isKstr(fs, k));
1316 t->u.ind.t = temp; /* (can't do a direct assignment; values overlap) */ 1320 t->u.ind.t = temp; /* (can't do a direct assignment; values overlap) */
1317 t->u.ind.idx = cast(short, k->u.info); /* literal short string */ 1321 lua_assert(isKstr(fs, k));
1322 t->u.ind.idx = cast_short(k->u.info); /* literal short string */
1318 t->k = VINDEXUP; 1323 t->k = VINDEXUP;
1319 } 1324 }
1320 else { 1325 else {
1321 /* register index of the table */ 1326 /* register index of the table */
1322 t->u.ind.t = cast_byte((t->k == VLOCAL) ? t->u.var.ridx: t->u.info); 1327 t->u.ind.t = cast_byte((t->k == VLOCAL) ? t->u.var.ridx: t->u.info);
1323 if (isKstr(fs, k)) { 1328 if (isKstr(fs, k)) {
1324 t->u.ind.idx = cast(short, k->u.info); /* literal short string */ 1329 t->u.ind.idx = cast_short(k->u.info); /* literal short string */
1325 t->k = VINDEXSTR; 1330 t->k = VINDEXSTR;
1326 } 1331 }
1327 else if (isCint(k)) { /* int. constant in proper range? */ 1332 else if (isCint(k)) { /* int. constant in proper range? */
1328 t->u.ind.idx = cast(short, k->u.ival); 1333 t->u.ind.idx = cast_short(k->u.ival);
1329 t->k = VINDEXI; 1334 t->k = VINDEXI;
1330 } 1335 }
1331 else { 1336 else {
1332 t->u.ind.idx = cast(short, luaK_exp2anyreg(fs, k)); /* register */ 1337 t->u.ind.idx = cast_short(luaK_exp2anyreg(fs, k)); /* register */
1333 t->k = VINDEXED; 1338 t->k = VINDEXED;
1334 } 1339 }
1335 } 1340 }
1341 t->u.ind.keystr = keystr; /* string index in 'k' */
1342 t->u.ind.ro = 0; /* by default, not read-only */
1336} 1343}
1337 1344
1338 1345