aboutsummaryrefslogtreecommitdiff
path: root/ltests.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2018-10-08 10:42:07 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2018-10-08 10:42:07 -0300
commit4cd1f4aac01184765818e0cebf02da454ccf6590 (patch)
treec7e6398095afccc9987ed42598477094b6ee2aa6 /ltests.c
parentb114c7d4871051cbdd7af185a61f35fe4028da79 (diff)
downloadlua-4cd1f4aac01184765818e0cebf02da454ccf6590.tar.gz
lua-4cd1f4aac01184765818e0cebf02da454ccf6590.tar.bz2
lua-4cd1f4aac01184765818e0cebf02da454ccf6590.zip
Towards "to closed" local variables
Start of the implementation of "scoped variables" or "to be closed" variables, local variables whose '__close' (or themselves) are called when they go out of scope. This commit implements the syntax, the opcode, and the creation of the corresponding upvalue, but it still does not call the finalizations when the variable goes out of scope (the most important part). Currently, the syntax is 'local scoped name = exp', but that will probably change.
Diffstat (limited to '')
-rw-r--r--ltests.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/ltests.c b/ltests.c
index bc71d937..ff962543 100644
--- a/ltests.c
+++ b/ltests.c
@@ -357,7 +357,8 @@ static void checkrefs (global_State *g, GCObject *o) {
357 checkudata(g, gco2u(o)); 357 checkudata(g, gco2u(o));
358 break; 358 break;
359 } 359 }
360 case LUA_TUPVAL: { 360 case LUA_TUPVAL:
361 case LUA_TUPVALTBC: {
361 checkvalref(g, o, gco2upv(o)->v); 362 checkvalref(g, o, gco2upv(o)->v);
362 break; 363 break;
363 } 364 }
@@ -522,35 +523,37 @@ int lua_checkmemory (lua_State *L) {
522 523
523 524
524static char *buildop (Proto *p, int pc, char *buff) { 525static char *buildop (Proto *p, int pc, char *buff) {
526 char *obuff = buff;
525 Instruction i = p->code[pc]; 527 Instruction i = p->code[pc];
526 OpCode o = GET_OPCODE(i); 528 OpCode o = GET_OPCODE(i);
527 const char *name = opnames[o]; 529 const char *name = opnames[o];
528 int line = luaG_getfuncline(p, pc); 530 int line = luaG_getfuncline(p, pc);
529 int lineinfo = (p->lineinfo != NULL) ? p->lineinfo[pc] : 0; 531 int lineinfo = (p->lineinfo != NULL) ? p->lineinfo[pc] : 0;
530 sprintf(buff, "(%2d - %4d) %4d - ", lineinfo, line, pc); 532 if (lineinfo == ABSLINEINFO)
533 buff += sprintf(buff, "(__");
534 else
535 buff += sprintf(buff, "(%2d", lineinfo);
536 buff += sprintf(buff, " - %4d) %4d - ", line, pc);
531 switch (getOpMode(o)) { 537 switch (getOpMode(o)) {
532 case iABC: 538 case iABC:
533 sprintf(buff+strlen(buff), "%-12s%4d %4d %4d%s", name, 539 sprintf(buff, "%-12s%4d %4d %4d%s", name,
534 GETARG_A(i), GETARG_B(i), GETARG_C(i), 540 GETARG_A(i), GETARG_B(i), GETARG_C(i),
535 GETARG_k(i) ? " (k)" : ""); 541 GETARG_k(i) ? " (k)" : "");
536 break; 542 break;
537 case iABx: 543 case iABx:
538 sprintf(buff+strlen(buff), "%-12s%4d %4d", name, GETARG_A(i), 544 sprintf(buff, "%-12s%4d %4d", name, GETARG_A(i), GETARG_Bx(i));
539 GETARG_Bx(i));
540 break; 545 break;
541 case iAsBx: 546 case iAsBx:
542 sprintf(buff+strlen(buff), "%-12s%4d %4d", name, GETARG_A(i), 547 sprintf(buff, "%-12s%4d %4d", name, GETARG_A(i), GETARG_sBx(i));
543 GETARG_sBx(i));
544 break; 548 break;
545 case iAx: 549 case iAx:
546 sprintf(buff+strlen(buff), "%-12s%4d", name, GETARG_Ax(i)); 550 sprintf(buff, "%-12s%4d", name, GETARG_Ax(i));
547 break; 551 break;
548 case isJ: 552 case isJ:
549 sprintf(buff+strlen(buff), "%-12s%4d (%1d)", name, GETARG_sJ(i), 553 sprintf(buff, "%-12s%4d (%1d)", name, GETARG_sJ(i), !!GETARG_m(i));
550 !!GETARG_m(i));
551 break; 554 break;
552 } 555 }
553 return buff; 556 return obuff;
554} 557}
555 558
556 559