summaryrefslogtreecommitdiff
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-github-4cd1f4aac01184765818e0cebf02da454ccf6590.tar.gz
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 'ltests.c')
-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) {
checkudata(g, gco2u(o));
break;
}
- case LUA_TUPVAL: {
+ case LUA_TUPVAL:
+ case LUA_TUPVALTBC: {
checkvalref(g, o, gco2upv(o)->v);
break;
}
@@ -522,35 +523,37 @@ int lua_checkmemory (lua_State *L) {
static char *buildop (Proto *p, int pc, char *buff) {
+ char *obuff = buff;
Instruction i = p->code[pc];
OpCode o = GET_OPCODE(i);
const char *name = opnames[o];
int line = luaG_getfuncline(p, pc);
int lineinfo = (p->lineinfo != NULL) ? p->lineinfo[pc] : 0;
- sprintf(buff, "(%2d - %4d) %4d - ", lineinfo, line, pc);
+ if (lineinfo == ABSLINEINFO)
+ buff += sprintf(buff, "(__");
+ else
+ buff += sprintf(buff, "(%2d", lineinfo);
+ buff += sprintf(buff, " - %4d) %4d - ", line, pc);
switch (getOpMode(o)) {
case iABC:
- sprintf(buff+strlen(buff), "%-12s%4d %4d %4d%s", name,
+ sprintf(buff, "%-12s%4d %4d %4d%s", name,
GETARG_A(i), GETARG_B(i), GETARG_C(i),
GETARG_k(i) ? " (k)" : "");
break;
case iABx:
- sprintf(buff+strlen(buff), "%-12s%4d %4d", name, GETARG_A(i),
- GETARG_Bx(i));
+ sprintf(buff, "%-12s%4d %4d", name, GETARG_A(i), GETARG_Bx(i));
break;
case iAsBx:
- sprintf(buff+strlen(buff), "%-12s%4d %4d", name, GETARG_A(i),
- GETARG_sBx(i));
+ sprintf(buff, "%-12s%4d %4d", name, GETARG_A(i), GETARG_sBx(i));
break;
case iAx:
- sprintf(buff+strlen(buff), "%-12s%4d", name, GETARG_Ax(i));
+ sprintf(buff, "%-12s%4d", name, GETARG_Ax(i));
break;
case isJ:
- sprintf(buff+strlen(buff), "%-12s%4d (%1d)", name, GETARG_sJ(i),
- !!GETARG_m(i));
+ sprintf(buff, "%-12s%4d (%1d)", name, GETARG_sJ(i), !!GETARG_m(i));
break;
}
- return buff;
+ return obuff;
}