diff options
-rw-r--r-- | lbaselib.c | 4 | ||||
-rw-r--r-- | lcode.c | 14 | ||||
-rw-r--r-- | ldebug.c | 48 | ||||
-rw-r--r-- | ldump.c | 3 | ||||
-rw-r--r-- | lfunc.c | 3 | ||||
-rw-r--r-- | lobject.h | 3 | ||||
-rw-r--r-- | lopcodes.c | 6 | ||||
-rw-r--r-- | lopcodes.h | 7 | ||||
-rw-r--r-- | lparser.c | 47 | ||||
-rw-r--r-- | lparser.h | 4 | ||||
-rw-r--r-- | lundump.c | 3 | ||||
-rw-r--r-- | lvm.c | 34 |
12 files changed, 52 insertions, 124 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lbaselib.c,v 1.234 2009/12/22 15:32:50 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.235 2009/12/28 16:30:31 roberto Exp roberto $ |
3 | ** Basic library | 3 | ** Basic library |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -376,7 +376,7 @@ static int luaB_loadin (lua_State *L) { | |||
376 | n = luaB_load_aux(L, 2); | 376 | n = luaB_load_aux(L, 2); |
377 | if (n == 1) { /* success? */ | 377 | if (n == 1) { /* success? */ |
378 | lua_pushvalue(L, 1); /* environment for loaded function */ | 378 | lua_pushvalue(L, 1); /* environment for loaded function */ |
379 | lua_setfenv(L, -2); | 379 | lua_setupvalue(L, -2, 1); |
380 | } | 380 | } |
381 | return n; | 381 | return n; |
382 | } | 382 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lcode.c,v 2.43 2010/01/11 17:38:30 roberto Exp roberto $ | 2 | ** $Id: lcode.c,v 2.44 2010/02/26 20:40:29 roberto Exp roberto $ |
3 | ** Code generator for Lua | 3 | ** Code generator for Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -372,11 +372,6 @@ void luaK_dischargevars (FuncState *fs, expdesc *e) { | |||
372 | e->k = VRELOCABLE; | 372 | e->k = VRELOCABLE; |
373 | break; | 373 | break; |
374 | } | 374 | } |
375 | case VGLOBAL: { | ||
376 | e->u.s.info = luaK_codeABxX(fs, OP_GETGLOBAL, 0, e->u.s.info); | ||
377 | e->k = VRELOCABLE; | ||
378 | break; | ||
379 | } | ||
380 | case VINDEXED: { | 375 | case VINDEXED: { |
381 | freereg(fs, e->u.s.aux); | 376 | freereg(fs, e->u.s.aux); |
382 | freereg(fs, e->u.s.info); | 377 | freereg(fs, e->u.s.info); |
@@ -555,11 +550,6 @@ void luaK_storevar (FuncState *fs, expdesc *var, expdesc *ex) { | |||
555 | luaK_codeABC(fs, OP_SETUPVAL, e, var->u.s.info, 0); | 550 | luaK_codeABC(fs, OP_SETUPVAL, e, var->u.s.info, 0); |
556 | break; | 551 | break; |
557 | } | 552 | } |
558 | case VGLOBAL: { | ||
559 | int e = luaK_exp2anyreg(fs, ex); | ||
560 | luaK_codeABxX(fs, OP_SETGLOBAL, e, var->u.s.info); | ||
561 | break; | ||
562 | } | ||
563 | case VINDEXED: { | 553 | case VINDEXED: { |
564 | int e = luaK_exp2RK(fs, ex); | 554 | int e = luaK_exp2RK(fs, ex); |
565 | luaK_codeABC(fs, OP_SETTABLE, var->u.s.info, var->u.s.aux, e); | 555 | luaK_codeABC(fs, OP_SETTABLE, var->u.s.info, var->u.s.aux, e); |
@@ -584,9 +574,9 @@ void luaK_self (FuncState *fs, expdesc *e, expdesc *key) { | |||
584 | luaK_exp2anyreg(fs, e); | 574 | luaK_exp2anyreg(fs, e); |
585 | freeexp(fs, e); | 575 | freeexp(fs, e); |
586 | func = fs->freereg; | 576 | func = fs->freereg; |
587 | luaK_reserveregs(fs, 2); | ||
588 | luaK_codeABC(fs, OP_SELF, func, e->u.s.info, luaK_exp2RK(fs, key)); | 577 | luaK_codeABC(fs, OP_SELF, func, e->u.s.info, luaK_exp2RK(fs, key)); |
589 | freeexp(fs, key); | 578 | freeexp(fs, key); |
579 | luaK_reserveregs(fs, 2); | ||
590 | e->u.s.info = func; | 580 | e->u.s.info = func; |
591 | e->k = VNONRELOC; | 581 | e->k = VNONRELOC; |
592 | } | 582 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldebug.c,v 2.64 2010/02/26 20:40:29 roberto Exp roberto $ | 2 | ** $Id: ldebug.c,v 2.65 2010/03/05 14:01:29 roberto Exp roberto $ |
3 | ** Debug Interface | 3 | ** Debug Interface |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -260,11 +260,14 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { | |||
260 | */ | 260 | */ |
261 | 261 | ||
262 | 262 | ||
263 | static const char *kname (Proto *p, int c) { | 263 | static void kname (Proto *p, int c, int reg, const char *what, |
264 | if (ISK(c) && ttisstring(&p->k[INDEXK(c)])) | 264 | const char **name) { |
265 | return svalue(&p->k[INDEXK(c)]); | 265 | if (c == reg && *what == 'c') |
266 | return; /* index is a constant; name already correct */ | ||
267 | else if (ISK(c) && ttisstring(&p->k[INDEXK(c)])) | ||
268 | *name = svalue(&p->k[INDEXK(c)]); | ||
266 | else | 269 | else |
267 | return "?"; | 270 | *name = "?"; |
268 | } | 271 | } |
269 | 272 | ||
270 | 273 | ||
@@ -283,17 +286,6 @@ static const char *getobjname (lua_State *L, CallInfo *ci, int reg, | |||
283 | OpCode op = GET_OPCODE(i); | 286 | OpCode op = GET_OPCODE(i); |
284 | int a = GETARG_A(i); | 287 | int a = GETARG_A(i); |
285 | switch (op) { | 288 | switch (op) { |
286 | case OP_GETGLOBAL: { | ||
287 | if (reg == a) { | ||
288 | int g = GETARG_Bx(i); | ||
289 | if (g != 0) g--; | ||
290 | else g = GETARG_Ax(p->code[++pc]); | ||
291 | lua_assert(ttisstring(&p->k[g])); | ||
292 | *name = svalue(&p->k[g]); | ||
293 | what = "global"; | ||
294 | } | ||
295 | break; | ||
296 | } | ||
297 | case OP_MOVE: { | 289 | case OP_MOVE: { |
298 | if (reg == a) { | 290 | if (reg == a) { |
299 | int b = GETARG_B(i); /* move from 'b' to 'a' */ | 291 | int b = GETARG_B(i); /* move from 'b' to 'a' */ |
@@ -307,8 +299,12 @@ static const char *getobjname (lua_State *L, CallInfo *ci, int reg, | |||
307 | case OP_GETTABLE: { | 299 | case OP_GETTABLE: { |
308 | if (reg == a) { | 300 | if (reg == a) { |
309 | int k = GETARG_C(i); /* key index */ | 301 | int k = GETARG_C(i); /* key index */ |
310 | *name = kname(p, k); | 302 | int t = GETARG_B(i); |
311 | what = "field"; | 303 | const char *tabname = (op == OP_GETTABLE) |
304 | ? luaF_getlocalname(p, t + 1, pc) | ||
305 | : getstr(p->upvalues[t].name); | ||
306 | kname(p, k, a, what, name); | ||
307 | what = (tabname && strcmp(tabname, "_ENV") == 0) ? "global" : "field"; | ||
312 | } | 308 | } |
313 | break; | 309 | break; |
314 | } | 310 | } |
@@ -321,6 +317,17 @@ static const char *getobjname (lua_State *L, CallInfo *ci, int reg, | |||
321 | } | 317 | } |
322 | break; | 318 | break; |
323 | } | 319 | } |
320 | case OP_LOADK: { | ||
321 | if (reg == a) { | ||
322 | int b = GETARG_Bx(i); | ||
323 | b = (b > 0) ? b - 1 : GETARG_Ax(p->code[pc + 1]); | ||
324 | if (ttisstring(&p->k[b])) { | ||
325 | what = "constant"; | ||
326 | *name = svalue(&p->k[b]); | ||
327 | } | ||
328 | } | ||
329 | break; | ||
330 | } | ||
324 | case OP_LOADNIL: { | 331 | case OP_LOADNIL: { |
325 | int b = GETARG_B(i); /* move from 'b' to 'a' */ | 332 | int b = GETARG_B(i); /* move from 'b' to 'a' */ |
326 | if (a <= reg && reg <= b) /* set registers from 'a' to 'b' */ | 333 | if (a <= reg && reg <= b) /* set registers from 'a' to 'b' */ |
@@ -330,7 +337,7 @@ static const char *getobjname (lua_State *L, CallInfo *ci, int reg, | |||
330 | case OP_SELF: { | 337 | case OP_SELF: { |
331 | if (reg == a) { | 338 | if (reg == a) { |
332 | int k = GETARG_C(i); /* key index */ | 339 | int k = GETARG_C(i); /* key index */ |
333 | *name = kname(p, k); | 340 | kname(p, k, a, what, name); |
334 | what = "method"; | 341 | what = "method"; |
335 | } | 342 | } |
336 | break; | 343 | break; |
@@ -378,11 +385,10 @@ static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) { | |||
378 | *name = "for iterator"; | 385 | *name = "for iterator"; |
379 | return "for iterator"; | 386 | return "for iterator"; |
380 | } | 387 | } |
381 | case OP_GETGLOBAL: | ||
382 | case OP_SELF: | 388 | case OP_SELF: |
383 | case OP_GETTABUP: | 389 | case OP_GETTABUP: |
384 | case OP_GETTABLE: tm = TM_INDEX; break; | 390 | case OP_GETTABLE: tm = TM_INDEX; break; |
385 | case OP_SETGLOBAL: | 391 | case OP_SETTABUP: |
386 | case OP_SETTABLE: tm = TM_NEWINDEX; break; | 392 | case OP_SETTABLE: tm = TM_NEWINDEX; break; |
387 | case OP_EQ: tm = TM_EQ; break; | 393 | case OP_EQ: tm = TM_EQ; break; |
388 | case OP_ADD: tm = TM_ADD; break; | 394 | case OP_ADD: tm = TM_ADD; break; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldump.c,v 2.11 2009/09/28 16:32:50 roberto Exp roberto $ | 2 | ** $Id: ldump.c,v 2.12 2009/09/30 15:38:37 roberto Exp roberto $ |
3 | ** save precompiled Lua chunks | 3 | ** save precompiled Lua chunks |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -145,7 +145,6 @@ static void DumpFunction(const Proto* f, const TString* p, DumpState* D) | |||
145 | DumpChar(f->numparams,D); | 145 | DumpChar(f->numparams,D); |
146 | DumpChar(f->is_vararg,D); | 146 | DumpChar(f->is_vararg,D); |
147 | DumpChar(f->maxstacksize,D); | 147 | DumpChar(f->maxstacksize,D); |
148 | DumpChar(f->envreg,D); | ||
149 | DumpCode(f,D); | 148 | DumpCode(f,D); |
150 | DumpConstants(f,D); | 149 | DumpConstants(f,D); |
151 | DumpUpvalues(f,D); | 150 | DumpUpvalues(f,D); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lfunc.c,v 2.18 2009/12/11 13:39:34 roberto Exp roberto $ | 2 | ** $Id: lfunc.c,v 2.19 2009/12/16 16:42:58 roberto Exp roberto $ |
3 | ** Auxiliary functions to manipulate prototypes and closures | 3 | ** Auxiliary functions to manipulate prototypes and closures |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -127,7 +127,6 @@ Proto *luaF_newproto (lua_State *L) { | |||
127 | f->linedefined = 0; | 127 | f->linedefined = 0; |
128 | f->lastlinedefined = 0; | 128 | f->lastlinedefined = 0; |
129 | f->source = NULL; | 129 | f->source = NULL; |
130 | f->envreg = NO_REG; | ||
131 | return f; | 130 | return f; |
132 | } | 131 | } |
133 | 132 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lobject.h,v 2.33 2009/11/19 19:06:52 roberto Exp roberto $ | 2 | ** $Id: lobject.h,v 2.34 2010/01/08 20:00:20 roberto Exp roberto $ |
3 | ** Type definitions for Lua objects | 3 | ** Type definitions for Lua objects |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -264,7 +264,6 @@ typedef struct Proto { | |||
264 | lu_byte numparams; | 264 | lu_byte numparams; |
265 | lu_byte is_vararg; | 265 | lu_byte is_vararg; |
266 | lu_byte maxstacksize; | 266 | lu_byte maxstacksize; |
267 | lu_byte envreg; /* register in outer function with initial environment */ | ||
268 | } Proto; | 267 | } Proto; |
269 | 268 | ||
270 | 269 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lopcodes.c,v 1.41 2009/11/19 19:06:52 roberto Exp roberto $ | 2 | ** $Id: lopcodes.c,v 1.42 2010/02/26 20:40:29 roberto Exp roberto $ |
3 | ** See Copyright Notice in lua.h | 3 | ** See Copyright Notice in lua.h |
4 | */ | 4 | */ |
5 | 5 | ||
@@ -19,10 +19,8 @@ LUAI_DDEF const char *const luaP_opnames[NUM_OPCODES+1] = { | |||
19 | "LOADBOOL", | 19 | "LOADBOOL", |
20 | "LOADNIL", | 20 | "LOADNIL", |
21 | "GETUPVAL", | 21 | "GETUPVAL", |
22 | "GETGLOBAL", | ||
23 | "GETTABUP", | 22 | "GETTABUP", |
24 | "GETTABLE", | 23 | "GETTABLE", |
25 | "SETGLOBAL", | ||
26 | "SETTABUP", | 24 | "SETTABUP", |
27 | "SETUPVAL", | 25 | "SETUPVAL", |
28 | "SETTABLE", | 26 | "SETTABLE", |
@@ -69,10 +67,8 @@ LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = { | |||
69 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_LOADBOOL */ | 67 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_LOADBOOL */ |
70 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_LOADNIL */ | 68 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_LOADNIL */ |
71 | ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_GETUPVAL */ | 69 | ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_GETUPVAL */ |
72 | ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_GETGLOBAL */ | ||
73 | ,opmode(0, 1, OpArgU, OpArgK, iABC) /* OP_GETTABUP */ | 70 | ,opmode(0, 1, OpArgU, OpArgK, iABC) /* OP_GETTABUP */ |
74 | ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_GETTABLE */ | 71 | ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_GETTABLE */ |
75 | ,opmode(0, 0, OpArgK, OpArgN, iABx) /* OP_SETGLOBAL */ | ||
76 | ,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_SETTABUP */ | 72 | ,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_SETTABUP */ |
77 | ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_SETUPVAL */ | 73 | ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_SETUPVAL */ |
78 | ,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_SETTABLE */ | 74 | ,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_SETTABLE */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lopcodes.h,v 1.133 2009/11/19 19:06:52 roberto Exp roberto $ | 2 | ** $Id: lopcodes.h,v 1.134 2010/02/26 20:40:29 roberto Exp roberto $ |
3 | ** Opcodes for Lua virtual machine | 3 | ** Opcodes for Lua virtual machine |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -171,11 +171,9 @@ OP_LOADBOOL,/* A B C R(A) := (Bool)B; if (C) pc++ */ | |||
171 | OP_LOADNIL,/* A B R(A) := ... := R(B) := nil */ | 171 | OP_LOADNIL,/* A B R(A) := ... := R(B) := nil */ |
172 | OP_GETUPVAL,/* A B R(A) := UpValue[B] */ | 172 | OP_GETUPVAL,/* A B R(A) := UpValue[B] */ |
173 | 173 | ||
174 | OP_GETGLOBAL,/* A Bx R(A) := Gbl[Kst(Bx - 1)] */ | ||
175 | OP_GETTABUP,/* A B C R(A) := UpValue[B][RK(C)] */ | 174 | OP_GETTABUP,/* A B C R(A) := UpValue[B][RK(C)] */ |
176 | OP_GETTABLE,/* A B C R(A) := R(B)[RK(C)] */ | 175 | OP_GETTABLE,/* A B C R(A) := R(B)[RK(C)] */ |
177 | 176 | ||
178 | OP_SETGLOBAL,/* A Bx Gbl[Kst(Bx - 1)] := R(A) */ | ||
179 | OP_SETTABUP,/* A B C UpValue[A][RK(B)] := RK(C) */ | 177 | OP_SETTABUP,/* A B C UpValue[A][RK(B)] := RK(C) */ |
180 | OP_SETUPVAL,/* A B UpValue[B] := R(A) */ | 178 | OP_SETUPVAL,/* A B UpValue[B] := R(A) */ |
181 | OP_SETTABLE,/* A B C R(A)[RK(B)] := RK(C) */ | 179 | OP_SETTABLE,/* A B C R(A)[RK(B)] := RK(C) */ |
@@ -245,8 +243,7 @@ OP_EXTRAARG/* Ax extra (larger) argument for previous opcode */ | |||
245 | (*) In OP_SETLIST, if (B == 0) then B = `top'; if (C == 0) then next | 243 | (*) In OP_SETLIST, if (B == 0) then B = `top'; if (C == 0) then next |
246 | 'instruction' is EXTRAARG(real C). | 244 | 'instruction' is EXTRAARG(real C). |
247 | 245 | ||
248 | (*) In OP_LOADK, OP_GETGLOBAL, and OP_SETGLOBAL, if (Bx == 0) then next | 246 | (*) In OP_LOADK, if (Bx == 0) then next 'instruction' is EXTRAARG(real Bx). |
249 | 'instruction' is EXTRAARG(real Bx). | ||
250 | 247 | ||
251 | (*) For comparisons, A specifies what condition the test should accept | 248 | (*) For comparisons, A specifies what condition the test should accept |
252 | (true or false). | 249 | (true or false). |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lparser.c,v 2.77 2010/03/04 18:12:57 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 2.78 2010/03/08 16:55:52 roberto Exp roberto $ |
3 | ** Lua Parser | 3 | ** Lua Parser |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -259,7 +259,7 @@ static void markupval (FuncState *fs, int level) { | |||
259 | */ | 259 | */ |
260 | static int singlevaraux (FuncState *fs, TString *n, expdesc *var, int base) { | 260 | static int singlevaraux (FuncState *fs, TString *n, expdesc *var, int base) { |
261 | if (fs == NULL) /* no more levels? */ | 261 | if (fs == NULL) /* no more levels? */ |
262 | return VGLOBAL; /* default is global variable */ | 262 | return VVOID; /* default is global */ |
263 | else { | 263 | else { |
264 | int v = searchvar(fs, n); /* look up locals at current level */ | 264 | int v = searchvar(fs, n); /* look up locals at current level */ |
265 | if (v >= 0) { /* found? */ | 265 | if (v >= 0) { /* found? */ |
@@ -271,8 +271,8 @@ static int singlevaraux (FuncState *fs, TString *n, expdesc *var, int base) { | |||
271 | else { /* not found as local at current level; try upvalues */ | 271 | else { /* not found as local at current level; try upvalues */ |
272 | int idx = searchupvalue(fs, n); /* try existing upvalues */ | 272 | int idx = searchupvalue(fs, n); /* try existing upvalues */ |
273 | if (idx < 0) { /* not found? */ | 273 | if (idx < 0) { /* not found? */ |
274 | if (singlevaraux(fs->prev, n, var, 0) == VGLOBAL) /* try upper levels */ | 274 | if (singlevaraux(fs->prev, n, var, 0) == VVOID) /* try upper levels */ |
275 | return VGLOBAL; /* not found; is a global */ | 275 | return VVOID; /* not found; is a global */ |
276 | /* else was LOCAL or UPVAL */ | 276 | /* else was LOCAL or UPVAL */ |
277 | idx = newupvalue(fs, n, var); /* will be a new upvalue */ | 277 | idx = newupvalue(fs, n, var); /* will be a new upvalue */ |
278 | } | 278 | } |
@@ -286,15 +286,12 @@ static int singlevaraux (FuncState *fs, TString *n, expdesc *var, int base) { | |||
286 | static void singlevar (LexState *ls, expdesc *var) { | 286 | static void singlevar (LexState *ls, expdesc *var) { |
287 | TString *varname = str_checkname(ls); | 287 | TString *varname = str_checkname(ls); |
288 | FuncState *fs = ls->fs; | 288 | FuncState *fs = ls->fs; |
289 | if (singlevaraux(fs, varname, var, 1) == VGLOBAL) { | 289 | if (singlevaraux(fs, varname, var, 1) == VVOID) { /* global name? */ |
290 | if (fs->envreg == NO_REG) /* regular global? */ | 290 | expdesc key; |
291 | init_exp(var, VGLOBAL, luaK_stringK(fs, varname)); | 291 | singlevaraux(fs, ls->envn, var, 1); /* get _ENV variable */ |
292 | else { /* "globals" are in current lexical environment */ | 292 | lua_assert(var->k == VLOCAL || var->k == VUPVAL); |
293 | expdesc key; | 293 | codestring(ls, &key, varname); /* key is variable name */ |
294 | init_exp(var, VLOCAL, fs->envreg); /* current environment */ | 294 | luaK_indexed(fs, var, &key); /* env[varname] */ |
295 | codestring(ls, &key, varname); /* key is variable name */ | ||
296 | luaK_indexed(fs, var, &key); /* env[varname] */ | ||
297 | } | ||
298 | } | 295 | } |
299 | } | 296 | } |
300 | 297 | ||
@@ -363,7 +360,6 @@ static void pushclosure (LexState *ls, Proto *clp, expdesc *v) { | |||
363 | while (oldsize < f->sizep) f->p[oldsize++] = NULL; | 360 | while (oldsize < f->sizep) f->p[oldsize++] = NULL; |
364 | f->p[fs->np++] = clp; | 361 | f->p[fs->np++] = clp; |
365 | /* initial environment for new function is current lexical environment */ | 362 | /* initial environment for new function is current lexical environment */ |
366 | clp->envreg = fs->envreg; | ||
367 | luaC_objbarrier(ls->L, f, clp); | 363 | luaC_objbarrier(ls->L, f, clp); |
368 | init_exp(v, VRELOCABLE, luaK_codeABx(fs, OP_CLOSURE, 0, fs->np-1)); | 364 | init_exp(v, VRELOCABLE, luaK_codeABx(fs, OP_CLOSURE, 0, fs->np-1)); |
369 | } | 365 | } |
@@ -386,7 +382,6 @@ static void open_func (LexState *ls, FuncState *fs) { | |||
386 | fs->nlocvars = 0; | 382 | fs->nlocvars = 0; |
387 | fs->nactvar = 0; | 383 | fs->nactvar = 0; |
388 | fs->firstlocal = ls->varl->nactvar; | 384 | fs->firstlocal = ls->varl->nactvar; |
389 | fs->envreg = NO_REG; | ||
390 | fs->bl = NULL; | 385 | fs->bl = NULL; |
391 | f = luaF_newproto(L); | 386 | f = luaF_newproto(L); |
392 | fs->f = f; | 387 | fs->f = f; |
@@ -1304,24 +1299,6 @@ static void funcstat (LexState *ls, int line) { | |||
1304 | } | 1299 | } |
1305 | 1300 | ||
1306 | 1301 | ||
1307 | static void instat (LexState *ls, int line) { | ||
1308 | /* instat -> IN exp DO block END */ | ||
1309 | FuncState *fs = ls->fs; | ||
1310 | int oldenv = fs->envreg; /* save current environment */ | ||
1311 | BlockCnt bl; | ||
1312 | luaX_next(ls); /* skip IN */ | ||
1313 | enterblock(fs, &bl, 0); /* scope for environment variable */ | ||
1314 | new_localvarliteral(ls, "(environment)"); | ||
1315 | fs->envreg = exp1(ls); /* new environment */ | ||
1316 | adjustlocalvars(ls, 1); | ||
1317 | checknext(ls, TK_DO); | ||
1318 | block(ls); | ||
1319 | leaveblock(fs); | ||
1320 | check_match(ls, TK_END, TK_IN, line); | ||
1321 | fs->envreg = oldenv; /* restore outer environment */ | ||
1322 | } | ||
1323 | |||
1324 | |||
1325 | static void exprstat (LexState *ls) { | 1302 | static void exprstat (LexState *ls) { |
1326 | /* stat -> func | assignment */ | 1303 | /* stat -> func | assignment */ |
1327 | FuncState *fs = ls->fs; | 1304 | FuncState *fs = ls->fs; |
@@ -1386,10 +1363,6 @@ static int statement (LexState *ls) { | |||
1386 | check_match(ls, TK_END, TK_DO, line); | 1363 | check_match(ls, TK_END, TK_DO, line); |
1387 | return 0; | 1364 | return 0; |
1388 | } | 1365 | } |
1389 | case TK_IN: { | ||
1390 | instat(ls, line); | ||
1391 | return 0; | ||
1392 | } | ||
1393 | case TK_FOR: { /* stat -> forstat */ | 1366 | case TK_FOR: { /* stat -> forstat */ |
1394 | forstat(ls, line); | 1367 | forstat(ls, line); |
1395 | return 0; | 1368 | return 0; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lparser.h,v 1.61 2009/10/11 20:02:19 roberto Exp roberto $ | 2 | ** $Id: lparser.h,v 1.62 2010/02/26 20:40:29 roberto Exp roberto $ |
3 | ** Lua Parser | 3 | ** Lua Parser |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -25,7 +25,6 @@ typedef enum { | |||
25 | VKNUM, /* nval = numerical value */ | 25 | VKNUM, /* nval = numerical value */ |
26 | VLOCAL, /* info = local register */ | 26 | VLOCAL, /* info = local register */ |
27 | VUPVAL, /* info = index of upvalue in 'upvalues' */ | 27 | VUPVAL, /* info = index of upvalue in 'upvalues' */ |
28 | VGLOBAL, /* info = index of global name in 'k' */ | ||
29 | VINDEXED, /* info = table R/K; aux = index R/K */ | 28 | VINDEXED, /* info = table R/K; aux = index R/K */ |
30 | VINDEXEDUP, /* info = table upvalue; aux = R/K */ | 29 | VINDEXEDUP, /* info = table upvalue; aux = R/K */ |
31 | VJMP, /* info = instruction pc */ | 30 | VJMP, /* info = instruction pc */ |
@@ -81,7 +80,6 @@ typedef struct FuncState { | |||
81 | short nlocvars; /* number of elements in `locvars' */ | 80 | short nlocvars; /* number of elements in `locvars' */ |
82 | lu_byte nactvar; /* number of active local variables */ | 81 | lu_byte nactvar; /* number of active local variables */ |
83 | lu_byte nups; /* number of upvalues */ | 82 | lu_byte nups; /* number of upvalues */ |
84 | lu_byte envreg; /* register holding current lexical environment */ | ||
85 | } FuncState; | 83 | } FuncState; |
86 | 84 | ||
87 | 85 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lundump.c,v 2.11 2009/09/28 16:32:50 roberto Exp roberto $ | 2 | ** $Id: lundump.c,v 2.12 2009/09/30 15:38:37 roberto Exp roberto $ |
3 | ** load precompiled Lua chunks | 3 | ** load precompiled Lua chunks |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -180,7 +180,6 @@ static Proto* LoadFunction(LoadState* S, TString* p) | |||
180 | f->numparams=LoadByte(S); | 180 | f->numparams=LoadByte(S); |
181 | f->is_vararg=LoadByte(S); | 181 | f->is_vararg=LoadByte(S); |
182 | f->maxstacksize=LoadByte(S); | 182 | f->maxstacksize=LoadByte(S); |
183 | f->envreg=LoadByte(S); | ||
184 | LoadCode(S,f); | 183 | LoadCode(S,f); |
185 | LoadConstants(S,f); | 184 | LoadConstants(S,f); |
186 | LoadUpvalues(S,f); | 185 | LoadUpvalues(S,f); |
@@ -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); |