From 54f7b46c1e8a0188e1649046a3a72522f2d769f4 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 9 Jul 2019 10:43:17 -0300 Subject: New implementation for constants VLOCAL expressions keep a reference to their corresponding 'Vardesc', and 'Upvaldesc' (for upvalues) has a field 'ro' (read-only). So, it is easier to check whether a variable is read-only. The decoupling in VLOCAL between 'vidx' ('Vardesc' index) and 'sidx' (stack index) should also help the forthcoming implementation of compile-time constant propagation. --- testes/locals.lua | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'testes') diff --git a/testes/locals.lua b/testes/locals.lua index 50230a27..0de00a98 100644 --- a/testes/locals.lua +++ b/testes/locals.lua @@ -177,14 +177,24 @@ do -- constants local a, b, c = 10, 20, 30 b = a + c + b -- 'b' is not constant assert(a == 10 and b == 60 and c == 30) - local function checkro (code, name) + local function checkro (name, code) local st, msg = load(code) local gab = string.format("attempt to assign to const variable '%s'", name) assert(not st and string.find(msg, gab)) end - checkro("local x, y, z = 10, 20, 30; x = 11; y = 12", "y") - checkro("local x, y, z = 10, 20, 30; x = 11", "x") - checkro("local x, y, z = 10, 20, 30; y = 10; z = 11", "z") + checkro("y", "local x, y, z = 10, 20, 30; x = 11; y = 12") + checkro("x", "local x, y, z = 10, 20, 30; x = 11") + checkro("z", "local x, y, z = 10, 20, 30; y = 10; z = 11") + + checkro("z", [[ + local a, z, b = 10; + function foo() a = 20; z = 32; end + ]]) + + checkro("var1", [[ + local a, var1 = 10; + function foo() a = 20; z = function () var1 = 12; end end + ]]) end -- cgit v1.2.3-55-g6feb