From 0d529138042563baf260366e19a7aa2c60a07174 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 30 Jul 2019 12:18:19 -0300 Subject: Change in the syntax of attributes Attributes changed to posfixed ('x ', instead of ' 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. --- testes/api.lua | 2 +- testes/code.lua | 36 +++++++++++++------------- testes/constructs.lua | 16 ++++++------ testes/coroutine.lua | 8 +++--- testes/files.lua | 14 +++++------ testes/goto.lua | 2 +- testes/locals.lua | 70 +++++++++++++++++++++++++-------------------------- testes/main.lua | 4 +-- testes/math.lua | 24 +++++++++--------- testes/strings.lua | 4 +-- 10 files changed, 90 insertions(+), 90 deletions(-) (limited to 'testes') 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) testamem("to-be-closed variables", function() local flag do - local x = + local x = setmetatable({}, {__close = function () flag = true end}) flag = false 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 print "testing code generation and optimizations" -- to test constant propagation -local k0aux = 0 -local k0 = k0aux -local k1 = 1 -local k3 = 3 -local k6 = k3 + (k3 << k0) -local kFF0 = 0xFF0 -local k3_78 = 3.78 -local x, k3_78_4 = 10, k3_78 / 4 +local k0aux = 0 +local k0 = k0aux +local k1 = 1 +local k3 = 3 +local k6 = k3 + (k3 << k0) +local kFF0 = 0xFF0 +local k3_78 = 3.78 +local x, k3_78_4 = 10, k3_78 / 4 assert(x == 10) -local kx = "x" +local kx = "x" -local kTrue = true -local kFalse = false +local kTrue = true +local kFalse = false -local kNil = nil +local kNil = nil -- this code gave an error for the code checker do @@ -105,7 +105,7 @@ end, 'CLOSURE', 'NEWTABLE', 'EXTRAARG', 'GETTABUP', 'CALL', -- sequence of LOADNILs check(function () - local kNil = nil + local kNil = nil local a,b,c local d; local e; local f,g,h; @@ -173,7 +173,7 @@ end, -- "get/set table" with numeric indices check(function (a) - local k255 = 255 + local k255 = 255 a[1] = a[100] a[k255] = a[256] a[256] = 5 @@ -276,14 +276,14 @@ checkI(function () return ((100 << k6) << -4) >> 2 end, 100) -- borders around MAXARG_sBx ((((1 << 17) - 1) >> 1) == 65535) local a = 17; local sbx = ((1 << a) - 1) >> 1 -- avoid folding -local border = 65535 +local border = 65535 checkI(function () return border end, sbx) checkI(function () return -border end, -sbx) checkI(function () return border + 1 end, sbx + 1) checkK(function () return border + 2 end, sbx + 2) checkK(function () return -(border + 1) end, -(sbx + 1)) -local border = 65535.0 +local border = 65535.0 checkF(function () return border end, sbx + 0.0) checkF(function () return -border end, -sbx + 0.0) checkF(function () return border + 1 end, (sbx + 1.0)) @@ -411,9 +411,9 @@ checkequal(function () return 6 and true or nil end, do -- string constants - local k0 = "00000000000000000000000000000000000000000000000000" + local k0 = "00000000000000000000000000000000000000000000000000" local function f1 () - local k = k0 + local k = k0 return function () return function () return k end 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) print'+'; do -- testing constants - local prog = [[local x = 10]] + local prog = [[local x = 10]] checkload(prog, "unknown attribute 'XXX'") - checkload([[local xxx = 20; xxx = 10]], + checkload([[local xxx = 20; xxx = 10]], ":1: attempt to assign to const variable 'xxx'") checkload([[ local xx; - local xxx = 20; + local xxx = 20; local yyy; local function foo () local abc = xx + yyy + xxx; @@ -228,7 +228,7 @@ do -- testing constants ]], ":6: attempt to assign to const variable 'xxx'") checkload([[ - local x = nil + local x = nil x = io.open() ]], ":2: attempt to assign to const variable 'x'") end @@ -304,7 +304,7 @@ if _ENV.GLOB1 == 0 then basiccases[2][1] = "F" -- constant false prog = [[ - local F = false + local F = false if %s then IX = true end return %s ]] @@ -312,7 +312,7 @@ else basiccases[4][1] = "k10" -- constant 10 prog = [[ - local k10 = 10 + local k10 = 10 if %s then IX = true end return %s ]] @@ -322,12 +322,12 @@ print('testing short-circuit optimizations (' .. _ENV.GLOB1 .. ')') -- operators with their respective values -local binops = { +local binops = { {" and ", function (a,b) if not a then return a else return b end end}, {" or ", function (a,b) if a then return a else return b end end}, } -local cases = {} +local cases = {} -- creates all combinations of '(cases[i] op cases[n-i])' plus -- '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 end co = coroutine.create(function () - local x = func2close(function (self, err) + local x = func2close(function (self, err) assert(err == nil); X = false end) X = true @@ -165,12 +165,12 @@ do -- error closing a coroutine local x = 0 co = coroutine.create(function() - local y = func2close(function (self,err) + local y = func2close(function (self,err) if (err ~= 111) then os.exit(false) end -- should not happen x = 200 error(200) end) - local x = func2close(function (self, err) + local x = func2close(function (self, err) assert(err == nil); error(111) end) coroutine.yield() @@ -356,7 +356,7 @@ do local X = false A = coroutine.wrap(function() - local _ = setmetatable({}, {__close = function () X = true end}) + local _ = setmetatable({}, {__close = function () X = true end}) return pcall(A, 1) end) 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 -- closing file by scope local F = nil do - local f = assert(io.open(file, "w")) + local f = assert(io.open(file, "w")) F = f end assert(tostring(F) == "file (closed)") @@ -135,7 +135,7 @@ assert(os.remove(file)) do -- test writing/reading numbers - local f = assert(io.open(file, "w")) + local f = assert(io.open(file, "w")) f:write(maxint, '\n') f:write(string.format("0X%x\n", maxint)) f:write("0xABCp-3", '\n') @@ -144,7 +144,7 @@ do f:write(string.format("0x%X\n", -maxint)) f:write("-0xABCp-3", '\n') assert(f:close()) - local f = assert(io.open(file, "r")) + local f = assert(io.open(file, "r")) assert(f:read("n") == maxint) assert(f:read("n") == maxint) assert(f:read("n") == 0xABCp-3) @@ -158,7 +158,7 @@ assert(os.remove(file)) -- testing multiple arguments to io.read do - local f = assert(io.open(file, "w")) + local f = assert(io.open(file, "w")) f:write[[ a line another line @@ -170,18 +170,18 @@ three ]] local l1, l2, l3, l4, n1, n2, c, dummy assert(f:close()) - local f = assert(io.open(file, "r")) + local f = assert(io.open(file, "r")) l1, l2, n1, n2, dummy = f:read("l", "L", "n", "n") assert(l1 == "a line" and l2 == "another line\n" and n1 == 1234 and n2 == 3.45 and dummy == nil) assert(f:close()) - local f = assert(io.open(file, "r")) + local f = assert(io.open(file, "r")) l1, l2, n1, n2, c, l3, l4, dummy = f:read(7, "l", "n", "n", 1, "l", "l") assert(l1 == "a line\n" and l2 == "another line" and c == '\n' and n1 == 1234 and n2 == 3.45 and l3 == "one" and l4 == "two" and dummy == nil) assert(f:close()) - local f = assert(io.open(file, "r")) + local f = assert(io.open(file, "r")) -- second item failing l1, n1, n2, dummy = f:read("l", "n", "n", "l") 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 ::L2:: goto L3 ::L1:: do - local a = setmetatable({}, {__close = function () X = true end}) + local a = setmetatable({}, {__close = function () X = true end}) assert(X == nil) if a then goto L2 end -- jumping back out of scope of 'a' 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) do -- constants - local a, b, c = 10, 20, 30 + 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 (name, code) @@ -182,17 +182,17 @@ do -- constants local gab = string.format("attempt to assign to const variable '%s'", name) assert(not st and string.find(msg, gab)) end - 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("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; + local a, z , b = 10; function foo() a = 20; z = 32; end ]]) checkro("var1", [[ - local a, var1 = 10; + local a, var1 = 10; function foo() a = 20; z = function () var1 = 12; end end ]]) end @@ -215,9 +215,9 @@ end do local a = {} do - local x = setmetatable({"x"}, {__close = function (self) + local x = setmetatable({"x"}, {__close = function (self) a[#a + 1] = self[1] end}) - local w, y, z = func2close(function (self, err) + local w, y , z = func2close(function (self, err) assert(err == nil); a[#a + 1] = "y" end, 10, 20) a[#a + 1] = "in" @@ -235,7 +235,7 @@ do -- closing functions do not corrupt returning values local function foo (x) - local _ = closescope + local _ = closescope return x, X, 23 end @@ -244,7 +244,7 @@ do X = false foo = function (x) - local _ = closescope + local _ = closescope local y = 15 return y end @@ -253,7 +253,7 @@ do X = false foo = function () - local x = closescope + local x = closescope return x end @@ -266,13 +266,13 @@ do -- calls cannot be tail in the scope of to-be-closed variables local X, Y local function foo () - local _ = func2close(function () Y = 10 end) + local _ = func2close(function () Y = 10 end) assert(X == true and Y == nil) -- 'X' not closed yet return 1,2,3 end local function bar () - local _ = func2close(function () X = false end) + local _ = func2close(function () X = false end) X = true do return foo() -- not a tail call! @@ -287,14 +287,14 @@ end do -- errors in __close local log = {} local function foo (err) - local x = + local x = func2close(function (self, msg) log[#log + 1] = msg; error(1) end) - local x1 = + local x1 = func2close(function (self, msg) log[#log + 1] = msg; end) - local gc = func2close(function () collectgarbage() end) - local y = + local gc = func2close(function () collectgarbage() end) + local y = func2close(function (self, msg) log[#log + 1] = msg; error(2) end) - local z = + local z = func2close(function (self, msg) log[#log + 1] = (msg or 10) + 1; error(3) @@ -316,7 +316,7 @@ do -- errors in __close -- error in toclose in vararg function function foo (...) - local x123 = 10 + local x123 = 10 end local st, msg = pcall(foo) @@ -329,7 +329,7 @@ do -- errors due to non-closable values local function foo () - local x = {} + local x = {} end local stat, msg = pcall(foo) assert(not stat and string.find(msg, "variable 'x'")) @@ -337,8 +337,8 @@ do -- with other errors, non-closable values are ignored local function foo () - local x = 34 - local y = func2close(function () error(32) end) + local x = 34 + local y = func2close(function () error(32) end) end local stat, msg = pcall(foo) assert(not stat and msg == 32) @@ -350,8 +350,8 @@ if rawget(_G, "T") then -- memory error inside closing function local function foo () - local y = func2close(function () T.alloccount() end) - local x = setmetatable({}, {__close = function () + local y = func2close(function () T.alloccount() end) + local x = setmetatable({}, {__close = function () T.alloccount(0); local x = {} -- force a memory error end}) error(1000) -- common error inside the function's body @@ -377,7 +377,7 @@ if rawget(_G, "T") then end local function test () - local x = enter(0) -- set a memory limit + local x = enter(0) -- set a memory limit -- creation of previous upvalue will raise a memory error assert(false) -- should not run end @@ -392,14 +392,14 @@ if rawget(_G, "T") then -- repeat test with extra closing upvalues local function test () - local xxx = func2close(function (self, msg) + local xxx = func2close(function (self, msg) assert(msg == "not enough memory"); error(1000) -- raise another error end) - local xx = func2close(function (self, msg) + local xx = func2close(function (self, msg) assert(msg == "not enough memory"); end) - local x = enter(0) -- set a memory limit + local x = enter(0) -- set a memory limit -- creation of previous upvalue will raise a memory error os.exit(false) -- should not run end @@ -469,9 +469,9 @@ do local x = false local y = false local co = coroutine.wrap(function () - local xv = func2close(function () x = true end) + local xv = func2close(function () x = true end) do - local yv = func2close(function () y = true end) + local yv = func2close(function () y = true end) coroutine.yield(100) -- yield doesn't close variable end coroutine.yield(200) -- yield doesn't close variable @@ -491,8 +491,8 @@ do -- error in a wrapped coroutine raising errors when closing a variable local x = 0 local co = coroutine.wrap(function () - local xx = func2close(function () x = x + 1; error("YYY") end) - local xv = func2close(function () x = x + 1; error("XXX") end) + local xx = func2close(function () x = x + 1; error("YYY") end) + local xv = func2close(function () x = x + 1; error("XXX") end) coroutine.yield(100) error(200) end) @@ -503,8 +503,8 @@ do local x = 0 local y = 0 co = coroutine.wrap(function () - local xx = func2close(function () y = y + 1; error("YYY") end) - local xv = func2close(function () x = x + 1; error("XXX") end) + local xx = func2close(function () y = y + 1; error("YYY") end) + local xv = func2close(function () x = x + 1; error("XXX") end) coroutine.yield(100) return 200 end) @@ -519,7 +519,7 @@ end -- a suspended coroutine should not close its variables when collected local co co = coroutine.wrap(function() - local x = function () os.exit(false) end -- should not run + local x = function () os.exit(false) end -- should not run co = nil coroutine.yield() 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 -- to-be-closed variables in main chunk prepfile[[ - local x = function (err) + local x = function (err) assert(err == 120) print("Ok") end - local e1 = function () error(120) end + local e1 = function () error(120) end os.exit(true, true) ]] 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 @@ print("testing numbers and math lib") -local minint = math.mininteger -local maxint = math.maxinteger +local minint = math.mininteger +local maxint = math.maxinteger -local intbits = math.floor(math.log(maxint, 2) + 0.5) + 1 +local intbits = math.floor(math.log(maxint, 2) + 0.5) + 1 assert((1 << intbits) == 0) assert(minint == 1 << (intbits - 1)) @@ -270,7 +270,7 @@ else end do - local NaN = 0/0 + local NaN = 0/0 assert(not (NaN < 0)) assert(not (NaN > minint)) assert(not (NaN <= -9)) @@ -767,8 +767,8 @@ assert(a == '10' and b == '20') do print("testing -0 and NaN") - local mz = -0.0 - local z = 0.0 + local mz = -0.0 + local z = 0.0 assert(mz == z) assert(1/mz < 0 and 0 < 1/z) local a = {[mz] = 1} @@ -776,18 +776,18 @@ do a[z] = 2 assert(a[z] == 2 and a[mz] == 2) local inf = math.huge * 2 + 1 - local mz = -1/inf - local z = 1/inf + local mz = -1/inf + local z = 1/inf assert(mz == z) assert(1/mz < 0 and 0 < 1/z) - local NaN = inf - inf + local NaN = inf - inf assert(NaN ~= NaN) assert(not (NaN < NaN)) assert(not (NaN <= NaN)) assert(not (NaN > NaN)) assert(not (NaN >= NaN)) assert(not (0 < NaN) and not (NaN < 0)) - local NaN1 = 0/0 + local NaN1 = 0/0 assert(NaN ~= NaN1 and not (NaN <= NaN1) and not (NaN1 <= NaN)) local a = {} assert(not pcall(rawset, a, NaN, 1)) @@ -816,8 +816,8 @@ end -- the first call after seed 1007 should return 0x7a7040a5a323c9d6 do -- all computations should work with 32-bit integers - local h = 0x7a7040a5 -- higher half - local l = 0xa323c9d6 -- lower half + local h = 0x7a7040a5 -- higher half + local l = 0xa323c9d6 -- lower half math.randomseed(1007) -- 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 @@ print('testing strings and string library') -local maxi = math.maxinteger -local mini = math.mininteger +local maxi = math.maxinteger +local mini = math.mininteger local function checkerror (msg, f, ...) -- cgit v1.2.3-55-g6feb