mirror of
https://github.com/lua/lua
synced 2025-01-11 11:59:18 +03:00
"nupvalues" is kept in Closure, not in prototype (as a preparation
for C closures...)
This commit is contained in:
parent
4be18fa889
commit
45ccb0e881
4
ldo.c
4
ldo.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: ldo.c,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $
|
||||
** $Id: ldo.c,v 1.2 1997/09/26 15:02:26 roberto Exp roberto $
|
||||
** Stack and Call structure of Lua
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -338,7 +338,7 @@ static int protectedparser (ZIO *z, char *chunkname, int bin)
|
||||
luaD_adjusttop(luaD_Cstack.base+1); /* one slot for the pseudo-function */
|
||||
luaD_stack.stack[luaD_Cstack.base].ttype = LUA_T_PROTO;
|
||||
luaD_stack.stack[luaD_Cstack.base].value.tf = tf;
|
||||
luaV_closure();
|
||||
luaV_closure(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
3
lfunc.c
3
lfunc.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lfunc.c,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $
|
||||
** $Id: lfunc.c,v 1.2 1997/09/26 16:46:20 roberto Exp roberto $
|
||||
** Lua Funcion auxiliar
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -32,7 +32,6 @@ TProtoFunc *luaF_newproto (void)
|
||||
f->fileName = NULL;
|
||||
f->consts = NULL;
|
||||
f->nconsts = 0;
|
||||
f->nupvalues = 0;
|
||||
f->locvars = NULL;
|
||||
luaO_insertlist(&luaF_root, (GCnode *)f);
|
||||
return f;
|
||||
|
4
lgc.c
4
lgc.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lgc.c,v 1.2 1997/09/26 15:02:26 roberto Exp roberto $
|
||||
** $Id: lgc.c,v 1.3 1997/09/26 16:46:20 roberto Exp roberto $
|
||||
** Garbage Collector
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -187,7 +187,7 @@ static void funcmark (Closure *f)
|
||||
if (!f->head.marked) {
|
||||
int i;
|
||||
f->head.marked = 1;
|
||||
for (i=f->consts[0].value.tf->nupvalues; i>=0; i--)
|
||||
for (i=f->nelems; i>=0; i--)
|
||||
markobject(&f->consts[i]);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lobject.h,v 1.2 1997/09/26 15:02:26 roberto Exp roberto $
|
||||
** $Id: lobject.h,v 1.3 1997/09/26 16:46:20 roberto Exp roberto $
|
||||
** Type definitions for Lua objects
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -110,7 +110,6 @@ typedef struct TProtoFunc {
|
||||
struct TObject *consts;
|
||||
int nconsts;
|
||||
struct LocVar *locvars; /* ends with line = -1 */
|
||||
int nupvalues;
|
||||
} TProtoFunc;
|
||||
|
||||
typedef struct LocVar {
|
||||
@ -138,6 +137,7 @@ typedef struct LocVar {
|
||||
*/
|
||||
typedef struct Closure {
|
||||
GCnode head;
|
||||
int nelems; /* not included the first one (always the prototype) */
|
||||
TObject consts[1]; /* at least one for prototype */
|
||||
} Closure;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lopcodes.h,v 1.7 1997/10/06 14:51:11 roberto Exp roberto $
|
||||
** $Id: lopcodes.h,v 1.8 1997/10/13 22:12:04 roberto Exp roberto $
|
||||
** Opcodes for Lua virtual machine
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -135,8 +135,9 @@ IFTUPJMPW,/* w x - (x!=nil)? PC-=w */
|
||||
IFFUPJMP,/* b x - (x==nil)? PC-=b */
|
||||
IFFUPJMPW,/* w x - (x==nil)? PC-=w */
|
||||
|
||||
CLOSURE,/* b v_1...v_n c(CNST[b]) */
|
||||
CLOSUREW,/* w v_1...v_n c(CNST[w]) */
|
||||
CLOSURE,/* b v_b...v_1 prt c(prt) */
|
||||
CLOSURE0,/* b prt c(prt) */
|
||||
CLOSURE1,/* b v_1 prt c(prt) */
|
||||
|
||||
CALLFUNC,/* b c v_c...v_1 f r_b...r_1 f(v1,...,v_c) */
|
||||
CALLFUNC0,/* b v_b...v_1 f - f(v1,...,v_b) */
|
||||
|
15
lua.stx
15
lua.stx
@ -1,6 +1,6 @@
|
||||
%{
|
||||
/*
|
||||
** $Id: lua.stx,v 1.9 1997/10/13 22:12:04 roberto Exp roberto $
|
||||
** $Id: lua.stx,v 1.10 1997/10/15 20:16:00 roberto Exp roberto $
|
||||
** Syntax analizer and code generator
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -57,6 +57,7 @@ typedef struct State {
|
||||
int stacksize; /* number of values on activation register */
|
||||
int maxstacksize; /* maximum number of values on activation register */
|
||||
int nlocalvar; /* number of active local variables */
|
||||
int nupvalues; /* number of upvalues */
|
||||
int nvars; /* number of entries in f->locvars */
|
||||
int maxcode; /* size of f->code */
|
||||
int maxvars; /* size of f->locvars (-1 if no debug information) */
|
||||
@ -347,14 +348,14 @@ static int indexupvalue (TaggedString *n)
|
||||
{
|
||||
vardesc v = singlevar(n, currState-1);
|
||||
int i;
|
||||
for (i=0; i<currState->f->nupvalues; i++) {
|
||||
for (i=0; i<currState->nupvalues; i++) {
|
||||
if (currState->upvalues[i] == v)
|
||||
return i;
|
||||
}
|
||||
/* new one */
|
||||
if (++currState->f->nupvalues > MAXUPVALUES)
|
||||
if (++currState->nupvalues > MAXUPVALUES)
|
||||
luaY_error("too many upvalues in a single function");
|
||||
currState->upvalues[i] = v; /* i = currState->f->nupvalues - 1 */
|
||||
currState->upvalues[i] = v; /* i = currState->nupvalues - 1 */
|
||||
return i;
|
||||
}
|
||||
|
||||
@ -515,13 +516,14 @@ static void codereturn (void)
|
||||
static void func_onstack (TProtoFunc *f)
|
||||
{
|
||||
int i;
|
||||
int nupvalues = (currState+1)->f->nupvalues;
|
||||
int nupvalues = (currState+1)->nupvalues;
|
||||
int c = next_constant(currState);
|
||||
ttype(&currState->f->consts[c]) = LUA_T_PROTO;
|
||||
currState->f->consts[c].value.tf = (currState+1)->f;
|
||||
code_constant(c);
|
||||
for (i=0; i<nupvalues; i++)
|
||||
lua_pushvar((currState+1)->upvalues[i]);
|
||||
code_oparg(CLOSURE, 0, c, 1-nupvalues);
|
||||
code_oparg(CLOSURE, 2, nupvalues, -nupvalues);
|
||||
}
|
||||
|
||||
|
||||
@ -531,6 +533,7 @@ static void init_state (TaggedString *filename)
|
||||
currState->stacksize = 0;
|
||||
currState->maxstacksize = 0;
|
||||
currState->nlocalvar = 0;
|
||||
currState->nupvalues = 0;
|
||||
currState->f = f;
|
||||
f->fileName = filename;
|
||||
currState->pc = 0;
|
||||
|
26
lvm.c
26
lvm.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lvm.c,v 1.8 1997/10/06 14:51:11 roberto Exp roberto $
|
||||
** $Id: lvm.c,v 1.9 1997/10/13 22:12:04 roberto Exp roberto $
|
||||
** Lua virtual machine
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -76,12 +76,11 @@ int luaV_tostring (TObject *obj)
|
||||
}
|
||||
|
||||
|
||||
void luaV_closure (void)
|
||||
void luaV_closure (int nelems)
|
||||
{
|
||||
int nelems = (luaD_stack.top-1)->value.tf->nupvalues;
|
||||
Closure *c = luaF_newclosure(nelems);
|
||||
c->consts[0] = *(luaD_stack.top-1);
|
||||
memcpy(&c->consts[1], luaD_stack.top-(nelems+1), nelems*sizeof(TObject));
|
||||
memcpy(c->consts, luaD_stack.top-(nelems+1), (nelems+1)*sizeof(TObject));
|
||||
c->nelems = nelems;
|
||||
luaD_stack.top -= nelems;
|
||||
ttype(luaD_stack.top-1) = LUA_T_FUNCTION;
|
||||
(luaD_stack.top-1)->value.cl = c;
|
||||
@ -427,7 +426,7 @@ StkId luaV_execute (Closure *cl, StkId base)
|
||||
aux = 0; goto setmap;
|
||||
|
||||
case SETMAP:
|
||||
aux = *(pc++);
|
||||
aux = *pc++;
|
||||
setmap: {
|
||||
TObject *arr = luaD_stack.top-(2*aux)-3;
|
||||
do {
|
||||
@ -447,12 +446,12 @@ StkId luaV_execute (Closure *cl, StkId base)
|
||||
break;
|
||||
|
||||
case ARGS:
|
||||
luaD_adjusttop(base + *(pc++));
|
||||
luaD_adjusttop(base+(*pc++));
|
||||
break;
|
||||
|
||||
case VARARGS:
|
||||
luaC_checkGC();
|
||||
adjust_varargs(base + *(pc++));
|
||||
adjust_varargs(base+(*pc++));
|
||||
break;
|
||||
|
||||
case CREATEARRAYW:
|
||||
@ -632,14 +631,13 @@ StkId luaV_execute (Closure *cl, StkId base)
|
||||
if (ttype(--luaD_stack.top) == LUA_T_NIL) pc -= aux;
|
||||
break;
|
||||
|
||||
case CLOSUREW:
|
||||
aux = next_word(pc); goto closure;
|
||||
|
||||
case CLOSURE:
|
||||
aux = *pc++;
|
||||
aux = *pc++; goto closure;
|
||||
|
||||
case CLOSURE0: case CLOSURE1:
|
||||
aux -= CLOSURE0;
|
||||
closure:
|
||||
*luaD_stack.top++ = consts[aux];
|
||||
luaV_closure();
|
||||
luaV_closure(aux);
|
||||
luaC_checkGC();
|
||||
break;
|
||||
|
||||
|
4
lvm.h
4
lvm.h
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lvm.h,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $
|
||||
** $Id: lvm.h,v 1.2 1997/09/26 15:02:26 roberto Exp roberto $
|
||||
** Lua virtual machine
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -24,6 +24,6 @@ void luaV_settable (TObject *t, int mode);
|
||||
void luaV_getglobal (TaggedString *ts);
|
||||
void luaV_setglobal (TaggedString *ts);
|
||||
StkId luaV_execute (Closure *func, StkId base);
|
||||
void luaV_closure (void);
|
||||
void luaV_closure (int nelems);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user