diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-07-09 10:43:17 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-07-09 10:43:17 -0300 |
commit | 54f7b46c1e8a0188e1649046a3a72522f2d769f4 (patch) | |
tree | 28e973e10e2bc82de4d7d1e7a9f6673b028f7ad2 /testes | |
parent | e888976bc6ba5592fb8ab8ecc04a8f63e217aa74 (diff) | |
download | lua-54f7b46c1e8a0188e1649046a3a72522f2d769f4.tar.gz lua-54f7b46c1e8a0188e1649046a3a72522f2d769f4.tar.bz2 lua-54f7b46c1e8a0188e1649046a3a72522f2d769f4.zip |
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.
Diffstat (limited to 'testes')
-rw-r--r-- | testes/locals.lua | 18 |
1 files changed, 14 insertions, 4 deletions
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 | |||
177 | local <const> a, b, <const> c = 10, 20, 30 | 177 | local <const> a, b, <const> c = 10, 20, 30 |
178 | b = a + c + b -- 'b' is not constant | 178 | b = a + c + b -- 'b' is not constant |
179 | assert(a == 10 and b == 60 and c == 30) | 179 | assert(a == 10 and b == 60 and c == 30) |
180 | local function checkro (code, name) | 180 | local function checkro (name, code) |
181 | local st, msg = load(code) | 181 | local st, msg = load(code) |
182 | local gab = string.format("attempt to assign to const variable '%s'", name) | 182 | local gab = string.format("attempt to assign to const variable '%s'", name) |
183 | assert(not st and string.find(msg, gab)) | 183 | assert(not st and string.find(msg, gab)) |
184 | end | 184 | end |
185 | checkro("local x, <const> y, z = 10, 20, 30; x = 11; y = 12", "y") | 185 | checkro("y", "local x, <const> y, z = 10, 20, 30; x = 11; y = 12") |
186 | checkro("local <const> x, y, <const> z = 10, 20, 30; x = 11", "x") | 186 | checkro("x", "local <const> x, y, <const> z = 10, 20, 30; x = 11") |
187 | checkro("local <const> x, y, <const> z = 10, 20, 30; y = 10; z = 11", "z") | 187 | checkro("z", "local <const> x, y, <const> z = 10, 20, 30; y = 10; z = 11") |
188 | |||
189 | checkro("z", [[ | ||
190 | local a, <const> z, b = 10; | ||
191 | function foo() a = 20; z = 32; end | ||
192 | ]]) | ||
193 | |||
194 | checkro("var1", [[ | ||
195 | local a, <const> var1 = 10; | ||
196 | function foo() a = 20; z = function () var1 = 12; end end | ||
197 | ]]) | ||
188 | end | 198 | end |
189 | 199 | ||
190 | 200 | ||