diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-07-30 12:18:19 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-07-30 12:18:19 -0300 |
commit | 0d529138042563baf260366e19a7aa2c60a07174 (patch) | |
tree | ea8699a57a9b26e620a2ed6bc2a11c9e49dee780 /testes | |
parent | b80077b8f3e27a94c6afa895b41a9f8b52c42e61 (diff) | |
download | lua-0d529138042563baf260366e19a7aa2c60a07174.tar.gz lua-0d529138042563baf260366e19a7aa2c60a07174.tar.bz2 lua-0d529138042563baf260366e19a7aa2c60a07174.zip |
Change in the syntax of attributes
Attributes changed to posfixed ('x <const>', instead of '<const> x'),
and "toclose" renamed to "close". Posfixed attributes seem to make it
clearer that it applies to only one variable when there are multiple
variables.
Diffstat (limited to 'testes')
-rw-r--r-- | testes/api.lua | 2 | ||||
-rw-r--r-- | testes/code.lua | 36 | ||||
-rw-r--r-- | testes/constructs.lua | 16 | ||||
-rw-r--r-- | testes/coroutine.lua | 8 | ||||
-rw-r--r-- | testes/files.lua | 14 | ||||
-rw-r--r-- | testes/goto.lua | 2 | ||||
-rw-r--r-- | testes/locals.lua | 70 | ||||
-rw-r--r-- | testes/main.lua | 4 | ||||
-rw-r--r-- | testes/math.lua | 24 | ||||
-rw-r--r-- | testes/strings.lua | 4 |
10 files changed, 90 insertions, 90 deletions
diff --git a/testes/api.lua b/testes/api.lua index 0966ed19..3f7f7596 100644 --- a/testes/api.lua +++ b/testes/api.lua | |||
@@ -1203,7 +1203,7 @@ end) | |||
1203 | testamem("to-be-closed variables", function() | 1203 | testamem("to-be-closed variables", function() |
1204 | local flag | 1204 | local flag |
1205 | do | 1205 | do |
1206 | local <toclose> x = | 1206 | local x <close> = |
1207 | setmetatable({}, {__close = function () flag = true end}) | 1207 | setmetatable({}, {__close = function () flag = true end}) |
1208 | flag = false | 1208 | flag = false |
1209 | local x = {} | 1209 | local x = {} |
diff --git a/testes/code.lua b/testes/code.lua index 57923b14..3b768f33 100644 --- a/testes/code.lua +++ b/testes/code.lua | |||
@@ -8,22 +8,22 @@ end | |||
8 | print "testing code generation and optimizations" | 8 | print "testing code generation and optimizations" |
9 | 9 | ||
10 | -- to test constant propagation | 10 | -- to test constant propagation |
11 | local <const> k0aux = 0 | 11 | local k0aux <const> = 0 |
12 | local <const> k0 = k0aux | 12 | local k0 <const> = k0aux |
13 | local <const> k1 = 1 | 13 | local k1 <const> = 1 |
14 | local <const> k3 = 3 | 14 | local k3 <const> = 3 |
15 | local <const> k6 = k3 + (k3 << k0) | 15 | local k6 <const> = k3 + (k3 << k0) |
16 | local <const> kFF0 = 0xFF0 | 16 | local kFF0 <const> = 0xFF0 |
17 | local <const> k3_78 = 3.78 | 17 | local k3_78 <const> = 3.78 |
18 | local <const> x, <const> k3_78_4 = 10, k3_78 / 4 | 18 | local x, k3_78_4 <const> = 10, k3_78 / 4 |
19 | assert(x == 10) | 19 | assert(x == 10) |
20 | 20 | ||
21 | local <const> kx = "x" | 21 | local kx <const> = "x" |
22 | 22 | ||
23 | local <const> kTrue = true | 23 | local kTrue <const> = true |
24 | local <const> kFalse = false | 24 | local kFalse <const> = false |
25 | 25 | ||
26 | local <const> kNil = nil | 26 | local kNil <const> = nil |
27 | 27 | ||
28 | -- this code gave an error for the code checker | 28 | -- this code gave an error for the code checker |
29 | do | 29 | do |
@@ -105,7 +105,7 @@ end, 'CLOSURE', 'NEWTABLE', 'EXTRAARG', 'GETTABUP', 'CALL', | |||
105 | 105 | ||
106 | -- sequence of LOADNILs | 106 | -- sequence of LOADNILs |
107 | check(function () | 107 | check(function () |
108 | local <const> kNil = nil | 108 | local kNil <const> = nil |
109 | local a,b,c | 109 | local a,b,c |
110 | local d; local e; | 110 | local d; local e; |
111 | local f,g,h; | 111 | local f,g,h; |
@@ -173,7 +173,7 @@ end, | |||
173 | 173 | ||
174 | -- "get/set table" with numeric indices | 174 | -- "get/set table" with numeric indices |
175 | check(function (a) | 175 | check(function (a) |
176 | local <const> k255 = 255 | 176 | local k255 <const> = 255 |
177 | a[1] = a[100] | 177 | a[1] = a[100] |
178 | a[k255] = a[256] | 178 | a[k255] = a[256] |
179 | a[256] = 5 | 179 | a[256] = 5 |
@@ -276,14 +276,14 @@ checkI(function () return ((100 << k6) << -4) >> 2 end, 100) | |||
276 | 276 | ||
277 | -- borders around MAXARG_sBx ((((1 << 17) - 1) >> 1) == 65535) | 277 | -- borders around MAXARG_sBx ((((1 << 17) - 1) >> 1) == 65535) |
278 | local a = 17; local sbx = ((1 << a) - 1) >> 1 -- avoid folding | 278 | local a = 17; local sbx = ((1 << a) - 1) >> 1 -- avoid folding |
279 | local <const> border = 65535 | 279 | local border <const> = 65535 |
280 | checkI(function () return border end, sbx) | 280 | checkI(function () return border end, sbx) |
281 | checkI(function () return -border end, -sbx) | 281 | checkI(function () return -border end, -sbx) |
282 | checkI(function () return border + 1 end, sbx + 1) | 282 | checkI(function () return border + 1 end, sbx + 1) |
283 | checkK(function () return border + 2 end, sbx + 2) | 283 | checkK(function () return border + 2 end, sbx + 2) |
284 | checkK(function () return -(border + 1) end, -(sbx + 1)) | 284 | checkK(function () return -(border + 1) end, -(sbx + 1)) |
285 | 285 | ||
286 | local <const> border = 65535.0 | 286 | local border <const> = 65535.0 |
287 | checkF(function () return border end, sbx + 0.0) | 287 | checkF(function () return border end, sbx + 0.0) |
288 | checkF(function () return -border end, -sbx + 0.0) | 288 | checkF(function () return -border end, -sbx + 0.0) |
289 | checkF(function () return border + 1 end, (sbx + 1.0)) | 289 | checkF(function () return border + 1 end, (sbx + 1.0)) |
@@ -411,9 +411,9 @@ checkequal(function () return 6 and true or nil end, | |||
411 | 411 | ||
412 | 412 | ||
413 | do -- string constants | 413 | do -- string constants |
414 | local <const> k0 = "00000000000000000000000000000000000000000000000000" | 414 | local k0 <const> = "00000000000000000000000000000000000000000000000000" |
415 | local function f1 () | 415 | local function f1 () |
416 | local <const> k = k0 | 416 | local k <const> = k0 |
417 | return function () | 417 | return function () |
418 | return function () return k end | 418 | return function () return k end |
419 | end | 419 | end |
diff --git a/testes/constructs.lua b/testes/constructs.lua index 8a549e10..a74a8c04 100644 --- a/testes/constructs.lua +++ b/testes/constructs.lua | |||
@@ -211,15 +211,15 @@ assert(a==1 and b==nil) | |||
211 | print'+'; | 211 | print'+'; |
212 | 212 | ||
213 | do -- testing constants | 213 | do -- testing constants |
214 | local <const> prog = [[local <XXX> x = 10]] | 214 | local prog <const> = [[local x <XXX> = 10]] |
215 | checkload(prog, "unknown attribute 'XXX'") | 215 | checkload(prog, "unknown attribute 'XXX'") |
216 | 216 | ||
217 | checkload([[local <const> xxx = 20; xxx = 10]], | 217 | checkload([[local xxx <const> = 20; xxx = 10]], |
218 | ":1: attempt to assign to const variable 'xxx'") | 218 | ":1: attempt to assign to const variable 'xxx'") |
219 | 219 | ||
220 | checkload([[ | 220 | checkload([[ |
221 | local xx; | 221 | local xx; |
222 | local <const> xxx = 20; | 222 | local xxx <const> = 20; |
223 | local yyy; | 223 | local yyy; |
224 | local function foo () | 224 | local function foo () |
225 | local abc = xx + yyy + xxx; | 225 | local abc = xx + yyy + xxx; |
@@ -228,7 +228,7 @@ do -- testing constants | |||
228 | ]], ":6: attempt to assign to const variable 'xxx'") | 228 | ]], ":6: attempt to assign to const variable 'xxx'") |
229 | 229 | ||
230 | checkload([[ | 230 | checkload([[ |
231 | local <toclose> x = nil | 231 | local x <close> = nil |
232 | x = io.open() | 232 | x = io.open() |
233 | ]], ":2: attempt to assign to const variable 'x'") | 233 | ]], ":2: attempt to assign to const variable 'x'") |
234 | end | 234 | end |
@@ -304,7 +304,7 @@ if _ENV.GLOB1 == 0 then | |||
304 | basiccases[2][1] = "F" -- constant false | 304 | basiccases[2][1] = "F" -- constant false |
305 | 305 | ||
306 | prog = [[ | 306 | prog = [[ |
307 | local <const> F = false | 307 | local F <const> = false |
308 | if %s then IX = true end | 308 | if %s then IX = true end |
309 | return %s | 309 | return %s |
310 | ]] | 310 | ]] |
@@ -312,7 +312,7 @@ else | |||
312 | basiccases[4][1] = "k10" -- constant 10 | 312 | basiccases[4][1] = "k10" -- constant 10 |
313 | 313 | ||
314 | prog = [[ | 314 | prog = [[ |
315 | local <const> k10 = 10 | 315 | local k10 <const> = 10 |
316 | if %s then IX = true end | 316 | if %s then IX = true end |
317 | return %s | 317 | return %s |
318 | ]] | 318 | ]] |
@@ -322,12 +322,12 @@ print('testing short-circuit optimizations (' .. _ENV.GLOB1 .. ')') | |||
322 | 322 | ||
323 | 323 | ||
324 | -- operators with their respective values | 324 | -- operators with their respective values |
325 | local <const> binops = { | 325 | local binops <const> = { |
326 | {" and ", function (a,b) if not a then return a else return b end end}, | 326 | {" and ", function (a,b) if not a then return a else return b end end}, |
327 | {" or ", function (a,b) if a then return a else return b end end}, | 327 | {" or ", function (a,b) if a then return a else return b end end}, |
328 | } | 328 | } |
329 | 329 | ||
330 | local <const> cases = {} | 330 | local cases <const> = {} |
331 | 331 | ||
332 | -- creates all combinations of '(cases[i] op cases[n-i])' plus | 332 | -- creates all combinations of '(cases[i] op cases[n-i])' plus |
333 | -- 'not(cases[i] op cases[n-i])' (syntax + value) | 333 | -- 'not(cases[i] op cases[n-i])' (syntax + value) |
diff --git a/testes/coroutine.lua b/testes/coroutine.lua index 00531d8e..457374ca 100644 --- a/testes/coroutine.lua +++ b/testes/coroutine.lua | |||
@@ -151,7 +151,7 @@ do | |||
151 | end | 151 | end |
152 | 152 | ||
153 | co = coroutine.create(function () | 153 | co = coroutine.create(function () |
154 | local <toclose> x = func2close(function (self, err) | 154 | local x <close> = func2close(function (self, err) |
155 | assert(err == nil); X = false | 155 | assert(err == nil); X = false |
156 | end) | 156 | end) |
157 | X = true | 157 | X = true |
@@ -165,12 +165,12 @@ do | |||
165 | -- error closing a coroutine | 165 | -- error closing a coroutine |
166 | local x = 0 | 166 | local x = 0 |
167 | co = coroutine.create(function() | 167 | co = coroutine.create(function() |
168 | local <toclose> y = func2close(function (self,err) | 168 | local y <close> = func2close(function (self,err) |
169 | if (err ~= 111) then os.exit(false) end -- should not happen | 169 | if (err ~= 111) then os.exit(false) end -- should not happen |
170 | x = 200 | 170 | x = 200 |
171 | error(200) | 171 | error(200) |
172 | end) | 172 | end) |
173 | local <toclose> x = func2close(function (self, err) | 173 | local x <close> = func2close(function (self, err) |
174 | assert(err == nil); error(111) | 174 | assert(err == nil); error(111) |
175 | end) | 175 | end) |
176 | coroutine.yield() | 176 | coroutine.yield() |
@@ -356,7 +356,7 @@ do | |||
356 | 356 | ||
357 | local X = false | 357 | local X = false |
358 | A = coroutine.wrap(function() | 358 | A = coroutine.wrap(function() |
359 | local <toclose> _ = setmetatable({}, {__close = function () X = true end}) | 359 | local _ <close> = setmetatable({}, {__close = function () X = true end}) |
360 | return pcall(A, 1) | 360 | return pcall(A, 1) |
361 | end) | 361 | end) |
362 | st, res = A() | 362 | st, res = A() |
diff --git a/testes/files.lua b/testes/files.lua index 6e7bd9e2..585e5948 100644 --- a/testes/files.lua +++ b/testes/files.lua | |||
@@ -125,7 +125,7 @@ do | |||
125 | -- closing file by scope | 125 | -- closing file by scope |
126 | local F = nil | 126 | local F = nil |
127 | do | 127 | do |
128 | local <toclose> f = assert(io.open(file, "w")) | 128 | local f <close> = assert(io.open(file, "w")) |
129 | F = f | 129 | F = f |
130 | end | 130 | end |
131 | assert(tostring(F) == "file (closed)") | 131 | assert(tostring(F) == "file (closed)") |
@@ -135,7 +135,7 @@ assert(os.remove(file)) | |||
135 | 135 | ||
136 | do | 136 | do |
137 | -- test writing/reading numbers | 137 | -- test writing/reading numbers |
138 | local <toclose> f = assert(io.open(file, "w")) | 138 | local f <close> = assert(io.open(file, "w")) |
139 | f:write(maxint, '\n') | 139 | f:write(maxint, '\n') |
140 | f:write(string.format("0X%x\n", maxint)) | 140 | f:write(string.format("0X%x\n", maxint)) |
141 | f:write("0xABCp-3", '\n') | 141 | f:write("0xABCp-3", '\n') |
@@ -144,7 +144,7 @@ do | |||
144 | f:write(string.format("0x%X\n", -maxint)) | 144 | f:write(string.format("0x%X\n", -maxint)) |
145 | f:write("-0xABCp-3", '\n') | 145 | f:write("-0xABCp-3", '\n') |
146 | assert(f:close()) | 146 | assert(f:close()) |
147 | local <toclose> f = assert(io.open(file, "r")) | 147 | local f <close> = assert(io.open(file, "r")) |
148 | assert(f:read("n") == maxint) | 148 | assert(f:read("n") == maxint) |
149 | assert(f:read("n") == maxint) | 149 | assert(f:read("n") == maxint) |
150 | assert(f:read("n") == 0xABCp-3) | 150 | assert(f:read("n") == 0xABCp-3) |
@@ -158,7 +158,7 @@ assert(os.remove(file)) | |||
158 | 158 | ||
159 | -- testing multiple arguments to io.read | 159 | -- testing multiple arguments to io.read |
160 | do | 160 | do |
161 | local <toclose> f = assert(io.open(file, "w")) | 161 | local f <close> = assert(io.open(file, "w")) |
162 | f:write[[ | 162 | f:write[[ |
163 | a line | 163 | a line |
164 | another line | 164 | another line |
@@ -170,18 +170,18 @@ three | |||
170 | ]] | 170 | ]] |
171 | local l1, l2, l3, l4, n1, n2, c, dummy | 171 | local l1, l2, l3, l4, n1, n2, c, dummy |
172 | assert(f:close()) | 172 | assert(f:close()) |
173 | local <toclose> f = assert(io.open(file, "r")) | 173 | local f <close> = assert(io.open(file, "r")) |
174 | l1, l2, n1, n2, dummy = f:read("l", "L", "n", "n") | 174 | l1, l2, n1, n2, dummy = f:read("l", "L", "n", "n") |
175 | assert(l1 == "a line" and l2 == "another line\n" and | 175 | assert(l1 == "a line" and l2 == "another line\n" and |
176 | n1 == 1234 and n2 == 3.45 and dummy == nil) | 176 | n1 == 1234 and n2 == 3.45 and dummy == nil) |
177 | assert(f:close()) | 177 | assert(f:close()) |
178 | local <toclose> f = assert(io.open(file, "r")) | 178 | local f <close> = assert(io.open(file, "r")) |
179 | l1, l2, n1, n2, c, l3, l4, dummy = f:read(7, "l", "n", "n", 1, "l", "l") | 179 | l1, l2, n1, n2, c, l3, l4, dummy = f:read(7, "l", "n", "n", 1, "l", "l") |
180 | assert(l1 == "a line\n" and l2 == "another line" and c == '\n' and | 180 | assert(l1 == "a line\n" and l2 == "another line" and c == '\n' and |
181 | n1 == 1234 and n2 == 3.45 and l3 == "one" and l4 == "two" | 181 | n1 == 1234 and n2 == 3.45 and l3 == "one" and l4 == "two" |
182 | and dummy == nil) | 182 | and dummy == nil) |
183 | assert(f:close()) | 183 | assert(f:close()) |
184 | local <toclose> f = assert(io.open(file, "r")) | 184 | local f <close> = assert(io.open(file, "r")) |
185 | -- second item failing | 185 | -- second item failing |
186 | l1, n1, n2, dummy = f:read("l", "n", "n", "l") | 186 | l1, n1, n2, dummy = f:read("l", "n", "n", "l") |
187 | assert(l1 == "a line" and n1 == nil) | 187 | assert(l1 == "a line" and n1 == nil) |
diff --git a/testes/goto.lua b/testes/goto.lua index c9e48073..4ac6d7d0 100644 --- a/testes/goto.lua +++ b/testes/goto.lua | |||
@@ -258,7 +258,7 @@ do | |||
258 | ::L2:: goto L3 | 258 | ::L2:: goto L3 |
259 | 259 | ||
260 | ::L1:: do | 260 | ::L1:: do |
261 | local <toclose> a = setmetatable({}, {__close = function () X = true end}) | 261 | local a <close> = setmetatable({}, {__close = function () X = true end}) |
262 | assert(X == nil) | 262 | assert(X == nil) |
263 | if a then goto L2 end -- jumping back out of scope of 'a' | 263 | if a then goto L2 end -- jumping back out of scope of 'a' |
264 | end | 264 | end |
diff --git a/testes/locals.lua b/testes/locals.lua index 73267d02..3b145ca3 100644 --- a/testes/locals.lua +++ b/testes/locals.lua | |||
@@ -174,7 +174,7 @@ assert(x==20) | |||
174 | 174 | ||
175 | 175 | ||
176 | do -- constants | 176 | do -- constants |
177 | local <const> a, b, <const> c = 10, 20, 30 | 177 | local a<const>, b, c<const> = 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 (name, code) | 180 | local function checkro (name, code) |
@@ -182,17 +182,17 @@ do -- constants | |||
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("y", "local x, <const> y, z = 10, 20, 30; x = 11; y = 12") | 185 | checkro("y", "local x, y <const>, z = 10, 20, 30; x = 11; y = 12") |
186 | checkro("x", "local <const> x, y, <const> z = 10, 20, 30; x = 11") | 186 | checkro("x", "local x <const>, y, z <const> = 10, 20, 30; x = 11") |
187 | checkro("z", "local <const> x, y, <const> z = 10, 20, 30; y = 10; z = 11") | 187 | checkro("z", "local x <const>, y, z <const> = 10, 20, 30; y = 10; z = 11") |
188 | 188 | ||
189 | checkro("z", [[ | 189 | checkro("z", [[ |
190 | local a, <const> z, b = 10; | 190 | local a, z <const>, b = 10; |
191 | function foo() a = 20; z = 32; end | 191 | function foo() a = 20; z = 32; end |
192 | ]]) | 192 | ]]) |
193 | 193 | ||
194 | checkro("var1", [[ | 194 | checkro("var1", [[ |
195 | local a, <const> var1 = 10; | 195 | local a, var1 <const> = 10; |
196 | function foo() a = 20; z = function () var1 = 12; end end | 196 | function foo() a = 20; z = function () var1 = 12; end end |
197 | ]]) | 197 | ]]) |
198 | end | 198 | end |
@@ -215,9 +215,9 @@ end | |||
215 | do | 215 | do |
216 | local a = {} | 216 | local a = {} |
217 | do | 217 | do |
218 | local <toclose> x = setmetatable({"x"}, {__close = function (self) | 218 | local x <close> = setmetatable({"x"}, {__close = function (self) |
219 | a[#a + 1] = self[1] end}) | 219 | a[#a + 1] = self[1] end}) |
220 | local w, <toclose> y, z = func2close(function (self, err) | 220 | local w, y <close>, z = func2close(function (self, err) |
221 | assert(err == nil); a[#a + 1] = "y" | 221 | assert(err == nil); a[#a + 1] = "y" |
222 | end, 10, 20) | 222 | end, 10, 20) |
223 | a[#a + 1] = "in" | 223 | a[#a + 1] = "in" |
@@ -235,7 +235,7 @@ do | |||
235 | 235 | ||
236 | -- closing functions do not corrupt returning values | 236 | -- closing functions do not corrupt returning values |
237 | local function foo (x) | 237 | local function foo (x) |
238 | local <toclose> _ = closescope | 238 | local _ <close> = closescope |
239 | return x, X, 23 | 239 | return x, X, 23 |
240 | end | 240 | end |
241 | 241 | ||
@@ -244,7 +244,7 @@ do | |||
244 | 244 | ||
245 | X = false | 245 | X = false |
246 | foo = function (x) | 246 | foo = function (x) |
247 | local <toclose> _ = closescope | 247 | local _<close> = closescope |
248 | local y = 15 | 248 | local y = 15 |
249 | return y | 249 | return y |
250 | end | 250 | end |
@@ -253,7 +253,7 @@ do | |||
253 | 253 | ||
254 | X = false | 254 | X = false |
255 | foo = function () | 255 | foo = function () |
256 | local <toclose> x = closescope | 256 | local x <close> = closescope |
257 | return x | 257 | return x |
258 | end | 258 | end |
259 | 259 | ||
@@ -266,13 +266,13 @@ do | |||
266 | -- calls cannot be tail in the scope of to-be-closed variables | 266 | -- calls cannot be tail in the scope of to-be-closed variables |
267 | local X, Y | 267 | local X, Y |
268 | local function foo () | 268 | local function foo () |
269 | local <toclose> _ = func2close(function () Y = 10 end) | 269 | local _ <close> = func2close(function () Y = 10 end) |
270 | assert(X == true and Y == nil) -- 'X' not closed yet | 270 | assert(X == true and Y == nil) -- 'X' not closed yet |
271 | return 1,2,3 | 271 | return 1,2,3 |
272 | end | 272 | end |
273 | 273 | ||
274 | local function bar () | 274 | local function bar () |
275 | local <toclose> _ = func2close(function () X = false end) | 275 | local _ <close> = func2close(function () X = false end) |
276 | X = true | 276 | X = true |
277 | do | 277 | do |
278 | return foo() -- not a tail call! | 278 | return foo() -- not a tail call! |
@@ -287,14 +287,14 @@ end | |||
287 | do -- errors in __close | 287 | do -- errors in __close |
288 | local log = {} | 288 | local log = {} |
289 | local function foo (err) | 289 | local function foo (err) |
290 | local <toclose> x = | 290 | local x <close> = |
291 | func2close(function (self, msg) log[#log + 1] = msg; error(1) end) | 291 | func2close(function (self, msg) log[#log + 1] = msg; error(1) end) |
292 | local <toclose> x1 = | 292 | local x1 <close> = |
293 | func2close(function (self, msg) log[#log + 1] = msg; end) | 293 | func2close(function (self, msg) log[#log + 1] = msg; end) |
294 | local <toclose> gc = func2close(function () collectgarbage() end) | 294 | local gc <close> = func2close(function () collectgarbage() end) |
295 | local <toclose> y = | 295 | local y <close> = |
296 | func2close(function (self, msg) log[#log + 1] = msg; error(2) end) | 296 | func2close(function (self, msg) log[#log + 1] = msg; error(2) end) |
297 | local <toclose> z = | 297 | local z <close> = |
298 | func2close(function (self, msg) | 298 | func2close(function (self, msg) |
299 | log[#log + 1] = (msg or 10) + 1; | 299 | log[#log + 1] = (msg or 10) + 1; |
300 | error(3) | 300 | error(3) |
@@ -316,7 +316,7 @@ do -- errors in __close | |||
316 | 316 | ||
317 | -- error in toclose in vararg function | 317 | -- error in toclose in vararg function |
318 | function foo (...) | 318 | function foo (...) |
319 | local <toclose> x123 = 10 | 319 | local x123 <close> = 10 |
320 | end | 320 | end |
321 | 321 | ||
322 | local st, msg = pcall(foo) | 322 | local st, msg = pcall(foo) |
@@ -329,7 +329,7 @@ do | |||
329 | 329 | ||
330 | -- errors due to non-closable values | 330 | -- errors due to non-closable values |
331 | local function foo () | 331 | local function foo () |
332 | local <toclose> x = {} | 332 | local x <close> = {} |
333 | end | 333 | end |
334 | local stat, msg = pcall(foo) | 334 | local stat, msg = pcall(foo) |
335 | assert(not stat and string.find(msg, "variable 'x'")) | 335 | assert(not stat and string.find(msg, "variable 'x'")) |
@@ -337,8 +337,8 @@ do | |||
337 | 337 | ||
338 | -- with other errors, non-closable values are ignored | 338 | -- with other errors, non-closable values are ignored |
339 | local function foo () | 339 | local function foo () |
340 | local <toclose> x = 34 | 340 | local x <close> = 34 |
341 | local <toclose> y = func2close(function () error(32) end) | 341 | local y <close> = func2close(function () error(32) end) |
342 | end | 342 | end |
343 | local stat, msg = pcall(foo) | 343 | local stat, msg = pcall(foo) |
344 | assert(not stat and msg == 32) | 344 | assert(not stat and msg == 32) |
@@ -350,8 +350,8 @@ if rawget(_G, "T") then | |||
350 | 350 | ||
351 | -- memory error inside closing function | 351 | -- memory error inside closing function |
352 | local function foo () | 352 | local function foo () |
353 | local <toclose> y = func2close(function () T.alloccount() end) | 353 | local y <close> = func2close(function () T.alloccount() end) |
354 | local <toclose> x = setmetatable({}, {__close = function () | 354 | local x <close> = setmetatable({}, {__close = function () |
355 | T.alloccount(0); local x = {} -- force a memory error | 355 | T.alloccount(0); local x = {} -- force a memory error |
356 | end}) | 356 | end}) |
357 | error(1000) -- common error inside the function's body | 357 | error(1000) -- common error inside the function's body |
@@ -377,7 +377,7 @@ if rawget(_G, "T") then | |||
377 | end | 377 | end |
378 | 378 | ||
379 | local function test () | 379 | local function test () |
380 | local <toclose> x = enter(0) -- set a memory limit | 380 | local x <close> = enter(0) -- set a memory limit |
381 | -- creation of previous upvalue will raise a memory error | 381 | -- creation of previous upvalue will raise a memory error |
382 | assert(false) -- should not run | 382 | assert(false) -- should not run |
383 | end | 383 | end |
@@ -392,14 +392,14 @@ if rawget(_G, "T") then | |||
392 | 392 | ||
393 | -- repeat test with extra closing upvalues | 393 | -- repeat test with extra closing upvalues |
394 | local function test () | 394 | local function test () |
395 | local <toclose> xxx = func2close(function (self, msg) | 395 | local xxx <close> = func2close(function (self, msg) |
396 | assert(msg == "not enough memory"); | 396 | assert(msg == "not enough memory"); |
397 | error(1000) -- raise another error | 397 | error(1000) -- raise another error |
398 | end) | 398 | end) |
399 | local <toclose> xx = func2close(function (self, msg) | 399 | local xx <close> = func2close(function (self, msg) |
400 | assert(msg == "not enough memory"); | 400 | assert(msg == "not enough memory"); |
401 | end) | 401 | end) |
402 | local <toclose> x = enter(0) -- set a memory limit | 402 | local x <close> = enter(0) -- set a memory limit |
403 | -- creation of previous upvalue will raise a memory error | 403 | -- creation of previous upvalue will raise a memory error |
404 | os.exit(false) -- should not run | 404 | os.exit(false) -- should not run |
405 | end | 405 | end |
@@ -469,9 +469,9 @@ do | |||
469 | local x = false | 469 | local x = false |
470 | local y = false | 470 | local y = false |
471 | local co = coroutine.wrap(function () | 471 | local co = coroutine.wrap(function () |
472 | local <toclose> xv = func2close(function () x = true end) | 472 | local xv <close> = func2close(function () x = true end) |
473 | do | 473 | do |
474 | local <toclose> yv = func2close(function () y = true end) | 474 | local yv <close> = func2close(function () y = true end) |
475 | coroutine.yield(100) -- yield doesn't close variable | 475 | coroutine.yield(100) -- yield doesn't close variable |
476 | end | 476 | end |
477 | coroutine.yield(200) -- yield doesn't close variable | 477 | coroutine.yield(200) -- yield doesn't close variable |
@@ -491,8 +491,8 @@ do | |||
491 | -- error in a wrapped coroutine raising errors when closing a variable | 491 | -- error in a wrapped coroutine raising errors when closing a variable |
492 | local x = 0 | 492 | local x = 0 |
493 | local co = coroutine.wrap(function () | 493 | local co = coroutine.wrap(function () |
494 | local <toclose> xx = func2close(function () x = x + 1; error("YYY") end) | 494 | local xx <close> = func2close(function () x = x + 1; error("YYY") end) |
495 | local <toclose> xv = func2close(function () x = x + 1; error("XXX") end) | 495 | local xv <close> = func2close(function () x = x + 1; error("XXX") end) |
496 | coroutine.yield(100) | 496 | coroutine.yield(100) |
497 | error(200) | 497 | error(200) |
498 | end) | 498 | end) |
@@ -503,8 +503,8 @@ do | |||
503 | local x = 0 | 503 | local x = 0 |
504 | local y = 0 | 504 | local y = 0 |
505 | co = coroutine.wrap(function () | 505 | co = coroutine.wrap(function () |
506 | local <toclose> xx = func2close(function () y = y + 1; error("YYY") end) | 506 | local xx <close> = func2close(function () y = y + 1; error("YYY") end) |
507 | local <toclose> xv = func2close(function () x = x + 1; error("XXX") end) | 507 | local xv <close> = func2close(function () x = x + 1; error("XXX") end) |
508 | coroutine.yield(100) | 508 | coroutine.yield(100) |
509 | return 200 | 509 | return 200 |
510 | end) | 510 | end) |
@@ -519,7 +519,7 @@ end | |||
519 | -- a suspended coroutine should not close its variables when collected | 519 | -- a suspended coroutine should not close its variables when collected |
520 | local co | 520 | local co |
521 | co = coroutine.wrap(function() | 521 | co = coroutine.wrap(function() |
522 | local <toclose> x = function () os.exit(false) end -- should not run | 522 | local x <close> = function () os.exit(false) end -- should not run |
523 | co = nil | 523 | co = nil |
524 | coroutine.yield() | 524 | coroutine.yield() |
525 | end) | 525 | end) |
diff --git a/testes/main.lua b/testes/main.lua index 4c09645a..da2a9288 100644 --- a/testes/main.lua +++ b/testes/main.lua | |||
@@ -320,11 +320,11 @@ NoRun("", "lua %s", prog) -- no message | |||
320 | 320 | ||
321 | -- to-be-closed variables in main chunk | 321 | -- to-be-closed variables in main chunk |
322 | prepfile[[ | 322 | prepfile[[ |
323 | local <toclose> x = function (err) | 323 | local x <close> = function (err) |
324 | assert(err == 120) | 324 | assert(err == 120) |
325 | print("Ok") | 325 | print("Ok") |
326 | end | 326 | end |
327 | local <toclose> e1 = function () error(120) end | 327 | local e1 <close> = function () error(120) end |
328 | os.exit(true, true) | 328 | os.exit(true, true) |
329 | ]] | 329 | ]] |
330 | RUN('lua %s > %s', prog, out) | 330 | RUN('lua %s > %s', prog, out) |
diff --git a/testes/math.lua b/testes/math.lua index d0aaa6a5..bad43901 100644 --- a/testes/math.lua +++ b/testes/math.lua | |||
@@ -3,10 +3,10 @@ | |||
3 | 3 | ||
4 | print("testing numbers and math lib") | 4 | print("testing numbers and math lib") |
5 | 5 | ||
6 | local <const> minint = math.mininteger | 6 | local minint <const> = math.mininteger |
7 | local <const> maxint = math.maxinteger | 7 | local maxint <const> = math.maxinteger |
8 | 8 | ||
9 | local <const> intbits = math.floor(math.log(maxint, 2) + 0.5) + 1 | 9 | local intbits <const> = math.floor(math.log(maxint, 2) + 0.5) + 1 |
10 | assert((1 << intbits) == 0) | 10 | assert((1 << intbits) == 0) |
11 | 11 | ||
12 | assert(minint == 1 << (intbits - 1)) | 12 | assert(minint == 1 << (intbits - 1)) |
@@ -270,7 +270,7 @@ else | |||
270 | end | 270 | end |
271 | 271 | ||
272 | do | 272 | do |
273 | local <const> NaN = 0/0 | 273 | local NaN <const> = 0/0 |
274 | assert(not (NaN < 0)) | 274 | assert(not (NaN < 0)) |
275 | assert(not (NaN > minint)) | 275 | assert(not (NaN > minint)) |
276 | assert(not (NaN <= -9)) | 276 | assert(not (NaN <= -9)) |
@@ -767,8 +767,8 @@ assert(a == '10' and b == '20') | |||
767 | 767 | ||
768 | do | 768 | do |
769 | print("testing -0 and NaN") | 769 | print("testing -0 and NaN") |
770 | local <const> mz = -0.0 | 770 | local mz <const> = -0.0 |
771 | local <const> z = 0.0 | 771 | local z <const> = 0.0 |
772 | assert(mz == z) | 772 | assert(mz == z) |
773 | assert(1/mz < 0 and 0 < 1/z) | 773 | assert(1/mz < 0 and 0 < 1/z) |
774 | local a = {[mz] = 1} | 774 | local a = {[mz] = 1} |
@@ -776,18 +776,18 @@ do | |||
776 | a[z] = 2 | 776 | a[z] = 2 |
777 | assert(a[z] == 2 and a[mz] == 2) | 777 | assert(a[z] == 2 and a[mz] == 2) |
778 | local inf = math.huge * 2 + 1 | 778 | local inf = math.huge * 2 + 1 |
779 | local <const> mz = -1/inf | 779 | local mz <const> = -1/inf |
780 | local <const> z = 1/inf | 780 | local z <const> = 1/inf |
781 | assert(mz == z) | 781 | assert(mz == z) |
782 | assert(1/mz < 0 and 0 < 1/z) | 782 | assert(1/mz < 0 and 0 < 1/z) |
783 | local <const> NaN = inf - inf | 783 | local NaN <const> = inf - inf |
784 | assert(NaN ~= NaN) | 784 | assert(NaN ~= NaN) |
785 | assert(not (NaN < NaN)) | 785 | assert(not (NaN < NaN)) |
786 | assert(not (NaN <= NaN)) | 786 | assert(not (NaN <= NaN)) |
787 | assert(not (NaN > NaN)) | 787 | assert(not (NaN > NaN)) |
788 | assert(not (NaN >= NaN)) | 788 | assert(not (NaN >= NaN)) |
789 | assert(not (0 < NaN) and not (NaN < 0)) | 789 | assert(not (0 < NaN) and not (NaN < 0)) |
790 | local <const> NaN1 = 0/0 | 790 | local NaN1 <const> = 0/0 |
791 | assert(NaN ~= NaN1 and not (NaN <= NaN1) and not (NaN1 <= NaN)) | 791 | assert(NaN ~= NaN1 and not (NaN <= NaN1) and not (NaN1 <= NaN)) |
792 | local a = {} | 792 | local a = {} |
793 | assert(not pcall(rawset, a, NaN, 1)) | 793 | assert(not pcall(rawset, a, NaN, 1)) |
@@ -816,8 +816,8 @@ end | |||
816 | -- the first call after seed 1007 should return 0x7a7040a5a323c9d6 | 816 | -- the first call after seed 1007 should return 0x7a7040a5a323c9d6 |
817 | do | 817 | do |
818 | -- all computations should work with 32-bit integers | 818 | -- all computations should work with 32-bit integers |
819 | local <const> h = 0x7a7040a5 -- higher half | 819 | local h <const> = 0x7a7040a5 -- higher half |
820 | local <const> l = 0xa323c9d6 -- lower half | 820 | local l <const> = 0xa323c9d6 -- lower half |
821 | 821 | ||
822 | math.randomseed(1007) | 822 | math.randomseed(1007) |
823 | -- get the low 'intbits' of the 64-bit expected result | 823 | -- get the low 'intbits' of the 64-bit expected result |
diff --git a/testes/strings.lua b/testes/strings.lua index aa039c4f..2e0e160f 100644 --- a/testes/strings.lua +++ b/testes/strings.lua | |||
@@ -3,8 +3,8 @@ | |||
3 | 3 | ||
4 | print('testing strings and string library') | 4 | print('testing strings and string library') |
5 | 5 | ||
6 | local <const> maxi = math.maxinteger | 6 | local maxi <const> = math.maxinteger |
7 | local <const> mini = math.mininteger | 7 | local mini <const> = math.mininteger |
8 | 8 | ||
9 | 9 | ||
10 | local function checkerror (msg, f, ...) | 10 | local function checkerror (msg, f, ...) |