Skip to content

Commit 63d546b

Browse files
committed
update lua55
1 parent 80db34f commit 63d546b

File tree

14 files changed

+115
-29
lines changed

14 files changed

+115
-29
lines changed

3rd/lua55/lbaselib.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -279,21 +279,22 @@ static int luaB_next (lua_State *L) {
279279

280280
static int pairscont (lua_State *L, int status, lua_KContext k) {
281281
(void)L; (void)status; (void)k; /* unused */
282-
return 3;
282+
return 4; /* __pairs did all the work, just return its results */
283283
}
284284

285285
static int luaB_pairs (lua_State *L) {
286286
luaL_checkany(L, 1);
287287
if (luaL_getmetafield(L, 1, "__pairs") == LUA_TNIL) { /* no metamethod? */
288-
lua_pushcfunction(L, luaB_next); /* will return generator, */
289-
lua_pushvalue(L, 1); /* state, */
290-
lua_pushnil(L); /* and initial value */
288+
lua_pushcfunction(L, luaB_next); /* will return generator and */
289+
lua_pushvalue(L, 1); /* state */
290+
lua_pushnil(L); /* initial value */
291+
lua_pushnil(L); /* to-be-closed object */
291292
}
292293
else {
293294
lua_pushvalue(L, 1); /* argument 'self' to metamethod */
294-
lua_callk(L, 1, 3, 0, pairscont); /* get 3 values from metamethod */
295+
lua_callk(L, 1, 4, 0, pairscont); /* get 4 values from metamethod */
295296
}
296-
return 3;
297+
return 4;
297298
}
298299

299300

3rd/lua55/lcode.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ l_noret luaK_semerror (LexState *ls, const char *fmt, ...) {
4545
va_list argp;
4646
pushvfstring(ls->L, argp, fmt, msg);
4747
ls->t.token = 0; /* remove "near <token>" from final message */
48+
ls->linenumber = ls->lastline; /* back to line of last used token */
4849
luaX_syntaxerror(ls, msg);
4950
}
5051

@@ -705,6 +706,22 @@ static void luaK_float (FuncState *fs, int reg, lua_Number f) {
705706
}
706707

707708

709+
/*
710+
** Get the value of 'var' in a register and generate an opcode to check
711+
** whether that register is nil. 'k' is the index of the variable name
712+
** in the list of constants. If its value cannot be encoded in Bx, a 0
713+
** will use '?' for the name.
714+
*/
715+
void luaK_codecheckglobal (FuncState *fs, expdesc *var, int k, int line) {
716+
luaK_exp2anyreg(fs, var);
717+
luaK_fixline(fs, line);
718+
k = (k >= MAXARG_Bx) ? 0 : k + 1;
719+
luaK_codeABx(fs, OP_ERRNNIL, var->u.info, k);
720+
luaK_fixline(fs, line);
721+
freeexp(fs, var);
722+
}
723+
724+
708725
/*
709726
** Convert a constant in 'v' into an expression description 'e'
710727
*/
@@ -1109,6 +1126,10 @@ void luaK_storevar (FuncState *fs, expdesc *var, expdesc *ex) {
11091126
codeABRK(fs, OP_SETFIELD, var->u.ind.t, var->u.ind.idx, ex);
11101127
break;
11111128
}
1129+
case VVARGIND: {
1130+
fs->f->flag |= PF_VATAB; /* function will need a vararg table */
1131+
/* now, assignment is to a regular table */
1132+
} /* FALLTHROUGH */
11121133
case VINDEXED: {
11131134
codeABRK(fs, OP_SETTABLE, var->u.ind.t, var->u.ind.idx, ex);
11141135
break;
@@ -1242,7 +1263,7 @@ static void codenot (FuncState *fs, expdesc *e) {
12421263
** Check whether expression 'e' is a short literal string
12431264
*/
12441265
static int isKstr (FuncState *fs, expdesc *e) {
1245-
return (e->k == VK && !hasjumps(e) && e->u.info <= MAXARG_B &&
1266+
return (e->k == VK && !hasjumps(e) && e->u.info <= MAXINDEXRK &&
12461267
ttisshrstring(&fs->f->k[e->u.info]));
12471268
}
12481269

3rd/lua55/lcode.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ LUAI_FUNC int luaK_codevABCk (FuncState *fs, OpCode o, int A, int B, int C,
6868
LUAI_FUNC int luaK_exp2const (FuncState *fs, const expdesc *e, TValue *v);
6969
LUAI_FUNC void luaK_fixline (FuncState *fs, int line);
7070
LUAI_FUNC void luaK_nil (FuncState *fs, int from, int n);
71+
LUAI_FUNC void luaK_codecheckglobal (FuncState *fs, expdesc *var, int k,
72+
int line);
7173
LUAI_FUNC void luaK_reserveregs (FuncState *fs, int n);
7274
LUAI_FUNC void luaK_checkstack (FuncState *fs, int n);
7375
LUAI_FUNC void luaK_int (FuncState *fs, int reg, lua_Integer n);

3rd/lua55/ldebug.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,14 @@ l_noret luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2) {
814814
}
815815

816816

817+
l_noret luaG_errnnil (lua_State *L, LClosure *cl, int k) {
818+
const char *globalname = "?"; /* default name if k == 0 */
819+
if (k > 0)
820+
kname(cl->p, k - 1, &globalname);
821+
luaG_runerror(L, "global '%s' already defined", globalname);
822+
}
823+
824+
817825
/* add src:line information to 'msg' */
818826
const char *luaG_addinfo (lua_State *L, const char *msg, TString *src,
819827
int line) {

3rd/lua55/ldebug.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ LUAI_FUNC l_noret luaG_tointerror (lua_State *L, const TValue *p1,
5353
const TValue *p2);
5454
LUAI_FUNC l_noret luaG_ordererror (lua_State *L, const TValue *p1,
5555
const TValue *p2);
56+
LUAI_FUNC l_noret luaG_errnnil (lua_State *L, LClosure *cl, int k);
5657
LUAI_FUNC l_noret luaG_runerror (lua_State *L, const char *fmt, ...);
5758
LUAI_FUNC const char *luaG_addinfo (lua_State *L, const char *msg,
5859
TString *src, int line);

3rd/lua55/lgc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -594,10 +594,10 @@ static void traversestrongtable (global_State *g, Table *h) {
594594
*/
595595
static int getmode (global_State *g, Table *h) {
596596
const TValue *mode = gfasttm(g, h->metatable, TM_MODE);
597-
if (mode == NULL || !ttisshrstring(mode))
598-
return 0; /* ignore non-(short)string modes */
597+
if (mode == NULL || !ttisstring(mode))
598+
return 0; /* ignore non-string modes */
599599
else {
600-
const char *smode = getshrstr(tsvalue(mode));
600+
const char *smode = getstr(tsvalue(mode));
601601
const char *weakkey = strchr(smode, 'k');
602602
const char *weakvalue = strchr(smode, 'v');
603603
return ((weakkey != NULL) << 1) | (weakvalue != NULL);

3rd/lua55/ljumptab.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ static const void *const disptab[NUM_OPCODES] = {
107107
&&L_OP_CLOSURE,
108108
&&L_OP_VARARG,
109109
&&L_OP_GETVARG,
110+
&&L_OP_ERRNNIL,
110111
&&L_OP_VARARGPREP,
111112
&&L_OP_EXTRAARG
112113

3rd/lua55/lopcodes.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = {
103103
,opmode(0, 0, 0, 0, 1, iABx) /* OP_CLOSURE */
104104
,opmode(0, 1, 0, 0, 1, iABC) /* OP_VARARG */
105105
,opmode(0, 0, 0, 0, 1, iABC) /* OP_GETVARG */
106+
,opmode(0, 0, 0, 0, 0, iABx) /* OP_ERRNNIL */
106107
,opmode(0, 0, 1, 0, 1, iABC) /* OP_VARARGPREP */
107108
,opmode(0, 0, 0, 0, 0, iAx) /* OP_EXTRAARG */
108109
};

3rd/lua55/lopcodes.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,8 @@ OP_VARARG,/* A C R[A], R[A+1], ..., R[A+C-2] = vararg */
340340

341341
OP_GETVARG, /* A B C R[A] := R[B][R[C]], R[B] is vararg parameter */
342342

343+
OP_ERRNNIL,/* A Bx raise error if R[A] ~= nil (K[Bx] is global name)*/
344+
343345
OP_VARARGPREP,/* (adjust vararg parameters) */
344346

345347
OP_EXTRAARG/* Ax extra (larger) argument for previous opcode */

3rd/lua55/lopnames.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ static const char *const opnames[] = {
9595
"CLOSURE",
9696
"VARARG",
9797
"GETVARG",
98+
"ERRNNIL",
9899
"VARARGPREP",
99100
"EXTRAARG",
100101
NULL

0 commit comments

Comments
 (0)