new definitions for closure structures

This commit is contained in:
Roberto Ierusalimschy
2001-10-02 13:45:03 -03:00
parent 6f936bc793
commit 15462edb0f
11 changed files with 137 additions and 156 deletions

30
lvm.c
View File

@@ -64,8 +64,8 @@ int luaV_tostring (lua_State *L, TObject *obj) {
static void traceexec (lua_State *L, lua_Hook linehook) {
CallInfo *ci = L->ci;
int *lineinfo = ci_func(ci)->u.l.p->lineinfo;
int pc = (*ci->pc - ci_func(ci)->u.l.p->code) - 1;
int *lineinfo = ci_func(ci)->l.p->lineinfo;
int pc = (*ci->pc - ci_func(ci)->l.p->code) - 1;
int newline;
if (pc == 0) { /* may be first time? */
ci->line = 1;
@@ -351,8 +351,8 @@ static void adjust_varargs (lua_State *L, StkId base, int nfixargs) {
** Executes the given Lua function. Parameters are between [base,top).
** Returns n such that the the results are between [n,top).
*/
StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) {
const Proto *const tf = cl->u.l.p;
StkId luaV_execute (lua_State *L, const LClosure *cl, StkId base) {
const Proto *const tf = cl->p;
const Instruction *pc;
lua_Hook linehook;
if (tf->is_vararg) /* varargs? */
@@ -391,8 +391,8 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) {
}
case OP_GETUPVAL: {
int b = GETARG_B(i);
lua_assert(luaF_isclosed(cl, b) || cl->u.l.upvals[b] < base);
setobj(ra, cl->u.l.upvals[b]);
lua_assert(cl->upvals[b].heap || cl->upvals[b].val < base);
setobj(ra, cl->upvals[b].val);
break;
}
case OP_GETGLOBAL: {
@@ -411,8 +411,8 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) {
}
case OP_SETUPVAL: {
int b = GETARG_B(i);
lua_assert(luaF_isclosed(cl, b) || cl->u.l.upvals[b] < base);
setobj(cl->u.l.upvals[b], ra);
lua_assert(cl->upvals[b].heap || cl->upvals[b].val < base);
setobj(cl->upvals[b].val, ra);
break;
}
case OP_SETTABLE: {
@@ -644,18 +644,14 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) {
p = tf->p[GETARG_Bc(i)];
nup = p->nupvalues;
ncl = luaF_newLclosure(L, nup);
ncl->u.l.p = p;
ncl->l.p = p;
for (j=0; j<nup; j++, pc++) {
if (GET_OPCODE(*pc) == OP_GETUPVAL) {
int n = GETARG_B(*pc);
if (!luaF_isclosed(cl, n))
luaF_openentry(ncl, j);
ncl->u.l.upvals[j] = cl->u.l.upvals[n];
}
if (GET_OPCODE(*pc) == OP_GETUPVAL)
ncl->l.upvals[j] = cl->upvals[GETARG_B(*pc)];
else {
lua_assert(GET_OPCODE(*pc) == OP_MOVE);
luaF_openentry(ncl, j);
ncl->u.l.upvals[j] = base + GETARG_B(*pc);
ncl->l.upvals[j].heap = NULL;
ncl->l.upvals[j].val = base + GETARG_B(*pc);
}
}
luaF_LConlist(L, ncl);