aboutsummaryrefslogtreecommitdiff
path: root/lcode.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 /lcode.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--lcode.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/lcode.c b/lcode.c
index d00038dd..e84b85ac 100644
--- a/lcode.c
+++ b/lcode.c
@@ -1673,13 +1673,13 @@ void luaK_finish (FuncState *fs) {
1673 lua_assert(i == 0 || isOT(*(pc - 1)) == isIT(*pc)); 1673 lua_assert(i == 0 || isOT(*(pc - 1)) == isIT(*pc));
1674 switch (GET_OPCODE(*pc)) { 1674 switch (GET_OPCODE(*pc)) {
1675 case OP_RETURN0: case OP_RETURN1: { 1675 case OP_RETURN0: case OP_RETURN1: {
1676 if (p->sizep == 0 && !p->is_vararg) 1676 if (!(fs->needclose || p->is_vararg))
1677 break; /* no extra work */ 1677 break; /* no extra work */
1678 /* else use OP_RETURN to do the extra work */ 1678 /* else use OP_RETURN to do the extra work */
1679 SET_OPCODE(*pc, OP_RETURN); 1679 SET_OPCODE(*pc, OP_RETURN);
1680 } /* FALLTHROUGH */ 1680 } /* FALLTHROUGH */
1681 case OP_RETURN: case OP_TAILCALL: { 1681 case OP_RETURN: case OP_TAILCALL: {
1682 if (p->sizep > 0 || p->is_vararg) { 1682 if (fs->needclose || p->is_vararg) {
1683 SETARG_C(*pc, p->is_vararg ? p->numparams + 1 : 0); 1683 SETARG_C(*pc, p->is_vararg ? p->numparams + 1 : 0);
1684 SETARG_k(*pc, 1); /* signal that there is extra work */ 1684 SETARG_k(*pc, 1); /* signal that there is extra work */
1685 } 1685 }