From 4cd1f4aac01184765818e0cebf02da454ccf6590 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 8 Oct 2018 10:42:07 -0300 Subject: 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. --- ltests.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'ltests.c') 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; } -- cgit v1.2.1