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 local y=ymin+(j-1)*dy
S = S + level(x,y) S = S + level(x,y)
end end
-- if i % 10 == 0 then print(collectgarbage"count") end -- if i % 10 == 0 then print(collectgarbage("count")) end
end end
print(S) print(S)

View File

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

View File

@ -275,7 +275,7 @@ local function memory(s)
local t=os.clock() local t=os.clock()
--local dt=string.format("%f",t-t0) --local dt=string.format("%f",t-t0)
local dt=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 t0=t
end end
@ -286,7 +286,7 @@ local function do_(f,s)
end end
local function julia(l,a,b) local function julia(l,a,b)
memory"begin" memory("begin")
cx=a cy=b cx=a cy=b
root=newcell() root=newcell()
exterior=newcell() exterior.color=white exterior=newcell() exterior.color=white
@ -297,14 +297,14 @@ memory"begin"
do_(update,"update") do_(update,"update")
repeat repeat
N=0 color(root,Rxmin,Rxmax,Rymin,Rymax) --print("color",N) N=0 color(root,Rxmin,Rxmax,Rymin,Rymax) --print("color",N)
until N==0 memory"color" until N==0 memory("color")
repeat repeat
N=0 prewhite(root,Rxmin,Rxmax,Rymin,Rymax) --print("prewhite",N) 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_(recolor,"recolor")
do_(colorup,"colorup") --print("colorup",N) do_(colorup,"colorup") --print("colorup",N)
local g,b=do_(area,"area") --print("area",g,b,g+b) local g,b=do_(area,"area") --print("area",g,b,g+b)
show(i) memory"output" show(i) memory("output")
--print("edges",nE) --print("edges",nE)
end end
end end

View File

@ -419,11 +419,5 @@ co = coroutine.create(function ()
return loadstring("return a")() return loadstring("return a")()
end) 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

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

View File

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