diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-09-28 13:32:50 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-09-28 13:32:50 -0300 |
commit | 5938212748636d21d6f4b372481ab3b6dd6c7538 (patch) | |
tree | fa5d0a28dac1ff6c087585bc684534eb1ae82298 /lvm.c | |
parent | 1829911d7c1c16cf01dfdbfc8e7a26cfa10ec797 (diff) | |
download | lua-5938212748636d21d6f4b372481ab3b6dd6c7538.tar.gz lua-5938212748636d21d6f4b372481ab3b6dd6c7538.tar.bz2 lua-5938212748636d21d6f4b372481ab3b6dd6c7538.zip |
information about upvalues (where they come from) kept in Proto structure,
instead of sequence of pseudo-opcodes after OP_CLOSURE
Diffstat (limited to 'lvm.c')
-rw-r--r-- | lvm.c | 28 |
1 files changed, 12 insertions, 16 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 2.96 2009/08/07 16:17:41 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.97 2009/09/23 20:33:05 roberto Exp roberto $ |
3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -773,22 +773,18 @@ void luaV_execute (lua_State *L) { | |||
773 | continue; | 773 | continue; |
774 | } | 774 | } |
775 | case OP_CLOSURE: { | 775 | case OP_CLOSURE: { |
776 | Proto *p; | 776 | Proto *p = cl->p->p[GETARG_Bx(i)]; /* prototype for new closure */ |
777 | Closure *ncl; | 777 | int nup = p->sizeupvalues; |
778 | int nup, j; | 778 | Closure *ncl = luaF_newLclosure(L, nup, cl->env); |
779 | p = cl->p->p[GETARG_Bx(i)]; | 779 | Upvaldesc *uv = p->upvalues; |
780 | nup = p->nups; | 780 | int j; |
781 | ncl = luaF_newLclosure(L, nup, cl->env); | ||
782 | ncl->l.p = p; | 781 | ncl->l.p = p; |
783 | setclvalue(L, ra, ncl); | 782 | setclvalue(L, ra, ncl); /* anchor new closure in stack */ |
784 | for (j=0; j<nup; j++) { | 783 | for (j = 0; j < nup; j++) { /* fill in upvalues */ |
785 | Instruction u = *ci->u.l.savedpc++; | 784 | if (uv[j].instack) /* upvalue refers to local variable? */ |
786 | if (GET_OPCODE(u) == OP_GETUPVAL) | 785 | ncl->l.upvals[j] = luaF_findupval(L, base + uv[j].idx); |
787 | ncl->l.upvals[j] = cl->upvals[GETARG_B(u)]; | 786 | else /* get upvalue from enclosing function */ |
788 | else { | 787 | ncl->l.upvals[j] = cl->upvals[uv[j].idx]; |
789 | lua_assert(GET_OPCODE(u) == OP_MOVE); | ||
790 | ncl->l.upvals[j] = luaF_findupval(L, base + GETARG_B(u)); | ||
791 | } | ||
792 | } | 788 | } |
793 | Protect(luaC_checkGC(L)); | 789 | Protect(luaC_checkGC(L)); |
794 | continue; | 790 | continue; |