mirror of
https://github.com/lua/lua
synced 2025-01-11 11:59:18 +03:00
code check for upvalues
This commit is contained in:
parent
c1db0b2bf1
commit
888f91fa24
7
ldebug.c
7
ldebug.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: ldebug.c,v 1.64 2001/02/16 17:58:27 roberto Exp roberto $
|
||||
** $Id: ldebug.c,v 1.65 2001/02/20 18:15:33 roberto Exp roberto $
|
||||
** Debug Interface
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -433,7 +433,7 @@ static Instruction luaG_symbexec (lua_State *L, const Proto *pt,
|
||||
break;
|
||||
}
|
||||
case OP_PUSHUPVALUE: {
|
||||
/* ?? */
|
||||
check(arg1 < pt->nupvalues);
|
||||
break;
|
||||
}
|
||||
case OP_GETLOCAL:
|
||||
@ -462,7 +462,8 @@ static Instruction luaG_symbexec (lua_State *L, const Proto *pt,
|
||||
break;
|
||||
}
|
||||
case OP_CLOSURE: {
|
||||
/* ?? */
|
||||
check(arg1 < pt->sizekproto);
|
||||
check(arg2 == pt->kproto[arg1]->nupvalues);
|
||||
pop = arg2;
|
||||
break;
|
||||
}
|
||||
|
3
lfunc.c
3
lfunc.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lfunc.c,v 1.39 2001/02/01 17:40:48 roberto Exp roberto $
|
||||
** $Id: lfunc.c,v 1.40 2001/02/09 20:22:29 roberto Exp roberto $
|
||||
** Auxiliary functions to manipulate prototypes and closures
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -37,6 +37,7 @@ Proto *luaF_newproto (lua_State *L) {
|
||||
f->sizekproto = 0;
|
||||
f->code = NULL;
|
||||
f->sizecode = 0;
|
||||
f->nupvalues = 0;
|
||||
f->numparams = 0;
|
||||
f->is_vararg = 0;
|
||||
f->maxstacksize = 0;
|
||||
|
6
lgc.c
6
lgc.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lgc.c,v 1.88 2001/02/07 18:13:49 roberto Exp roberto $
|
||||
** $Id: lgc.c,v 1.89 2001/02/20 18:15:33 roberto Exp roberto $
|
||||
** Garbage Collector
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -62,8 +62,10 @@ static void protomark (Proto *f) {
|
||||
|
||||
static void markclosure (GCState *st, Closure *cl) {
|
||||
if (!ismarked(cl)) {
|
||||
if (!cl->isC)
|
||||
if (!cl->isC) {
|
||||
lua_assert(cl->nupvalues == cl->f.l->nupvalues);
|
||||
protomark(cl->f.l);
|
||||
}
|
||||
cl->mark = st->cmark; /* chain it for later traversal */
|
||||
st->cmark = cl;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lobject.h,v 1.95 2001/02/09 20:22:29 roberto Exp roberto $
|
||||
** $Id: lobject.h,v 1.96 2001/02/20 18:15:33 roberto Exp roberto $
|
||||
** Type definitions for Lua objects
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -133,6 +133,7 @@ typedef struct Proto {
|
||||
int sizekproto; /* size of `kproto' */
|
||||
Instruction *code;
|
||||
int sizecode;
|
||||
short nupvalues;
|
||||
short numparams;
|
||||
short is_vararg;
|
||||
short maxstacksize;
|
||||
|
17
lparser.c
17
lparser.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lparser.c,v 1.134 2001/02/14 17:38:45 roberto Exp roberto $
|
||||
** $Id: lparser.c,v 1.135 2001/02/20 18:15:33 roberto Exp roberto $
|
||||
** LL(1) Parser and code generator for Lua
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -219,14 +219,14 @@ static void singlevar (LexState *ls, TString *n, expdesc *var) {
|
||||
static int indexupvalue (LexState *ls, expdesc *v) {
|
||||
FuncState *fs = ls->fs;
|
||||
int i;
|
||||
for (i=0; i<fs->nupvalues; i++) {
|
||||
for (i=0; i<fs->f->nupvalues; i++) {
|
||||
if (fs->upvalues[i].k == v->k && fs->upvalues[i].u.index == v->u.index)
|
||||
return i;
|
||||
}
|
||||
/* new one */
|
||||
luaX_checklimit(ls, fs->nupvalues+1, MAXUPVALUES, "upvalues");
|
||||
fs->upvalues[fs->nupvalues] = *v;
|
||||
return fs->nupvalues++;
|
||||
luaX_checklimit(ls, fs->f->nupvalues+1, MAXUPVALUES, "upvalues");
|
||||
fs->upvalues[fs->f->nupvalues] = *v;
|
||||
return fs->f->nupvalues++;
|
||||
}
|
||||
|
||||
|
||||
@ -297,12 +297,12 @@ static void pushclosure (LexState *ls, FuncState *func) {
|
||||
FuncState *fs = ls->fs;
|
||||
Proto *f = fs->f;
|
||||
int i;
|
||||
for (i=0; i<func->nupvalues; i++)
|
||||
for (i=0; i<func->f->nupvalues; i++)
|
||||
luaK_tostack(ls, &func->upvalues[i], 1);
|
||||
luaM_growvector(ls->L, f->kproto, fs->nkproto, f->sizekproto, Proto *,
|
||||
MAXARG_A, "constant table overflow");
|
||||
f->kproto[fs->nkproto++] = func->f;
|
||||
luaK_code2(fs, OP_CLOSURE, fs->nkproto-1, func->nupvalues);
|
||||
luaK_code2(fs, OP_CLOSURE, fs->nkproto-1, func->f->nupvalues);
|
||||
}
|
||||
|
||||
|
||||
@ -323,7 +323,6 @@ static void open_func (LexState *ls, FuncState *fs) {
|
||||
fs->nlineinfo = 0;
|
||||
fs->nlocvars = 0;
|
||||
fs->nactloc = 0;
|
||||
fs->nupvalues = 0;
|
||||
fs->lastline = 0;
|
||||
fs->bl = NULL;
|
||||
f->code = NULL;
|
||||
@ -370,7 +369,7 @@ Proto *luaY_parser (lua_State *L, ZIO *z) {
|
||||
check_condition(&lexstate, (lexstate.t.token == TK_EOS), "<eof> expected");
|
||||
close_func(&lexstate);
|
||||
lua_assert(funcstate.prev == NULL);
|
||||
lua_assert(funcstate.nupvalues == 0);
|
||||
lua_assert(funcstate.f->nupvalues == 0);
|
||||
return funcstate.f;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lparser.h,v 1.28 2000/12/26 18:46:09 roberto Exp roberto $
|
||||
** $Id: lparser.h,v 1.29 2000/12/28 12:55:41 roberto Exp roberto $
|
||||
** LL(1) Parser and code generator for Lua
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -51,7 +51,6 @@ typedef struct FuncState {
|
||||
int nlineinfo; /* number of elements in `lineinfo' */
|
||||
int nlocvars; /* number of elements in `locvars' */
|
||||
int nactloc; /* number of active local variables */
|
||||
int nupvalues; /* number of upvalues */
|
||||
int lastline; /* line where last `lineinfo' was generated */
|
||||
struct Breaklabel *bl; /* chain of breakable blocks */
|
||||
expdesc upvalues[MAXUPVALUES]; /* upvalues */
|
||||
|
Loading…
Reference in New Issue
Block a user