diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-03-12 16:14:06 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-03-12 16:14:06 -0300 |
commit | 25c557ec6367870c127e879cce8ed8fa21f34398 (patch) | |
tree | 37d322402a8163145a0f3a5728f98115402f352f /ldebug.c | |
parent | f292760f12022a83cf01e788482a264aeeb3c276 (diff) | |
download | lua-25c557ec6367870c127e879cce8ed8fa21f34398.tar.gz lua-25c557ec6367870c127e879cce8ed8fa21f34398.tar.bz2 lua-25c557ec6367870c127e879cce8ed8fa21f34398.zip |
first version of _ENV; no more global variables
Diffstat (limited to 'ldebug.c')
-rw-r--r-- | ldebug.c | 48 |
1 files changed, 27 insertions, 21 deletions
@@ -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; |