Improve readability (#206)

Co-authored-by: Josh Soref <jsoref@users.noreply.github.com>
Co-authored-by: Arseny Kapoulkine <arseny.kapoulkine@gmail.com>
This commit is contained in:
Josh Soref 2021-11-19 13:45:53 -05:00 committed by GitHub
parent 100710c9f6
commit ec8a5643cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 38 additions and 44 deletions

View File

@ -88,7 +88,7 @@ for i=1,N do
local y=ymin+(j-1)*dy
S = S + level(x,y)
end
-- if i % 10 == 0 then print(collectgarbage"count") end
-- if i % 10 == 0 then print(collectgarbage("count")) end
end
print(S)

View File

@ -88,7 +88,7 @@ for i=1,N do
local y=ymin+(j-1)*dy
S = S + level(x,y)
end
-- if i % 10 == 0 then print(collectgarbage"count") end
-- if i % 10 == 0 then print(collectgarbage("count")) end
end
print(S)

View File

@ -275,7 +275,7 @@ local function memory(s)
local t=os.clock()
--local dt=string.format("%f",t-t0)
local dt=t-t0
--io.stdout:write(s,"\t",dt," sec\t",t," sec\t",math.floor(collectgarbage"count"/1024),"M\n")
--io.stdout:write(s,"\t",dt," sec\t",t," sec\t",math.floor(collectgarbage("count")/1024),"M\n")
t0=t
end
@ -286,7 +286,7 @@ local function do_(f,s)
end
local function julia(l,a,b)
memory"begin"
memory("begin")
cx=a cy=b
root=newcell()
exterior=newcell() exterior.color=white
@ -297,14 +297,14 @@ memory"begin"
do_(update,"update")
repeat
N=0 color(root,Rxmin,Rxmax,Rymin,Rymax) --print("color",N)
until N==0 memory"color"
until N==0 memory("color")
repeat
N=0 prewhite(root,Rxmin,Rxmax,Rymin,Rymax) --print("prewhite",N)
until N==0 memory"prewhite"
until N==0 memory("prewhite")
do_(recolor,"recolor")
do_(colorup,"colorup") --print("colorup",N)
local g,b=do_(area,"area") --print("area",g,b,g+b)
show(i) memory"output"
show(i) memory("output")
--print("edges",nE)
end
end

View File

@ -876,4 +876,4 @@ assert(concat(typeof(5), typeof(nil), typeof({}), typeof(newproxy())) == "number
testgetfenv() -- DONT MOVE THIS LINE
return'OK'
return 'OK'

View File

@ -419,11 +419,5 @@ co = coroutine.create(function ()
return loadstring("return a")()
end)
a = {a = 15}
-- debug.setfenv(co, a)
-- assert(debug.getfenv(co) == a)
-- assert(select(2, coroutine.resume(co)) == a)
-- assert(select(2, coroutine.resume(co)) == a.a)
return'OK'
return 'OK'

View File

@ -237,4 +237,4 @@ repeat
i = i+1
until i==c
return'OK'
return 'OK'

View File

@ -373,4 +373,4 @@ do
assert(f() == 42)
end
return'OK'
return 'OK'

View File

@ -74,4 +74,4 @@ assert(os.difftime(t1,t2) == 60*2-19)
assert(os.time({ year = 1970, day = 1, month = 1, hour = 0}) == 0)
return'OK'
return 'OK'

View File

@ -98,4 +98,4 @@ assert(quuz(function(...) end) == "0 true")
assert(quuz(function(a, b) end) == "2 false")
assert(quuz(function(a, b, ...) end) == "2 true")
return'OK'
return 'OK'

View File

@ -34,15 +34,15 @@ assert(doit("error('hi', 0)") == 'hi')
assert(doit("unpack({}, 1, n=2^30)"))
assert(doit("a=math.sin()"))
assert(not doit("tostring(1)") and doit("tostring()"))
assert(doit"tonumber()")
assert(doit"repeat until 1; a")
assert(doit("tonumber()"))
assert(doit("repeat until 1; a"))
checksyntax("break label", "", "label", 1)
assert(doit";")
assert(doit"a=1;;")
assert(doit"return;;")
assert(doit"assert(false)")
assert(doit"assert(nil)")
assert(doit"a=math.sin\n(3)")
assert(doit(";"))
assert(doit("a=1;;"))
assert(doit("return;;"))
assert(doit("assert(false)"))
assert(doit("assert(nil)"))
assert(doit("a=math.sin\n(3)"))
assert(doit("function a (... , ...) end"))
assert(doit("function a (, ...) end"))
@ -59,7 +59,7 @@ checkmessage("a=1; local a,bbbb=2,3; a = math.sin(1) and bbbb(3)",
"local 'bbbb'")
checkmessage("a={}; do local a=1 end a:bbbb(3)", "method 'bbbb'")
checkmessage("local a={}; a.bbbb(3)", "field 'bbbb'")
assert(not string.find(doit"a={13}; local bbbb=1; a[bbbb](3)", "'bbbb'"))
assert(not string.find(doit("a={13}; local bbbb=1; a[bbbb](3)"), "'bbbb'"))
checkmessage("a={13}; local bbbb=1; a[bbbb](3)", "number")
aaa = nil
@ -67,14 +67,14 @@ checkmessage("aaa.bbb:ddd(9)", "global 'aaa'")
checkmessage("local aaa={bbb=1}; aaa.bbb:ddd(9)", "field 'bbb'")
checkmessage("local aaa={bbb={}}; aaa.bbb:ddd(9)", "method 'ddd'")
checkmessage("local a,b,c; (function () a = b+1 end)()", "upvalue 'b'")
assert(not doit"local aaa={bbb={ddd=next}}; aaa.bbb:ddd(nil)")
assert(not doit("local aaa={bbb={ddd=next}}; aaa.bbb:ddd(nil)"))
checkmessage("b=1; local aaa='a'; x=aaa+b", "local 'aaa'")
checkmessage("aaa={}; x=3/aaa", "global 'aaa'")
checkmessage("aaa='2'; b=nil;x=aaa*b", "global 'b'")
checkmessage("aaa={}; x=-aaa", "global 'aaa'")
assert(not string.find(doit"aaa={}; x=(aaa or aaa)+(aaa and aaa)", "'aaa'"))
assert(not string.find(doit"aaa={}; (aaa or aaa)()", "'aaa'"))
assert(not string.find(doit("aaa={}; x=(aaa or aaa)+(aaa and aaa)"), "'aaa'"))
assert(not string.find(doit("aaa={}; (aaa or aaa)()"), "'aaa'"))
checkmessage([[aaa=9
repeat until 3==3
@ -122,10 +122,10 @@ function lineerror (s)
return line and line+0
end
assert(lineerror"local a\n for i=1,'a' do \n print(i) \n end" == 2)
-- assert(lineerror"\n local a \n for k,v in 3 \n do \n print(k) \n end" == 3)
-- assert(lineerror"\n\n for k,v in \n 3 \n do \n print(k) \n end" == 4)
assert(lineerror"function a.x.y ()\na=a+1\nend" == 1)
assert(lineerror("local a\n for i=1,'a' do \n print(i) \n end") == 2)
-- assert(lineerror("\n local a \n for k,v in 3 \n do \n print(k) \n end") == 3)
-- assert(lineerror("\n\n for k,v in \n 3 \n do \n print(k) \n end") == 4)
assert(lineerror("function a.x.y ()\na=a+1\nend") == 1)
local p = [[
function g() f() end

View File

@ -77,7 +77,7 @@ end
local function dosteps (siz)
collectgarbage()
collectgarbage"stop"
collectgarbage("stop")
local a = {}
for i=1,100 do a[i] = {{}}; local b = {} end
local x = gcinfo()
@ -99,11 +99,11 @@ assert(dosteps(10000) == 1)
do
local x = gcinfo()
collectgarbage()
collectgarbage"stop"
collectgarbage("stop")
repeat
local a = {}
until gcinfo() > 1000
collectgarbage"restart"
collectgarbage("restart")
repeat
local a = {}
until gcinfo() < 1000
@ -123,7 +123,7 @@ for n in pairs(b) do
end
b = nil
collectgarbage()
for n in pairs(a) do error'cannot be here' end
for n in pairs(a) do error("cannot be here") end
for i=1,lim do a[i] = i end
for i=1,lim do assert(a[i] == i) end

View File

@ -368,9 +368,9 @@ assert(next(a,nil) == 1000 and next(a,1000) == nil)
assert(next({}) == nil)
assert(next({}, nil) == nil)
for a,b in pairs{} do error"not here" end
for i=1,0 do error'not here' end
for i=0,1,-1 do error'not here' end
for a,b in pairs{} do error("not here") end
for i=1,0 do error("not here") end
for i=0,1,-1 do error("not here") end
a = nil; for i=1,1 do assert(not a); a=1 end; assert(a)
a = nil; for i=1,1,-1 do assert(not a); a=1 end; assert(a)

View File

@ -144,4 +144,4 @@ coroutine.resume(co)
resumeerror(co, "fail")
checkresults({ true, false, "fail" }, coroutine.resume(co))
return'OK'
return 'OK'

View File

@ -205,4 +205,4 @@ for p, c in string.gmatch(x, "()(" .. utf8.charpattern .. ")") do
end
end
return'OK'
return 'OK'