From 4cd1f4aac01184765818e0cebf02da454ccf6590 Mon Sep 17 00:00:00 2001
From: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
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.
---
 lvm.c | 6 ++++++
 1 file changed, 6 insertions(+)

(limited to 'lvm.c')

diff --git a/lvm.c b/lvm.c
index dd6a660b..fdd99a42 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1455,6 +1455,12 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
         luaF_close(L, ra);
         vmbreak;
       }
+      vmcase(OP_TBC) {
+        UpVal *up = luaF_findupval(L, ra);  /* create new upvalue */
+        up->tt = LUA_TUPVALTBC;  /* mark it to be closed */
+        setnilvalue(s2v(ra));  /* intialize it with nil */
+        vmbreak;
+      }
       vmcase(OP_JMP) {
         dojump(ci, i, 0);
         vmbreak;
-- 
cgit v1.2.3-55-g6feb