aboutsummaryrefslogtreecommitdiff
path: root/lvm.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2010-03-12 16:14:06 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2010-03-12 16:14:06 -0300
commit25c557ec6367870c127e879cce8ed8fa21f34398 (patch)
tree37d322402a8163145a0f3a5728f98115402f352f /lvm.c
parentf292760f12022a83cf01e788482a264aeeb3c276 (diff)
downloadlua-25c557ec6367870c127e879cce8ed8fa21f34398.tar.gz
lua-25c557ec6367870c127e879cce8ed8fa21f34398.tar.bz2
lua-25c557ec6367870c127e879cce8ed8fa21f34398.zip
first version of _ENV; no more global variables
Diffstat (limited to 'lvm.c')
-rw-r--r--lvm.c34
1 files changed, 3 insertions, 31 deletions
diff --git a/lvm.c b/lvm.c
index 26ad6dc4..3c0a8276 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 2.104 2010/02/26 20:40:29 roberto Exp roberto $ 2** $Id: lvm.c,v 2.105 2010/02/27 21:16:24 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*/
@@ -355,14 +355,10 @@ void luaV_finishOp (lua_State *L) {
355 StkId base = ci->u.l.base; 355 StkId base = ci->u.l.base;
356 Instruction inst = *(ci->u.l.savedpc - 1); /* interrupted instruction */ 356 Instruction inst = *(ci->u.l.savedpc - 1); /* interrupted instruction */
357 OpCode op = GET_OPCODE(inst); 357 OpCode op = GET_OPCODE(inst);
358 if (op == OP_EXTRAARG) { /* extra argument? */
359 inst = *(ci->u.l.savedpc - 2); /* get its 'main' instruction */
360 op = GET_OPCODE(inst);
361 }
362 switch (op) { /* finish its execution */ 358 switch (op) { /* finish its execution */
363 case OP_ADD: case OP_SUB: case OP_MUL: case OP_DIV: 359 case OP_ADD: case OP_SUB: case OP_MUL: case OP_DIV:
364 case OP_MOD: case OP_POW: case OP_UNM: case OP_LEN: 360 case OP_MOD: case OP_POW: case OP_UNM: case OP_LEN:
365 case OP_GETGLOBAL: case OP_GETTABUP: case OP_GETTABLE: case OP_SELF: { 361 case OP_GETTABUP: case OP_GETTABLE: case OP_SELF: {
366 setobjs2s(L, base + GETARG_A(inst), --L->top); 362 setobjs2s(L, base + GETARG_A(inst), --L->top);
367 break; 363 break;
368 } 364 }
@@ -403,7 +399,7 @@ void luaV_finishOp (lua_State *L) {
403 L->top = ci->top; /* adjust results */ 399 L->top = ci->top; /* adjust results */
404 break; 400 break;
405 } 401 }
406 case OP_TAILCALL: case OP_SETGLOBAL: case OP_SETTABUP: case OP_SETTABLE: 402 case OP_TAILCALL: case OP_SETTABUP: case OP_SETTABLE:
407 break; 403 break;
408 default: lua_assert(0); 404 default: lua_assert(0);
409 } 405 }
@@ -501,14 +497,6 @@ void luaV_execute (lua_State *L) {
501 setobj2s(L, ra, cl->upvals[b]->v); 497 setobj2s(L, ra, cl->upvals[b]->v);
502 break; 498 break;
503 } 499 }
504 case OP_GETGLOBAL: {
505 TValue g;
506 TValue *rb = KBx(i);
507 sethvalue(L, &g, cl->env);
508 lua_assert(ttisstring(rb));
509 Protect(luaV_gettable(L, &g, rb, ra));
510 break;
511 }
512 case OP_GETTABUP: { 500 case OP_GETTABUP: {
513 int b = GETARG_B(i); 501 int b = GETARG_B(i);
514 Protect(luaV_gettable(L, cl->upvals[b]->v, RKC(i), ra)); 502 Protect(luaV_gettable(L, cl->upvals[b]->v, RKC(i), ra));
@@ -518,14 +506,6 @@ void luaV_execute (lua_State *L) {
518 Protect(luaV_gettable(L, RB(i), RKC(i), ra)); 506 Protect(luaV_gettable(L, RB(i), RKC(i), ra));
519 break; 507 break;
520 } 508 }
521 case OP_SETGLOBAL: {
522 TValue g;
523 TValue *rb = KBx(i);
524 sethvalue(L, &g, cl->env);
525 lua_assert(ttisstring(rb));
526 Protect(luaV_settable(L, &g, rb, ra));
527 break;
528 }
529 case OP_SETTABUP: { 509 case OP_SETTABUP: {
530 int a = GETARG_A(i); 510 int a = GETARG_A(i);
531 Protect(luaV_settable(L, cl->upvals[a]->v, RKB(i), RKC(i))); 511 Protect(luaV_settable(L, cl->upvals[a]->v, RKB(i), RKC(i)));
@@ -796,14 +776,6 @@ void luaV_execute (lua_State *L) {
796 int j; 776 int j;
797 ncl->l.p = p; 777 ncl->l.p = p;
798 setclvalue(L, ra, ncl); /* anchor new closure in stack */ 778 setclvalue(L, ra, ncl); /* anchor new closure in stack */
799 if (p->envreg != NO_REG) { /* lexical environment? */
800 StkId env = base + p->envreg;
801 if (!ttistable(env))
802 luaG_runerror(L, "environment is not a table: "
803 "cannot create closure");
804 else
805 ncl->l.env = hvalue(env);
806 }
807 for (j = 0; j < nup; j++) { /* fill in upvalues */ 779 for (j = 0; j < nup; j++) { /* fill in upvalues */
808 if (uv[j].instack) /* upvalue refers to local variable? */ 780 if (uv[j].instack) /* upvalue refers to local variable? */
809 ncl->l.upvals[j] = luaF_findupval(L, base + uv[j].idx); 781 ncl->l.upvals[j] = luaF_findupval(L, base + uv[j].idx);