mirror of
https://github.com/lua/lua
synced 2026-09-29 04:35:58 +03:00
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.
This commit is contained in:
parent
b114c7d487
commit
4cd1f4aac0
15 changed files with 81 additions and 22 deletions
25
ltests.c
25
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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue