mirror of https://github.com/rusefi/lua.git
details
This commit is contained in:
parent
39a8082f50
commit
70751dd27c
37
lparser.c
37
lparser.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lparser.c,v 2.9 2004/12/03 20:44:19 roberto Exp roberto $
|
** $Id: lparser.c,v 2.10 2004/12/03 20:50:25 roberto Exp roberto $
|
||||||
** Lua Parser
|
** Lua Parser
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -109,10 +109,15 @@ static int testnext (LexState *ls, int c) {
|
||||||
|
|
||||||
|
|
||||||
static void check (LexState *ls, int c) {
|
static void check (LexState *ls, int c) {
|
||||||
if (!testnext(ls, c))
|
if (ls->t.token != c)
|
||||||
error_expected(ls, c);
|
error_expected(ls, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void checknext (LexState *ls, int c) {
|
||||||
|
check(ls, c);
|
||||||
|
next(ls);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#define check_condition(ls,c,msg) { if (!(c)) luaX_syntaxerror(ls, msg); }
|
#define check_condition(ls,c,msg) { if (!(c)) luaX_syntaxerror(ls, msg); }
|
||||||
|
|
||||||
|
@ -133,7 +138,7 @@ static void check_match (LexState *ls, int what, int who, int where) {
|
||||||
|
|
||||||
static TString *str_checkname (LexState *ls) {
|
static TString *str_checkname (LexState *ls) {
|
||||||
TString *ts;
|
TString *ts;
|
||||||
if (ls->t.token != TK_NAME) error_expected(ls, TK_NAME);
|
check(ls, TK_NAME);
|
||||||
ts = ls->t.seminfo.ts;
|
ts = ls->t.seminfo.ts;
|
||||||
next(ls);
|
next(ls);
|
||||||
return ts;
|
return ts;
|
||||||
|
@ -396,7 +401,7 @@ Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) {
|
||||||
funcstate.f->is_vararg = NEWSTYLEVARARG;
|
funcstate.f->is_vararg = NEWSTYLEVARARG;
|
||||||
next(&lexstate); /* read first token */
|
next(&lexstate); /* read first token */
|
||||||
chunk(&lexstate);
|
chunk(&lexstate);
|
||||||
check_condition(&lexstate, (lexstate.t.token == TK_EOS), "<eof> expected");
|
check(&lexstate, TK_EOS);
|
||||||
close_func(&lexstate);
|
close_func(&lexstate);
|
||||||
lua_assert(funcstate.prev == NULL);
|
lua_assert(funcstate.prev == NULL);
|
||||||
lua_assert(funcstate.f->nups == 0);
|
lua_assert(funcstate.f->nups == 0);
|
||||||
|
@ -428,7 +433,7 @@ static void yindex (LexState *ls, expdesc *v) {
|
||||||
next(ls); /* skip the '[' */
|
next(ls); /* skip the '[' */
|
||||||
expr(ls, v);
|
expr(ls, v);
|
||||||
luaK_exp2val(ls->fs, v);
|
luaK_exp2val(ls->fs, v);
|
||||||
check(ls, ']');
|
checknext(ls, ']');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -460,7 +465,7 @@ static void recfield (LexState *ls, struct ConsControl *cc) {
|
||||||
}
|
}
|
||||||
else /* ls->t.token == '[' */
|
else /* ls->t.token == '[' */
|
||||||
yindex(ls, &key);
|
yindex(ls, &key);
|
||||||
check(ls, '=');
|
checknext(ls, '=');
|
||||||
luaK_exp2RK(fs, &key);
|
luaK_exp2RK(fs, &key);
|
||||||
expr(ls, &val);
|
expr(ls, &val);
|
||||||
luaK_codeABC(fs, OP_SETTABLE, cc->t->info, luaK_exp2RK(fs, &key),
|
luaK_codeABC(fs, OP_SETTABLE, cc->t->info, luaK_exp2RK(fs, &key),
|
||||||
|
@ -514,7 +519,7 @@ static void constructor (LexState *ls, expdesc *t) {
|
||||||
init_exp(t, VRELOCABLE, pc);
|
init_exp(t, VRELOCABLE, pc);
|
||||||
init_exp(&cc.v, VVOID, 0); /* no value (yet) */
|
init_exp(&cc.v, VVOID, 0); /* no value (yet) */
|
||||||
luaK_exp2nextreg(ls->fs, t); /* fix it at stack top (for gc) */
|
luaK_exp2nextreg(ls->fs, t); /* fix it at stack top (for gc) */
|
||||||
check(ls, '{');
|
checknext(ls, '{');
|
||||||
do {
|
do {
|
||||||
lua_assert(cc.v.k == VVOID || cc.tostore > 0);
|
lua_assert(cc.v.k == VVOID || cc.tostore > 0);
|
||||||
testnext(ls, ';'); /* compatibility only */
|
testnext(ls, ';'); /* compatibility only */
|
||||||
|
@ -584,13 +589,13 @@ static void body (LexState *ls, expdesc *e, int needself, int line) {
|
||||||
FuncState new_fs;
|
FuncState new_fs;
|
||||||
open_func(ls, &new_fs);
|
open_func(ls, &new_fs);
|
||||||
new_fs.f->lineDefined = line;
|
new_fs.f->lineDefined = line;
|
||||||
check(ls, '(');
|
checknext(ls, '(');
|
||||||
if (needself) {
|
if (needself) {
|
||||||
new_localvarliteral(ls, "self", 0);
|
new_localvarliteral(ls, "self", 0);
|
||||||
adjustlocalvars(ls, 1);
|
adjustlocalvars(ls, 1);
|
||||||
}
|
}
|
||||||
parlist(ls);
|
parlist(ls);
|
||||||
check(ls, ')');
|
checknext(ls, ')');
|
||||||
chunk(ls);
|
chunk(ls);
|
||||||
check_match(ls, TK_END, TK_FUNCTION, line);
|
check_match(ls, TK_END, TK_FUNCTION, line);
|
||||||
close_func(ls);
|
close_func(ls);
|
||||||
|
@ -944,7 +949,7 @@ static void assignment (LexState *ls, struct LHS_assign *lh, int nvars) {
|
||||||
}
|
}
|
||||||
else { /* assignment -> `=' explist1 */
|
else { /* assignment -> `=' explist1 */
|
||||||
int nexps;
|
int nexps;
|
||||||
check(ls, '=');
|
checknext(ls, '=');
|
||||||
nexps = explist1(ls, &e);
|
nexps = explist1(ls, &e);
|
||||||
if (nexps != nvars) {
|
if (nexps != nvars) {
|
||||||
adjust_assign(ls, nvars, nexps, &e);
|
adjust_assign(ls, nvars, nexps, &e);
|
||||||
|
@ -1011,7 +1016,7 @@ static void whilestat (LexState *ls, int line) {
|
||||||
codeexp[i] = fs->f->code[expinit + i];
|
codeexp[i] = fs->f->code[expinit + i];
|
||||||
fs->pc = expinit; /* remove `exp' code */
|
fs->pc = expinit; /* remove `exp' code */
|
||||||
enterblock(fs, &bl, 1);
|
enterblock(fs, &bl, 1);
|
||||||
check(ls, TK_DO);
|
checknext(ls, TK_DO);
|
||||||
blockinit = luaK_getlabel(fs);
|
blockinit = luaK_getlabel(fs);
|
||||||
block(ls);
|
block(ls);
|
||||||
luaK_patchtohere(fs, whileinit); /* initial jump jumps to here */
|
luaK_patchtohere(fs, whileinit); /* initial jump jumps to here */
|
||||||
|
@ -1059,7 +1064,7 @@ static void forbody (LexState *ls, int base, int line, int nvars, int isnum) {
|
||||||
FuncState *fs = ls->fs;
|
FuncState *fs = ls->fs;
|
||||||
int prep, endfor;
|
int prep, endfor;
|
||||||
adjustlocalvars(ls, 3); /* control variables */
|
adjustlocalvars(ls, 3); /* control variables */
|
||||||
check(ls, TK_DO);
|
checknext(ls, TK_DO);
|
||||||
prep = luaK_codeAsBx(fs, (isnum ? OP_FORPREP : OP_TFORPREP), base, NO_JUMP);
|
prep = luaK_codeAsBx(fs, (isnum ? OP_FORPREP : OP_TFORPREP), base, NO_JUMP);
|
||||||
enterblock(fs, &bl, 0); /* scope for declared variables */
|
enterblock(fs, &bl, 0); /* scope for declared variables */
|
||||||
adjustlocalvars(ls, nvars);
|
adjustlocalvars(ls, nvars);
|
||||||
|
@ -1082,9 +1087,9 @@ static void fornum (LexState *ls, TString *varname, int line) {
|
||||||
new_localvarliteral(ls, "(for limit)", 1);
|
new_localvarliteral(ls, "(for limit)", 1);
|
||||||
new_localvarliteral(ls, "(for step)", 2);
|
new_localvarliteral(ls, "(for step)", 2);
|
||||||
new_localvar(ls, varname, 3);
|
new_localvar(ls, varname, 3);
|
||||||
check(ls, '=');
|
checknext(ls, '=');
|
||||||
exp1(ls); /* initial value */
|
exp1(ls); /* initial value */
|
||||||
check(ls, ',');
|
checknext(ls, ',');
|
||||||
exp1(ls); /* limit */
|
exp1(ls); /* limit */
|
||||||
if (testnext(ls, ','))
|
if (testnext(ls, ','))
|
||||||
exp1(ls); /* optional step */
|
exp1(ls); /* optional step */
|
||||||
|
@ -1111,7 +1116,7 @@ static void forlist (LexState *ls, TString *indexname) {
|
||||||
new_localvar(ls, indexname, nvars++);
|
new_localvar(ls, indexname, nvars++);
|
||||||
while (testnext(ls, ','))
|
while (testnext(ls, ','))
|
||||||
new_localvar(ls, str_checkname(ls), nvars++);
|
new_localvar(ls, str_checkname(ls), nvars++);
|
||||||
check(ls, TK_IN);
|
checknext(ls, TK_IN);
|
||||||
line = ls->linenumber;
|
line = ls->linenumber;
|
||||||
adjust_assign(ls, 3, explist1(ls, &e), &e);
|
adjust_assign(ls, 3, explist1(ls, &e), &e);
|
||||||
luaK_checkstack(fs, 3); /* extra space to call generator */
|
luaK_checkstack(fs, 3); /* extra space to call generator */
|
||||||
|
@ -1142,7 +1147,7 @@ static int test_then_block (LexState *ls) {
|
||||||
int flist;
|
int flist;
|
||||||
next(ls); /* skip IF or ELSEIF */
|
next(ls); /* skip IF or ELSEIF */
|
||||||
flist = cond(ls);
|
flist = cond(ls);
|
||||||
check(ls, TK_THEN);
|
checknext(ls, TK_THEN);
|
||||||
block(ls); /* `then' part */
|
block(ls); /* `then' part */
|
||||||
return flist;
|
return flist;
|
||||||
}
|
}
|
||||||
|
|
30
ltablib.c
30
ltablib.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: ltablib.c,v 1.25 2004/05/10 18:06:14 roberto Exp roberto $
|
** $Id: ltablib.c,v 1.26 2004/06/15 13:37:21 roberto Exp roberto $
|
||||||
** Library for Table Manipulation
|
** Library for Table Manipulation
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -19,7 +19,7 @@
|
||||||
#define aux_getn(L,n) (luaL_checktype(L, n, LUA_TTABLE), luaL_getn(L, n))
|
#define aux_getn(L,n) (luaL_checktype(L, n, LUA_TTABLE), luaL_getn(L, n))
|
||||||
|
|
||||||
|
|
||||||
static int luaB_foreachi (lua_State *L) {
|
static int foreachi (lua_State *L) {
|
||||||
int i;
|
int i;
|
||||||
int n = aux_getn(L, 1);
|
int n = aux_getn(L, 1);
|
||||||
luaL_checktype(L, 2, LUA_TFUNCTION);
|
luaL_checktype(L, 2, LUA_TFUNCTION);
|
||||||
|
@ -36,7 +36,7 @@ static int luaB_foreachi (lua_State *L) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int luaB_foreach (lua_State *L) {
|
static int foreach (lua_State *L) {
|
||||||
luaL_checktype(L, 1, LUA_TTABLE);
|
luaL_checktype(L, 1, LUA_TTABLE);
|
||||||
luaL_checktype(L, 2, LUA_TFUNCTION);
|
luaL_checktype(L, 2, LUA_TFUNCTION);
|
||||||
lua_pushnil(L); /* first key */
|
lua_pushnil(L); /* first key */
|
||||||
|
@ -54,13 +54,13 @@ static int luaB_foreach (lua_State *L) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int luaB_getn (lua_State *L) {
|
static int getn (lua_State *L) {
|
||||||
lua_pushinteger(L, aux_getn(L, 1));
|
lua_pushinteger(L, aux_getn(L, 1));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int luaB_setn (lua_State *L) {
|
static int setn (lua_State *L) {
|
||||||
luaL_checktype(L, 1, LUA_TTABLE);
|
luaL_checktype(L, 1, LUA_TTABLE);
|
||||||
luaL_setn(L, 1, luaL_checkint(L, 2));
|
luaL_setn(L, 1, luaL_checkint(L, 2));
|
||||||
lua_pushvalue(L, 1);
|
lua_pushvalue(L, 1);
|
||||||
|
@ -68,7 +68,7 @@ static int luaB_setn (lua_State *L) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int luaB_tinsert (lua_State *L) {
|
static int tinsert (lua_State *L) {
|
||||||
int v = lua_gettop(L); /* number of arguments */
|
int v = lua_gettop(L); /* number of arguments */
|
||||||
int e = aux_getn(L, 1) + LUA_FIRSTINDEX; /* first empty element */
|
int e = aux_getn(L, 1) + LUA_FIRSTINDEX; /* first empty element */
|
||||||
int pos; /* where to insert new element */
|
int pos; /* where to insert new element */
|
||||||
|
@ -90,7 +90,7 @@ static int luaB_tinsert (lua_State *L) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int luaB_tremove (lua_State *L) {
|
static int tremove (lua_State *L) {
|
||||||
int e = aux_getn(L, 1) + LUA_FIRSTINDEX - 1;
|
int e = aux_getn(L, 1) + LUA_FIRSTINDEX - 1;
|
||||||
int pos = luaL_optint(L, 2, e);
|
int pos = luaL_optint(L, 2, e);
|
||||||
if (e < LUA_FIRSTINDEX) return 0; /* table is `empty' */
|
if (e < LUA_FIRSTINDEX) return 0; /* table is `empty' */
|
||||||
|
@ -220,7 +220,7 @@ static void auxsort (lua_State *L, int l, int u) {
|
||||||
} /* repeat the routine for the larger one */
|
} /* repeat the routine for the larger one */
|
||||||
}
|
}
|
||||||
|
|
||||||
static int luaB_sort (lua_State *L) {
|
static int sort (lua_State *L) {
|
||||||
int n = aux_getn(L, 1);
|
int n = aux_getn(L, 1);
|
||||||
luaL_checkstack(L, 40, ""); /* assume array is smaller than 2^40 */
|
luaL_checkstack(L, 40, ""); /* assume array is smaller than 2^40 */
|
||||||
if (!lua_isnoneornil(L, 2)) /* is there a 2nd argument? */
|
if (!lua_isnoneornil(L, 2)) /* is there a 2nd argument? */
|
||||||
|
@ -235,13 +235,13 @@ static int luaB_sort (lua_State *L) {
|
||||||
|
|
||||||
static const luaL_reg tab_funcs[] = {
|
static const luaL_reg tab_funcs[] = {
|
||||||
{"concat", str_concat},
|
{"concat", str_concat},
|
||||||
{"foreach", luaB_foreach},
|
{"foreach", foreach},
|
||||||
{"foreachi", luaB_foreachi},
|
{"foreachi", foreachi},
|
||||||
{"getn", luaB_getn},
|
{"getn", getn},
|
||||||
{"setn", luaB_setn},
|
{"setn", setn},
|
||||||
{"sort", luaB_sort},
|
{"sort", sort},
|
||||||
{"insert", luaB_tinsert},
|
{"insert", tinsert},
|
||||||
{"remove", luaB_tremove},
|
{"remove", tremove},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue