diff -r 91a9e557e0e5 -r 984b3ba0ea99 buildscripts/squish --- a/buildscripts/squish Thu Sep 06 19:13:42 2018 +0100 +++ b/buildscripts/squish Mon Sep 10 09:50:42 2018 +0100 @@ -1,7 +1,7 @@ -#!/usr/bin/env lua5.2 +#!/usr/bin/lua5.2 package.preload['optlex']=(function(...) local _ENV=_ENV; -local function a(t,...) +local function e(t,...) local e=package.loaded[t]or _ENV[t]or{_NAME=t}; package.loaded[t]=e; for t=1,select("#",...)do @@ -11,18 +11,17 @@ _M=e; return e; end -local h=_G -local m=require"string" -a"optlex" -local i=m.match -local e=m.sub -local r=m.find -local l=m.rep +local s=_G +local u=require"string" +local i=u.match +local e=u.sub +local r=u.find +local l=u.rep local c -error=h.error +error=s.error warn={} local n,o,d -local k={ +local q={ TK_KEYWORD=true, TK_NAME=true, TK_NUMBER=true, @@ -31,47 +30,47 @@ TK_OP=true, TK_EOS=true, } -local v={ +local b={ TK_COMMENT=true, TK_LCOMMENT=true, TK_EOL=true, TK_SPACE=true, } -local s -local function q(e) +local h +local function k(e) local t=n[e-1] if e<=1 or t=="TK_EOL"then return true elseif t==""then -return q(e-1) +return k(e-1) end return false end -local function j(t) -local e=n[t+1] -if t>=#n or e=="TK_EOL"or e=="TK_EOS"then +local function g(e) +local t=n[e+1] +if e>=#n or t=="TK_EOL"or t=="TK_EOS"then return true -elseif e==""then -return j(t+1) +elseif t==""then +return g(e+1) end return false end -local function T(t) -local a=#i(t,"^%-%-%[=*%[") -local a=e(t,a+1,-(a-1)) +local function E(a) +local t=#i(a,"^%-%-%[=*%[") +local a=e(a,t+1,-(t-1)) local e,t=1,0 while true do -local o,n,i,a=r(a,"([\r\n])([\r\n]?)",e) -if not o then break end -e=o+1 +local a,n,i,o=r(a,"([\r\n])([\r\n]?)",e) +if not a then break end +e=a+1 t=t+1 -if#a>0 and i~=a then +if#o>0 and i~=o then e=e+1 end end return t end -local function b(s,h) +local function v(s,h) local a=i local t,e=n[s],n[h] if t=="TK_STRING"or t=="TK_LSTRING"or @@ -101,24 +100,24 @@ return" " end end -local function g() -local a,i,s={},{},{} +local function j() +local a,s,i={},{},{} local e=1 for t=1,#n do local n=n[t] if n~=""then -a[e],i[e],s[e]=n,o[t],d[t] +a[e],s[e],i[e]=n,o[t],d[t] e=e+1 end end -n,o,d=a,i,s -end -local function A(r) +n,o,d=a,s,i +end +local function x(r) local t=o[r] local t=t local n if i(t,"^0[xX]")then -local e=h.tostring(h.tonumber(t)) +local e=s.tostring(s.tonumber(t)) if#e<=#t then t=e else @@ -130,7 +129,7 @@ if t+0>0 then t=i(t,"^0*([1-9]%d*)$") local a=#i(t,"0*$") -local o=h.tostring(a) +local o=s.tostring(a) if a>#o+1 then t=e(t,1,#t-a).."e"..o end @@ -154,7 +153,7 @@ n="."..t local a=#i(t,"^0*") local o=#t-a -local a=h.tostring(#t) +local a=s.tostring(#t) if o+2+#a<1+#t then n=e(t,-o).."e-"..a end @@ -162,11 +161,11 @@ end else local t,a=i(t,"^([^eE]+)[eE]([%+%-]?%d+)$") -a=h.tonumber(a) -local s,o=i(t,"^(%d*)%.(%d*)$") -if s then +a=s.tonumber(a) +local h,o=i(t,"^(%d*)%.(%d*)$") +if h then a=a-#o -t=s..o +t=h..o end if t+0==0 then n="0" @@ -178,7 +177,7 @@ t=e(t,1,#t-o) a=a+o end -local i=h.tostring(a) +local i=s.tostring(a) if a==0 then n=t elseif a>0 and(a<=1+#i)then @@ -195,45 +194,45 @@ end end if n and n~=o[r]then -if s then +if h then c(" (line "..d[r]..") "..o[r].." -> "..n) -s=s+1 +h=h+1 end o[r]=n end end -local function I(u) -local t=o[u] +local function z(m) +local t=o[m] local n=e(t,1,1) local f=(n=="'")and'"'or"'" local t=e(t,2,-2) local a=1 -local l,h=0,0 +local l,s=0,0 while a<=#t do -local u=e(t,a,a) -if u=="\\"then +local c=e(t,a,a) +if c=="\\"then local o=a+1 local d=e(t,o,o) -local s=r("abfnrtv\\\n\r\"\'0123456789",d,1,true) -if not s then +local h=r("abfnrtv\\\n\r\"\'0123456789",d,1,true) +if not h then t=e(t,1,a-1)..e(t,o) a=a+1 -elseif s<=8 then +elseif h<=8 then a=a+2 -elseif s<=10 then +elseif h<=10 then local i=e(t,o,o+1) if i=="\r\n"or i=="\n\r"then t=e(t,1,a).."\n"..e(t,o+2) -elseif s==10 then +elseif h==10 then t=e(t,1,a).."\n"..e(t,o+1) end a=a+2 -elseif s<=12 then +elseif h<=12 then if d==n then l=l+1 a=a+2 else -h=h+1 +s=s+1 t=e(t,1,a-1)..e(t,o) a=a+1 end @@ -241,21 +240,21 @@ local i=i(t,"^(%d%d?%d?)",o) o=a+1+#i local d=i+0 -local s=m.char(d) -local r=r("\a\b\f\n\r\t\v",s,1,true) +local h=u.char(d) +local r=r("\a\b\f\n\r\t\v",h,1,true) if r then i="\\"..e("abfnrtv",r,r) elseif d<32 then i="\\"..d -elseif s==n then -i="\\"..s +elseif h==n then +i="\\"..h l=l+1 -elseif s=="\\"then +elseif h=="\\"then i="\\\\" else -i=s -if s==f then -h=h+1 +i=h +if h==f then +s=s+1 end end t=e(t,1,a-1)..i..e(t,o) @@ -263,12 +262,12 @@ end else a=a+1 -if u==f then -h=h+1 -end -end -end -if l>h then +if c==f then +s=s+1 +end +end +end +if l>s then a=1 while a<=#t do local o,s,i=r(t,"([\'\"])",a) @@ -284,24 +283,24 @@ n=f end t=n..t..n -if t~=o[u]then -if s then -c(" (line "..d[u]..") "..o[u].." -> "..t) -s=s+1 -end -o[u]=t -end -end -local function O(h) -local t=o[h] -local u=i(t,"^%[=*%[") -local a=#u +if t~=o[m]then +if h then +c(" (line "..d[m]..") "..o[m].." -> "..t) +h=h+1 +end +o[m]=t +end +end +local function _(u) +local t=o[u] +local h=i(t,"^%[=*%[") +local a=#h local c=e(t,-a,-1) local s=e(t,a+1,-(a+1)) local n="" local t=1 while true do -local a,o,l,r=r(s,"([\r\n])([\r\n]?)",t) +local a,o,r,h=r(s,"([\r\n])([\r\n]?)",t) local o if not a then o=e(s,t) @@ -310,7 +309,7 @@ end if o~=""then if i(o,"%s+$")then -warn.lstring="trailing whitespace in long string near line "..d[h] +warn.lstring="trailing whitespace in long string near line "..d[u] end n=n..o end @@ -319,7 +318,7 @@ end t=a+1 if a then -if#r>0 and l~=r then +if#h>0 and r~=h then t=t+1 end if not(t==1 and t==a)then @@ -336,16 +335,16 @@ end if t then a=l("=",t-2) -u,c="["..a.."[","]"..a.."]" -end -end -o[h]=u..n..c -end -local function w(d) -local a=o[d] +h,c="["..a.."[","]"..a.."]" +end +end +o[u]=h..n..c +end +local function w(u) +local a=o[u] local h=i(a,"^%-%-%[=*%[") local t=#h -local u=e(a,-t,-1) +local d=e(a,-t,-1) local s=e(a,t+1,-(t-1)) local n="" local a=1 @@ -383,20 +382,20 @@ end if a then t=l("=",a-2) -h,u="--["..t.."[","]"..t.."]" -end -end -o[d]=h..n..u -end -local function p(n) -local t=o[n] -local a=i(t,"%s*$") -if#a>0 then -t=e(t,1,-(a+1)) -end -o[n]=t -end -local function x(o,a) +h,d="--["..t.."[","]"..t.."]" +end +end +o[u]=h..n..d +end +local function p(a) +local t=o[a] +local i=i(t,"%s*$") +if#i>0 then +t=e(t,1,-(i+1)) +end +o[a]=t +end +local function A(o,a) if not o then return false end local t=i(a,"^%-%-%[=*%[") local t=#t @@ -406,56 +405,56 @@ return true end end -function optimize(t,r,a,i) +function optimize(t,i,r,a) local m=t["opt-comments"] local u=t["opt-whitespace"] local f=t["opt-emptylines"] local y=t["opt-eols"] -local z=t["opt-strings"] -local E=t["opt-numbers"] -local _=t.KEEP -s=t.DETAILS and 0 -c=c or h.print +local I=t["opt-strings"] +local T=t["opt-numbers"] +local O=t.KEEP +h=t.DETAILS and 0 +c=c or s.print if y then m=true u=true f=true end n,o,d -=r,a,i +=i,r,a local t=1 local a,r -local h -local function i(a,i,e) +local s +local function i(i,a,e) e=e or t -n[e]=a or"" -o[e]=i or"" +n[e]=i or"" +o[e]=a or"" end while true do a,r=n[t],o[t] -local s=q(t) -if s then h=nil end +local h=k(t) +if h then s=nil end if a=="TK_EOS"then break elseif a=="TK_KEYWORD"or a=="TK_NAME"or a=="TK_OP"then -h=t +s=t elseif a=="TK_NUMBER"then -if E then -A(t) -end -h=t +if T then +x(t) +end +s=t elseif a=="TK_STRING"or a=="TK_LSTRING"then -if z then +if I then if a=="TK_STRING"then -I(t) +z(t) else -O(t) -end -end -h=t +_(t) +end +end +s=t elseif a=="TK_COMMENT"then if m then if t==1 and e(r,1,1)=="#"then @@ -467,14 +466,14 @@ p(t) end elseif a=="TK_LCOMMENT"then -if x(_,r)then +if A(O,r)then if u then w(t) end -h=t +s=t elseif m then -local e=T(r) -if v[n[t+1]]then +local e=E(r) +if b[n[t+1]]then i() a="" else @@ -490,32 +489,32 @@ if u then w(t) end -h=t +s=t end elseif a=="TK_EOL"then -if s and f then +if h and f then i() elseif r=="\r\n"or r=="\n\r"then i("TK_EOL","\n") end elseif a=="TK_SPACE"then if u then -if s or j(t)then +if h or g(t)then i() else -local a=n[h] +local a=n[s] if a=="TK_LCOMMENT"then i() else local e=n[t+1] -if v[e]then +if b[e]then if(e=="TK_COMMENT"or e=="TK_LCOMMENT")and -a=="TK_OP"and o[h]=="-"then +a=="TK_OP"and o[s]=="-"then else i() end else -local e=b(h,t+1) +local e=v(s,t+1) if e==""then i() else @@ -530,7 +529,7 @@ end t=t+1 end -g() +j() if y then t=1 if n[1]=="TK_COMMENT"then @@ -542,8 +541,8 @@ break elseif a=="TK_EOL"then local e,a=n[t-1],n[t+1] -if k[e]and k[a]then -local e=b(t-1,t+1) +if q[e]and q[a]then +local e=v(t-1,t+1) if e==""then i() end @@ -551,16 +550,16 @@ end t=t+1 end -g() -end -if s and s>0 then c()end +j() +end +if h and h>0 then c()end return n,o,d end -return _M; +return{optimize=optimize} end) package.preload['optparser']=(function(...) local _ENV=_ENV; -local function o(t,...) +local function e(t,...) local e=package.loaded[t]or _ENV[t]or{_NAME=t}; package.loaded[t]=e; for t=1,select("#",...)do @@ -573,8 +572,7 @@ local e=_G local a=require"string" local l=require"table" -o"optparser" -local n="etaoinshrdlucmfwypvbgkqjxz_ETAOINSHRDLUCMFWYPVBGKQJXZ" +local s="etaoinshrdlucmfwypvbgkqjxz_ETAOINSHRDLUCMFWYPVBGKQJXZ" local d="etaoinshrdlucmfwypvbgkqjxz_0123456789ETAOINSHRDLUCMFWYPVBGKQJXZ" local w={} for e in a.gmatch([[ @@ -583,11 +581,11 @@ self _ENV]],"%S+")do w[e]=true end -local r,u, -c,o, -m,v, -h, -s +local h,u, +m,o, +c,v, +r, +n local function f(e) local i={} for n=1,#e do @@ -617,9 +615,9 @@ end return i end -local function p(e) +local function y(e) local i=a.byte -local s=a.char +local n=a.char local a={ TK_KEYWORD=true,TK_NAME=true,TK_NUMBER=true, TK_STRING=true,TK_LSTRING=true, @@ -628,95 +626,95 @@ a.TK_COMMENT=true a.TK_LCOMMENT=true end -local t={} -for e=1,#r do -t[e]=u[e] -end -for e=1,#o do -local e=o[e] -local a=e.xref -for e=1,e.xcount do -local e=a[e] -t[e]="" -end -end local e={} -for t=0,255 do e[t]=0 end -for o=1,#r do -local o,t=r[o],t[o] +for t=1,#h do +e[t]=u[t] +end +for t=1,#o do +local t=o[t] +local a=t.xref +for t=1,t.xcount do +local t=a[t] +e[t]="" +end +end +local t={} +for e=0,255 do t[e]=0 end +for o=1,#h do +local o,e=h[o],e[o] if a[o]then -for a=1,#t do -local t=i(t,a) -e[t]=e[t]+1 -end -end -end -local function a(o) -local t={} -for a=1,#o do -local o=i(o,a) -t[a]={c=o,freq=e[o],} -end -l.sort(t, +for a=1,#e do +local e=i(e,a) +t[e]=t[e]+1 +end +end +end +local function o(a) +local e={} +for o=1,#a do +local a=i(a,o) +e[o]={c=a,freq=t[a],} +end +l.sort(e, function(t,e) return t.freq>e.freq end ) -local e={} -for a=1,#t do -e[a]=s(t[a].c) -end -return l.concat(e) -end -n=a(n) -d=a(d) -end -local function y() +local t={} +for a=1,#e do +t[a]=n(e[a].c) +end +return l.concat(t) +end +s=o(s) +d=o(d) +end +local function p() local t -local s,r=#n,#d -local e=h -if ee +local i=e%n +e=(e-i)/n i=i+1 -until o>e -local o=e%s -e=(e-o)/s -o=o+1 -t=a.sub(n,o,o) -while i>1 do -local o=e%r -e=(e-o)/r -o=o+1 -t=t..a.sub(d,o,o) -i=i-1 -end -end -h=h+1 -return t,m[t]~=nil -end -function optimize(e,i,n,a,t) -r,u,c,o -=i,n,a,t -h=0 -s={} -m=f(c) +t=a.sub(s,i,i) +while o>1 do +local i=e%h +e=(e-i)/h +i=i+1 +t=t..a.sub(d,i,i) +o=o-1 +end +end +r=r+1 +return t,c[t]~=nil +end +function optimize(e,i,t,s,a) +h,u,m,o +=i,t,s,a +r=0 +n={} +c=f(m) v=f(o) if e["opt-entropy"]then -p(e) +y(e) end local e={} for t=1,#o do e[t]=o[t] end l.sort(e, -function(e,t) -return e.xcount>t.xcount +function(t,e) +return t.xcount>e.xcount end ) local a,t,r={},1,false @@ -730,20 +728,20 @@ end end e=a -local h=#e -while h>0 do -local n,a +local s=#e +while s>0 do +local h,t repeat -n,a=y() -until not w[n] -s[#s+1]=n -local t=h -if a then -local i=c[m[n].id].xref +h,t=p() +until not w[h] +n[#n+1]=h +local a=s +if t then +local i=m[c[h].id].xref local n=#i -for a=1,h do -local a=e[a] -local s,e=a.act,a.rem +for t=1,s do +local t=e[t] +local s,e=t.act,t.rem while e<0 do e=o[-e].rem end @@ -753,60 +751,60 @@ if t>=s and t<=e then o=true end end if o then -a.skip=true -t=t-1 -end -end -end -while t>0 do -local a=1 -while e[a].skip do -a=a+1 -end -t=t-1 -local i=e[a] -a=a+1 -i.newname=n +t.skip=true +a=a-1 +end +end +end +while a>0 do +local t=1 +while e[t].skip do +t=t+1 +end +a=a-1 +local i=e[t] +t=t+1 +i.newname=h i.skip=true i.done=true -local s,r=i.first,i.last -local h=i.xref -if s and t>0 then -local n=t +local s,h=i.first,i.last +local r=i.xref +if s and a>0 then +local n=a while n>0 do -while e[a].skip do -a=a+1 +while e[t].skip do +t=t+1 end n=n-1 -local e=e[a] -a=a+1 -local n,a=e.act,e.rem -while a<0 do -a=o[-a].rem -end -if not(ra)then +local e=e[t] +t=t+1 +local n,t=e.act,e.rem +while t<0 do +t=o[-t].rem +end +if not(ht)then if n>=i.act then for o=1,i.xcount do -local o=h[o] -if o>=n and o<=a then -t=t-1 +local o=r[o] +if o>=n and o<=t then +a=a-1 e.skip=true break end end else if e.last and e.last>=i.act then -t=t-1 +a=a-1 e.skip=true end end end -if t==0 then break end +if a==0 then break end end end end local a,t={},1 -for o=1,h do +for o=1,s do local e=e[o] if not e.done then e.skip=false @@ -815,7 +813,7 @@ end end e=a -h=#e +s=#e end for e=1,#o do local e=o[e] @@ -832,15 +830,15 @@ end end if r then -s[#s+1]="self" +n[#n+1]="self" end local e=f(o) end -return _M; +return{optimize=optimize} end) package.preload['llex']=(function(...) local _ENV=_ENV; -local function a(t,...) +local function e(t,...) local e=package.loaded[t]or _ENV[t]or{_NAME=t}; package.loaded[t]=e; for t=1,select("#",...)do @@ -850,31 +848,33 @@ _M=e; return e; end -local d=_G -local h=require"string" -a"llex" -local u=h.find -local c=h.match -local i=h.sub -local f={} -for e in h.gmatch([[ +local y=_G +local s=require"string" +local l=s.find +local c=s.match +local n=s.sub +local e='' +local r='' +local a=1 +local d=1 +local m={} +local w={} +local p={} +local i='' +local v={} +for e in s.gmatch([[ and break do else elseif end false for function if in local nil not or repeat return then true until while]],"%S+")do -f[e]=true -end -local e, -r, -a, -n, -s +v[e]=true +end local function o(a,t) -local e=#tok+1 -tok[e]=a -seminfo[e]=t -tokln[e]=s -end -local function l(t,h) -local n=i +local e=#m+1 +m[e]=a +w[e]=t +p[e]=d +end +local function h(t,s) +local n=n local i=n(e,t,t) t=t+1 local e=n(e,t,t) @@ -882,39 +882,34 @@ t=t+1 i=i..e end -if h then o("TK_EOL",i)end -s=s+1 +if s then o("TK_EOL",i)end +d=d+1 a=t return t end function init(i,t) e=i r=t -a=1 -s=1 -tok={} -seminfo={} -tokln={} -local i,n,e,t=u(e,"^(#[^\r\n]*)(\r?\n?)") -if i then +local t,n,e,i=l(e,"^(#[^\r\n]*)(\r?\n?)") +if t then a=a+#e o("TK_COMMENT",e) -if#t>0 then l(a,true)end +if#i>0 then h(a,true)end end end function chunkid() if r and c(r,"^[=@]")then -return i(r,2) +return n(r,2) end return"[string]" end -function errorline(a,t) -local e=error or d.error -e(h.format("%s:%d: %s",chunkid(),t or s,a)) +function errorline(t,a) +local e=error or y.error +e(s.format("%s:%d: %s",chunkid(),a or d,t)) end local r=errorline -local function m(t) -local i=i +local function u(t) +local i=n local n=i(e,t,t) t=t+1 local o=#c(e,"=*",t) @@ -922,53 +917,53 @@ a=t return(i(e,t,t)==n)and o or(-o)-1 end -local function w(d,h) +local function f(d,s) local t=a+1 -local i=i -local o=i(e,t,t) +local n=n +local o=n(e,t,t) if o=="\r"or o=="\n"then -t=l(t) +t=h(t) end local o=t while true do -local o,u,s=u(e,"([\r\n%]])",t) +local o,c,l=l(e,"([\r\n%]])",t) if not o then r(d and"unfinished long string"or "unfinished long comment") end t=o -if s=="]"then -if m(t)==h then -n=i(e,n,a) +if l=="]"then +if u(t)==s then +i=n(e,i,a) a=a+1 -return n +return i end t=a else -n=n.."\n" -t=l(t) -end -end -end -local function y(d) +i=i.."\n" +t=h(t) +end +end +end +local function b(u) local t=a -local s=u -local h=i +local s=l +local d=n while true do -local i,u,o=s(e,"([\n\r\\\"\'])",t) -if i then +local n,l,o=s(e,"([\n\r\\\"\'])",t) +if n then if o=="\n"or o=="\r"then r("unfinished string") end -t=i +t=n if o=="\\"then t=t+1 -o=h(e,t,t) +o=d(e,t,t) if o==""then break end -i=s("abfnrtv\n\r",o,1,true) -if i then -if i>7 then -t=l(t) +n=s("abfnrtv\n\r",o,1,true) +if n then +if n>7 then +t=h(t) else t=t+1 end @@ -983,9 +978,9 @@ end else t=t+1 -if o==d then +if o==u then a=t -return h(e,n,t-1) +return d(e,i,t-1) end end else @@ -995,76 +990,76 @@ r("unfinished string") end function llex() -local s=u -local u=c +local s=l +local d=c while true do local t=a while true do -local c,p,h=s(e,"^([_%a][_%w]*)",t) +local c,m,l=s(e,"^([_%a][_%w]*)",t) if c then -a=t+#h -if f[h]then -o("TK_KEYWORD",h) +a=t+#l +if v[l]then +o("TK_KEYWORD",l) else -o("TK_NAME",h) +o("TK_NAME",l) end break end -local h,f,c=s(e,"^(%.?)%d",t) -if h then +local l,m,c=s(e,"^(%.?)%d",t) +if l then if c=="."then t=t+1 end -local c,l,n=s(e,"^%d*[%.%d]*([eE]?)",t) -t=l+1 -if#n==1 then -if u(e,"^[%+%-]",t)then +local u,h,i=s(e,"^%d*[%.%d]*([eE]?)",t) +t=h+1 +if#i==1 then +if d(e,"^[%+%-]",t)then t=t+1 end end -local n,t=s(e,"^[_%w]*",t) +local i,t=s(e,"^[_%w]*",t) a=t+1 -local e=i(e,h,t) -if not d.tonumber(e)then +local e=n(e,l,t) +if not y.tonumber(e)then r("malformed number") end o("TK_NUMBER",e) break end -local d,c,f,h=s(e,"^((%s)[ \t\v\f]*)",t) -if d then -if h=="\n"or h=="\r"then -l(t,true) +local m,w,c,l=s(e,"^((%s)[ \t\v\f]*)",t) +if m then +if l=="\n"or l=="\r"then +h(t,true) else -a=c+1 -o("TK_SPACE",f) +a=w+1 +o("TK_SPACE",c) end break end -local h=u(e,"^%p",t) +local h=d(e,"^%p",t) if h then -n=t -local d=s("-[\"\'.=<>~",h,1,true) -if d then -if d<=2 then -if d==1 then -local r=u(e,"^%-%-(%[?)",t) +i=t +local l=s("-[\"\'.=<>~",h,1,true) +if l then +if l<=2 then +if l==1 then +local r=d(e,"^%-%-(%[?)",t) if r then t=t+2 local h=-1 if r=="["then -h=m(t) +h=u(t) end if h>=0 then -o("TK_LCOMMENT",w(false,h)) +o("TK_LCOMMENT",f(false,h)) else a=s(e,"[\n\r]",t)or(#e+1) -o("TK_COMMENT",i(e,n,a-1)) +o("TK_COMMENT",n(e,i,a-1)) end break end else -local e=m(t) +local e=u(t) if e>=0 then -o("TK_LSTRING",w(true,e)) +o("TK_LSTRING",f(true,e)) elseif e==-1 then o("TK_OP","[") else @@ -1072,22 +1067,22 @@ end break end -elseif d<=5 then -if d<5 then +elseif l<=5 then +if l<5 then a=t+1 -o("TK_STRING",y(h)) +o("TK_STRING",b(h)) break end -h=u(e,"^%.%.?%.?",t) +h=d(e,"^%.%.?%.?",t) else -h=u(e,"^%p=?",t) +h=d(e,"^%p=?",t) end end a=t+#h o("TK_OP",h) break end -local e=i(e,t,t) +local e=n(e,t,t) if e~=""then a=t+1 o("TK_OP",e) @@ -1098,13 +1093,18 @@ end end end -d.print(_M) -d.assert(d.type(_M)=="table") -return _M +return{ +llex=llex, +init=init, +chunkid=chunkid, +tok=m, +tokln=p, +seminfo=w +} end) package.preload['lparser']=(function(...) local _ENV=_ENV; -local function a(t,...) +local function e(t,...) local e=package.loaded[t]or _ENV[t]or{_NAME=t}; package.loaded[t]=e; for t=1,select("#",...)do @@ -1114,37 +1114,37 @@ _M=e; return e; end -local R=_G -local v=require"string" -a"lparser" -local E, +local U=_G +local b=require"string" +local D={} +local T, j, -T, -S, +A, +C, +d, r, -d, -B, -t,x,s,m, +P, +t,k,l,y, p, a, -K, +W, q, N, -l, -b, -A -local w,u,y,_,z,g -local e=v.gmatch -local O={} +u, +g, +E +local f,n,w,_,x,v +local e=b.gmatch +local H={} for e in e("else elseif end until ","%S+")do -O[e]=true -end -local G={} +H[e]=true +end +local Y={} for e in e("if while do for repeat function local return break","%S+")do -G[e]=e.."_stat" -end -local I={} -local Q={} +Y[e]=e.."_stat" +end +local S={} +local V={} for e,a,t in e([[ {+ 6 6}{- 6 6}{* 7 7}{/ 7 7}{% 7 7} {^ 10 9}{.. 5 4} @@ -1152,71 +1152,112 @@ {< 3 3}{<= 3 3}{> 3 3}{>= 3 3} {and 2 2}{or 1 1} ]],"{(%S+)%s(%d+)%s(%d+)}")do -I[e]=a+0 -Q[e]=t+0 -end -local X={["not"]=true,["-"]=true, +S[e]=a+0 +V[e]=t+0 +end +local Z={["not"]=true,["-"]=true, ["#"]=true,} -local Z=8 -local function o(e,a) -local t=error or R.error -t(v.format("(source):%d: %s",a or s,e)) +local ee=8 +local function o(t,a) +local e=error or U.error +e(b.format("(source):%d: %s",a or l,t)) end local function e() -B=T[r] -t,x,s,m -=E[r],j[r],T[r],S[r] -r=r+1 -end -local function J() -return E[r] -end -local function h(a) +P=A[d] +t,k,l,y +=T[d],j[d],A[d],C[d] +d=d+1 +end +local function X() +return T[d] +end +local function s(a) local e=t if e~=""and e~=""then -if e==""then e=x end +if e==""then e=k end e="'"..e.."'" end o(a.." near "..e) end local function c(e) -h("'"..e.."' expected") -end -local function i(a) +s("'"..e.."' expected") +end +local function o(a) if t==a then e();return true end end -local function D(e) +local function L(e) if t~=e then c(e)end end -local function o(t) -D(t);e() -end -local function V(e,t) -if not e then h(t)end -end -local function n(e,a,t) -if not i(e)then -if t==s then +local function i(t) +L(t);e() +end +local function F(e,t) +if not e then s(t)end +end +local function h(e,a,t) +if not o(e)then +if t==l then c(e) else -h("'"..e.."' expected (to close '"..a.."' at line "..t..")") -end -end -end -local function f() -D("") -local t=x -p=m +s("'"..e.."' expected (to close '"..a.."' at line "..t..")") +end +end +end +local function c() +L("") +local t=k +p=y e() return t end -local function U(e,t) +local function I(e,t) e.k="VK" end -local function L(e) -U(e,f()) -end -local function c(o,i) +local function R(e) +I(e,c()) +end +local function m(o,i) +local e=a.bl +local t +if e then +t=e.locallist +else +t=a.locallist +end +local e=#u+1 +u[e]={ +name=o, +xref={p}, +decl=p, +} +if i or o=="_ENV"then +u[e].preserve=true +end +local a=#g+1 +g[a]=e +E[a]=t +end +local function z(e) +local t=#g +while e>0 do +e=e-1 +local t=t-e +local a=g[t] +local e=u[a] +local o=e.name +e.act=y +g[t]=nil +local i=E[t] +E[t]=nil +local t=i[o] +if t then +e=u[t] +e.rem=-a +end +i[o]=a +end +end +local function O() local t=a.bl local e if t then @@ -1224,59 +1265,18 @@ else e=a.locallist end -local t=#l+1 -l[t]={ -name=o, -xref={p}, -decl=p, -} -if i or o=="_ENV"then -l[t].preserve=true -end -local a=#b+1 -b[a]=t -A[a]=e -end -local function k(e) -local t=#b -while e>0 do -e=e-1 -local e=t-e -local a=b[e] -local t=l[a] -local o=t.name -t.act=m -b[e]=nil -local i=A[e] -A[e]=nil -local e=i[o] -if e then -t=l[e] -t.rem=-a -end -i[o]=a -end -end -local function H() -local t=a.bl -local e -if t then -e=t.locallist -else -e=a.locallist -end -for t,e in R.pairs(e)do -local e=l[e] -e.rem=m -end -end -local function m(e,t) -if v.sub(e,1,1)=="("then +for t,e in U.pairs(e)do +local e=u[e] +e.rem=y +end +end +local function y(e,t) +if b.sub(e,1,1)=="("then return end -c(e,t) -end -local function R(o,a) +m(e,t) +end +local function U(o,a) local t=o.bl local e if t then @@ -1290,18 +1290,18 @@ e=o.locallist return e[a]or-1 end -local function v(t,o,e) +local function b(t,o,e) if t==nil then e.k="VGLOBAL" return"VGLOBAL" else -local a=R(t,o) +local a=U(t,o) if a>=0 then e.k="VLOCAL" e.id=a return"VLOCAL" else -if v(t.prev,o,e)=="VGLOBAL"then +if b(t.prev,o,e)=="VGLOBAL"then return"VGLOBAL" end e.k="VUPVAL" @@ -1309,9 +1309,9 @@ end end end -local function P(o) -local t=f() -v(a,t,o) +local function Q(o) +local t=c() +b(a,t,o) if o.k=="VGLOBAL"then local e=N[t] if not e then @@ -1327,7 +1327,7 @@ end else local e=o.id -local e=l[e].xref +local e=u[e].xref e[#e+1]=p end end @@ -1338,15 +1338,15 @@ e.locallist={} a.bl=e end -local function v() +local function b() local e=a.bl -H() +O() a.bl=e.prev end -local function Y() +local function B() local e if not a then -e=K +e=W else e={} end @@ -1355,147 +1355,147 @@ e.locallist={} a=e end -local function F() -H() +local function G() +O() a=a.prev end -local function H(a) -local t={} +local function U(t) +local a={} e() -L(t) -a.k="VINDEXED" -end -local function M(t) +R(a) +t.k="VINDEXED" +end +local function K(t) e() -u(t) -o("]") -end -local function R(e) +n(t) +i("]") +end +local function M(e) local e,a={},{} if t==""then -L(e) +R(e) else -M(e) -end -o("=") -u(a) -end -local function C(e) +K(e) +end +i("=") +n(a) +end +local function O(e) if e.v.k=="VVOID"then return end e.v.k="VVOID" end -local function C(e) -u(e.v) -end -local function W(a) -local s=s +local function O(e) +n(e.v) +end +local function J(a) +local n=l local e={} e.v={} e.t=a a.k="VRELOCABLE" e.v.k="VVOID" -o("{") +i("{") repeat if t=="}"then break end local t=t if t==""then -if J()~="="then -C(e) +if X()~="="then +O(e) else -R(e) +M(e) end elseif t=="["then -R(e) +M(e) else -C(e) -end -until not i(",")and not i(";") -n("}","{",s) -end -local function J() -local o=0 +O(e) +end +until not o(",")and not o(";") +h("}","{",n) +end +local function X() +local i=0 if t~=")"then repeat local t=t if t==""then -c(f()) -o=o+1 +m(c()) +i=i+1 elseif t=="..."then e() a.is_vararg=true else -h(" or '...' expected") -end -until a.is_vararg or not i(",") -end -k(o) -end -local function C(r) +s(" or '...' expected") +end +until a.is_vararg or not o(",") +end +z(i) +end +local function M(n) local a={} -local i=s +local i=l local o=t if o=="("then -if i~=B then -h("ambiguous syntax (function call x new statement)") +if i~=P then +s("ambiguous syntax (function call x new statement)") end e() if t==")"then a.k="VVOID" else -w(a) -end -n(")","(",i) +f(a) +end +h(")","(",i) elseif o=="{"then -W(a) +J(a) elseif o==""then -U(a,x) +I(a,k) e() else -h("function arguments expected") +s("function arguments expected") return end -r.k="VCALL" -end -local function B(a) +n.k="VCALL" +end +local function P(a) local t=t if t=="("then -local t=s +local t=l e() -u(a) -n(")","(",t) +n(a) +h(")","(",t) elseif t==""then +Q(a) +else +s("unexpected symbol") +end +end +local function O(a) P(a) -else -h("unexpected symbol") -end -end -local function R(a) -B(a) while true do local t=t if t=="."then -H(a) +U(a) elseif t=="["then local e={} -M(e) +K(e) elseif t==":"then local t={} e() -L(t) -C(a) +R(t) +M(a) elseif t=="("or t==""or t=="{"then -C(a) +M(a) else return end end end -local function L(o) +local function R(o) local t=t if t==""then o.k="VKNUM" elseif t==""then -U(o,x) +I(o,k) elseif t=="nil"then o.k="VNIL" elseif t=="true"then @@ -1503,229 +1503,229 @@ elseif t=="false"then o.k="VFALSE" elseif t=="..."then -V(a.is_vararg==true, +F(a.is_vararg==true, "cannot use '...' outside a vararg function"); o.k="VVARARG" elseif t=="{"then -W(o) +J(o) return elseif t=="function"then e() -z(o,false,s) +x(o,false,l) return else -R(o) +O(o) return end e() end -local function x(o,n) +local function k(o,n) local a=t -local i=X[a] +local i=Z[a] if i then e() -x(o,Z) +k(o,ee) else -L(o) +R(o) end a=t -local t=I[a] +local t=S[a] while t and t>n do local o={} e() -local e=x(o,Q[a]) +local e=k(o,V[a]) a=e -t=I[a] +t=S[a] end return a end -function u(e) -x(e,0) +function n(e) +k(e,0) end local function I(e) local t={} local e=e.v.k -V(e=="VLOCAL"or e=="VUPVAL"or e=="VGLOBAL" +F(e=="VLOCAL"or e=="VUPVAL"or e=="VGLOBAL" or e=="VINDEXED","syntax error") -if i(",")then +if o(",")then local e={} e.v={} -R(e.v) +O(e.v) I(e) else -o("=") -w(t) +i("=") +f(t) return end t.k="VNONRELOC" end -local function x(e,t) -o("do") +local function k(e,t) +i("do") p(false) -k(e) -y() -v() -end -local function U(e) -local t=d -m("(for index)") -m("(for limit)") -m("(for step)") -c(e) -o("=") +z(e) +w() +b() +end +local function R(e) +local t=r +y("(for index)") +y("(for limit)") +y("(for step)") +m(e) +i("=") _() -o(",") +i(",") _() -if i(",")then +if o(",")then _() else end -x(1,true) +k(1,true) end local function M(e) local t={} -m("(for generator)") -m("(for state)") -m("(for control)") -c(e) +y("(for generator)") +y("(for state)") +y("(for control)") +m(e) local e=1 -while i(",")do -c(f()) +while o(",")do +m(c()) e=e+1 end -o("in") -local a=d -w(t) -x(e,false) -end -local function L(e) +i("in") +local a=r +f(t) +k(e,false) +end +local function F(e) local a=false -P(e) +Q(e) while t=="."do -H(e) +U(e) end if t==":"then a=true -H(e) +U(e) end return a end function _() local e={} -u(e) -end -local function x() +n(e) +end +local function k() local e={} -u(e) -end -local function _() +n(e) +end +local function S() e() -x() -o("then") -y() -end -local function C() +k() +i("then") +w() +end +local function P() local t,e={} -c(f()) +m(c()) t.k="VLOCAL" -k(1) -z(e,false,s) -end -local function H() +z(1) +x(e,false,l) +end +local function U() local e=0 local t={} repeat -c(f()) +m(c()) e=e+1 -until not i(",") -if i("=")then -w(t) +until not o(",") +if o("=")then +f(t) else t.k="VVOID" end -k(e) -end -function w(e) -u(e) -while i(",")do -u(e) -end -end -function z(a,t,e) -Y() -o("(") +z(e) +end +function f(e) +n(e) +while o(",")do +n(e) +end +end +function x(a,t,e) +B() +i("(") if t then -m("self",true) -k(1) -end -J() -o(")") -g() -n("end","function",e) -F() -end -function y() +y("self",true) +z(1) +end +X() +i(")") +v() +h("end","function",e) +G() +end +function w() p(false) -g() v() +b() end function for_stat() -local o=d +local o=r p(true) e() -local a=f() +local a=c() local e=t if e=="="then -U(a) +R(a) elseif e==","or e=="in"then M(a) else -h("'=' or 'in' expected") -end -n("end","for",o) -v() +s("'=' or 'in' expected") +end +h("end","for",o) +b() end function while_stat() -local t=d +local t=r e() -x() +k() p(true) -o("do") -y() -n("end","while",t) -v() +i("do") +w() +h("end","while",t) +b() end function repeat_stat() -local t=d +local t=r p(true) p(false) e() -g() -n("until","repeat",t) -x() v() -v() +h("until","repeat",t) +k() +b() +b() end function if_stat() -local a=d +local a=r local o={} -_() +S() while t=="elseif"do -_() +S() end if t=="else"then e() -y() -end -n("end","if",a) +w() +end +h("end","if",a) end function return_stat() local a={} e() local e=t -if O[e]or e==";"then +if H[e]or e==";"then else -w(a) +f(a) end end function break_stat() @@ -1735,13 +1735,13 @@ t=t.prev end if not t then -h("no loop to break") +s("no loop to break") end end function expr_stat() local e={} e.v={} -R(e.v) +O(e.v) if e.v.k=="VCALL"then else e.prev=nil @@ -1749,59 +1749,59 @@ end end function function_stat() -local t=d -local o,a={},{} +local a=r +local o,t={},{} e() -local e=L(o) -z(a,e,t) +local e=F(o) +x(t,e,a) end function do_stat() -local t=d +local t=r e() -y() -n("end","do",t) +w() +h("end","do",t) end function local_stat() e() -if i("function")then -C() +if o("function")then +P() else -H() -end -end -local function o() -d=s +U() +end +end +local function i() +r=l local e=t -local t=G[e] +local t=Y[e] if t then -_M[t]() +D[t]() if e=="return"or e=="break"then return true end else expr_stat() end return false end -function g() +function v() local e=false -while not e and not O[t]do -e=o() -i(";") +while not e and not H[t]do +e=i() +o(";") end end function parser() -Y() +B() a.is_vararg=true e() -g() -D("") -F() -return q,l +v() +L("") +G() +return q,u end function init(e,o,n) -r=1 -K={} +d=1 +W={} local t=1 -E,j,T,S={},{},{},{} +T,j,A,C={},{},{},{} for a=1,#e do local e=e[a] local i=true @@ -1822,16 +1822,36 @@ i=false end if i then -E[t]=e -T[t]=n[a] -S[t]=a +T[t]=e +A[t]=n[a] +C[t]=a t=t+1 end end -q,N,l={},{},{} -b,A={},{} -end -return _M +q,N,u={},{},{} +g,E={},{} +end +D={ +expr=n, +exp1=_, +explist1=f, +body=x, +block=w, +for_stat=for_stat, +while_stat=while_stat, +repeat_stat=repeat_stat, +if_stat=if_stat, +return_stat=return_stat, +break_stat=break_stat, +expr_stat=expr_stat, +function_stat=function_stat, +do_stat=do_stat, +local_stat=local_stat, +chunk=v, +parser=parser, +init=init +} +return D end) package.preload['minichunkspy']=(function(...) local _ENV=_ENV; @@ -1845,86 +1865,86 @@ _M=e; return e; end -local c,t,u=string,table,math -local a,w,n,e=ipairs,setmetatable,type,assert +local m,t,u=string,table,math +local a,v,n,e=ipairs,setmetatable,type,assert local a=__END_OF_GLOBALS__ -local l,i,f=c.char,c.byte,c.sub -local E,d,_=u.frexp,u.ldexp,u.abs -local y=t.concat +local c,l,i=m.char,m.byte,m.sub +local w,d,g=u.frexp,u.ldexp,u.abs +local p=t.concat local a=u.huge -local x=a-a +local k=a-a local o=false -local h=4 +local r=4 local s=4 -local r=8 +local h=8 local t={} -local function v() +local function y() t[#t+1] -={o,h,s,r} -end -local function p() -o,h,s,r +={o,r,s,h} +end +local function b() +o,r,s,h =unpack(t[#t]) t[#t]=nil end local function t(e,t) return e.new(e,t) end -local m={} +local f={} local t=t{ new= function(e,a) local a=a or{} -local t=m[e]or{ +local t=f[e]or{ __index=e, __call=t } -m[e]=t -return w(a,t) +f[e]=t +return v(a,t) end, } -local q=t{ +local j=t{ unpack=function(t,t,e)return nil,e end, pack=function(e,e)return""end } -local m={} -local function b(e) -local t=m[e]or t{ +local f={} +local function v(e) +local t=f[e]or t{ unpack=function(o,a,t) -return f(a,t,t+e-1),t+e +return i(a,t,t+e-1),t+e end, -pack=function(a,t)return f(t,1,e)end +pack=function(a,t)return i(t,1,e)end } -m[e]=t +f[e]=t return t end -local w=t{ +local q=t{ unpack=function(a,t,e) -return i(t,e,e),e+1 +return l(t,e,e),e+1 end, -pack=function(t,e)return l(e)end +pack=function(t,e)return c(e)end } local i=t{ unpack= -function(t,e,a) -local e,t,n,i=i(e,a,a+3) -if o then e,t,n,i=i,n,t,e end -return e+t*256+n*256^2+i*256^3,a+4 +function(t,e,n) +local i,e,t,a=l(e,n,n+3) +if o then i,e,t,a=a,t,e,i end +return i+e*256+t*256^2+a*256^3,n+4 end, pack= function(t,s) e(n(s)=="number", "unexpected value type to pack as an uint32") -local t,a,i,e +local i,a,t,e e=s%2^32 -t=e%256;e=(e-t)/256 +i=e%256;e=(e-i)/256 a=e%256;e=(e-a)/256 -i=e%256;e=(e-i)/256 -if o then t,a,i,e=e,i,a,t end -return l(t,a,i,e) +t=e%256;e=(e-t)/256 +if o then i,a,t,e=e,t,a,i end +return c(i,a,t,e) end } -local j=t{ +local x=t{ unpack= function(a,e,t) local a=i:unpack(e,t) @@ -1942,9 +1962,9 @@ return i:pack(e)..i:pack(t) end } -local function z(a,e) -local t=i:unpack(a,e) -local e=i:unpack(a,e+4) +local function E(e,a) +local t=i:unpack(e,a) +local e=i:unpack(e,a+4) if o then t,e=e,t end local a=e%2^20 local t=t @@ -1954,35 +1974,35 @@ local e=e<=t and 1 or-1 return e,t,o end -local function l(a,n,t) +local function c(n,a,t) local e=t%2^32 -local s=(t-e)/2^32 -local t=e -local e=((a<0 and 2^11 or 0)+n)*2^20+s -if o then t,e=e,t end -return i.pack(nil,t)..i.pack(nil,e) -end -local function k(e) +local t=(t-e)/2^32 +local e=e +local t=((n<0 and 2^11 or 0)+a)*2^20+t +if o then e,t=t,e end +return i.pack(nil,e)..i.pack(nil,t) +end +local function _(e) if e~=e then return e end if e==0 then e=1/e end return e>0 and 1 or-1 end -local m=d(1,-1022-52) -local f=m*2^52 -local g=d(2^52-1,-1022-52) +local l=d(1,-1022-52) +local f=l*2^52 +local z=d(2^52-1,-1022-52) local f=d(2^53-1,1023-52) -e(m~=0 and m/2==0) +e(l~=0 and l/2==0) e(f~=a) e(f*2==a) -local l=t{ +local d=t{ unpack= function(t,e,i) -local n,o,t=z(e,i) +local n,o,t=E(e,i) local e if o==0 then e=d(t,-1022-52) elseif o==2047 then -e=t==0 and a or x +e=t==0 and a or k else e=d(2^52+t,o-1023-52) end @@ -1992,96 +2012,96 @@ pack= function(t,e) if e~=e then -return l(1,2047,2^52-1) -end -local o=k(e) -e=_(e) -if e==a then return l(o,2047,0)end -if e==0 then return l(o,0,0)end -local a,t -if e<=g then -a=0 -t=e/m +return c(1,2047,2^52-1) +end +local o=_(e) +e=g(e) +if e==a then return c(o,2047,0)end +if e==0 then return c(o,0,0)end +local t,a +if e<=z then +t=0 +a=e/l else -local e,o=E(e) -t=(2*e-1)*2^52 -a=o+1022 -end -return l(o,a,t) +local o,e=w(e) +a=(2*o-1)*2^52 +t=e+1022 +end +return c(o,t,a) end } -local a=w -local d={ +local a=q +local l={ [4]=i, -[8]=j +[8]=x } local w={ [4]=float, -[8]=l +[8]=d } -local m=t{ +local c=t{ unpack=function(a,t,e) -return d[h]:unpack(t,e) +return l[r]:unpack(t,e) end, pack=function(t,e) -return d[h]:pack(e) +return l[r]:pack(e) end, } local i=t{ -unpack=function(a,t,e) -return d[s]:unpack(t,e) +unpack=function(a,e,t) +return l[s]:unpack(e,t) end, pack=function(t,e) -return d[s]:pack(e) -end, -} -local j=t{ -unpack=function(a,t,e) -return w[r]:unpack(t,e) -end, -pack=function(t,e) -return w[r]:pack(e) +return l[s]:pack(e) end, } -local g=b(4) +local g=t{ +unpack=function(a,t,e) +return w[h]:unpack(t,e) +end, +pack=function(t,e) +return w[h]:pack(e) +end, +} +local k=v(4) local f=t{ unpack= -function(o,s,t) -local i={} -local e,a=1,1 -while o[e]do -local n=o[e] -local o=n.name -if not o then o,a=a,a+1 end -i[o],t=n:unpack(s,t) -e=e+1 -end -return i,t -end, -pack= -function(t,n) +function(t,s,o) local i={} local e,a=1,1 while t[e]do -local o=t[e] -local t=o.name +local n=t[e] +local t=n.name if not t then t,a=a,a+1 end -i[e]=o:pack(n[t]) +i[t],o=n:unpack(s,o) e=e+1 end -return y(i) +return i,o +end, +pack= +function(a,n) +local i={} +local e,t=1,1 +while a[e]do +local o=a[e] +local a=o.name +if not a then a,t=t,t+1 end +i[e]=o:pack(n[a]) +e=e+1 +end +return p(i) end } -local l=t{ +local d=t{ unpack= -function(n,a,e) -local o,e=i:unpack(a,e) -local t={} +function(n,t,e) +local o,e=i:unpack(t,e) +local a={} local i=n.type for o=1,o do -t[o],e=i:unpack(a,e) -end -return t,e +a[o],e=i:unpack(t,e) +end +return a,e end, pack= function(o,a) @@ -2091,10 +2111,10 @@ for t=1,t do e[#e+1]=o:pack(a[t]) end -return y(e) +return p(e) end } -local k=t{ +local q=t{ unpack= function(o,a,t) local t,a=i:unpack(a,t) @@ -2109,29 +2129,29 @@ return i:pack(t and 1 or 0) end } -local m=t{ +local c=t{ unpack= -function(t,o,e) -local t,e=m:unpack(o,e) -local a=nil +function(t,a,e) +local t,e=c:unpack(a,e) +local o=nil if t>0 then local t=t-1 -a=o:sub(e,e+t-1) -end -return a,e+t +o=a:sub(e,e+t-1) +end +return o,e+t end, pack= function(a,t) e(n(t)=="nil"or n(t)=="string", "unexpected value type to pack as a String") if t==nil then -return m:pack(0) -end -return m:pack(#t+1)..t.."\000" +return c:pack(0) +end +return c:pack(#t+1)..t.."\000" end } -local y=f{ -b(4){name="signature"}, +local p=f{ +v(4){name="signature"}, a{name="version"}, a{name="format"}, a{name="endianness"}, @@ -2141,17 +2161,17 @@ a{name="sizeof_Number"}, a{name="integral_flag"}, } -local b={ -[0]=q, -[1]=k, -[3]=j, -[4]=m, +local v={ +[0]=j, +[1]=q, +[3]=g, +[4]=c, } -local b=t{ +local g=t{ unpack= function(i,o,t) local t,i=a:unpack(o,t) -local a=b[t] +local a=v[t] e(a,"unknown constant type "..t.." to unpack") local a,o=a:unpack(o,i) if t==3 then @@ -2165,74 +2185,74 @@ pack= function(t,e) local e,t=e.type,e.value -return a:pack(e)..b[e]:pack(t) +return a:pack(e)..v[e]:pack(t) end } -local k=f{ -m{name="name"}, +local v=f{ +c{name="name"}, i{name="startpc"}, i{name="endpc"} } local a=f{ -m{name="name"}, +c{name="name"}, i{name="line"}, i{name="last_line"}, a{name="num_upvalues"}, a{name="num_parameters"}, a{name="is_vararg"}, a{name="max_stack_size"}, -l{name="insns",type=g}, -l{name="constants",type=b}, -l{name="prototypes",type=nil}, -l{name="source_lines",type=i}, -l{name="locals",type=k}, -l{name="upvalues",type=m}, +d{name="insns",type=k}, +d{name="constants",type=g}, +d{name="prototypes",type=nil}, +d{name="source_lines",type=i}, +d{name="locals",type=v}, +d{name="upvalues",type=c}, } e(a[10].name=="prototypes", "missed the function prototype list") a[10].type=a local a=t{ unpack= -function(i,l,t) -local i={} -local t,n=y:unpack(l,t) +function(i,d,t) +local n={} +local t,i=p:unpack(d,t) e(t.signature=="\027Lua","signature check failed") e(t.version==81,"version mismatch") e(t.format==0,"format mismatch") e(t.endianness==0 or t.endianness==1,"endianness mismatch") -e(d[t.sizeof_int],"int size unsupported") -e(d[t.sizeof_size_t],"size_t size unsupported") +e(l[t.sizeof_int],"int size unsupported") +e(l[t.sizeof_size_t],"size_t size unsupported") e(t.sizeof_insn==4,"insn size unsupported") e(w[t.sizeof_Number],"number size unsupported") e(t.integral_flag==0,"integral flag mismatch; only floats supported") -v() +y() o=t.endianness==0 -h=t.sizeof_size_t +r=t.sizeof_size_t s=t.sizeof_int -r=t.sizeof_Number -i.header=t -i.body,n=a:unpack(l,n) -p() -return i,n +h=t.sizeof_Number +n.header=t +n.body,i=a:unpack(d,i) +b() +return n,i end, pack= function(e,t) local i -v() +y() local e=t.header o=e.endianness==0 -h=e.sizeof_size_t +r=e.sizeof_size_t s=e.sizeof_int -r=e.sizeof_Number -i=y:pack(t.header)..a:pack(t.body) -p() +h=e.sizeof_Number +i=p:pack(t.header)..a:pack(t.body) +b() return i end } local function o(e) if n(e)=="function"then -return o(c.dump(e)) +return o(m.dump(e)) end local t=a:unpack(e,1) local a=a:pack(t) @@ -2319,43 +2339,73 @@ end\ \ "e["gunzip.lua"]="local base_char,keywords=128,{\"and\",\"break\",\"do\",\"else\",\"elseif\",\"end\",\"false\",\"for\",\"function\",\"if\",\"in\",\"local\",\"nil\",\"not\",\"or\",\"repeat\",\"return\",\"then\",\"true\",\"until\",\"while\",\"read\",\"nbits\",\"nbits_left_in_byte\",\"wnd_pos\",\"output\",\"val\",\"input\",}; function prettify(code) return code:gsub(\"[\"..string.char(base_char)..\"-\"..string.char(base_char+#keywords)..\"]\", \ -\9function (c) return keywords[c:byte()-base_char]; end) end return setfenv(assert(loadstring(prettify[===[ i,h,b,m,l,d,e,y,r,w,u,v,l,l=assert,error,ipairs,pairs,tostring,type,setmetatable,io,math,table.sort,math.max,string.char,io.open,_G; p(n) l={}; e=e({},l) l:__index(l) n=n(l);e[l]=n\ +\9function (c) return keywords[c:byte()-base_char]; end) end return setfenv(assert(loadstring(prettify[===[ i,h,b,m,l,d,e,y,r,w,\ +u,v,l,l=\ +assert,error,ipairs,pairs,tostring,type,setmetatable,io,math,table.sort,\ +math.max,string.char,io.open,_G;\ + p(n)\ + l={};\ + e=e({},l)\ + l:__index(l)\ + n=n(l);e[l]=n\ n\ \ e\ \ - l(n,l)l=l 1\ -h({n},l+1)\ - _(n) l={}l.outbs=n\ -l.wnd={}l.=1\ + l(n,l)\ +l=l 1\ +h({n},l+1)\ +\ + _(n)\ + l={}\ +l.outbs=n\ +l.wnd={}\ +l.=1\ l\ \ - t(l,e) n=l.\ -l.outbs(e)l.wnd[n]=e\ + t(l,e)\ + n=l.\ +l.outbs(e)\ +l.wnd[n]=e\ l.=n%32768+1\ \ - n(l) i(l,'unexpected end of file')\ - o(n,l) n%(l+l)>=l\ + n(l)\ + i(l,'unexpected end of file')\ +\ + o(n,l)\ + n%(l+l)>=l\ \ - a=p((l) 2^l ) c=e({},{__mode='k'}) g(o) l=1\ - e={} e:() n\ + a=p((l) 2^l )\ + c=e({},{__mode='k'})\ + g(o)\ + l=1\ + e={}\ + e:()\ + n\ l<=#o \ -n=o:byte(l)l=l+1\ +n=o:byte(l)\ +l=l+1\ \ n\ \ e\ \ l\ - s(d) n,l,o=0,0,{}; o:() l\ + s(d)\ + n,l,o=0,0,{};\ + o:()\ + l\ \ - o:(e)e=e 1\ + o:(e)\ +e=e 1\ l255 then -a:write(s); +a:write(t); a:close(); os.rename(o..".uglified",o); return; @@ -3046,8 +3189,8 @@ d[e]=string.char(i+t); end local r=0; -t:gsub("(=+)",function(e)r=math.max(r,#e);end); -h.init(s,"@"..l); +s:gsub("(=+)",function(e)r=math.max(r,#e);end); +h.init(t,"@"..l); h.llex() local s=h.seminfo; if e.uglify_level=="full"and i+#n<255 then @@ -3071,11 +3214,11 @@ for t=t+1,#e do e[t]=nil; end -local a=#n; -for t,e in ipairs(e)do +local t=#n; +for a,e in ipairs(e)do if e.score>0 then table.insert(n,e.value); -d[e.value]=string.char(i+a+t); +d[e.value]=string.char(i+t+a); end end end @@ -3087,16 +3230,16 @@ function (c) return keywords[c:byte()-base_char]; end) end ]] a:write[[return setfenv(assert(loadstring(prettify]] a:write("[",string.rep("=",r+1),"["); -for t,e in ipairs(h.tok)do -if e=="TK_KEYWORD"or e=="TK_NAME"or e=="TK_STRING"then -local e=d[s[t]]; -if e then -a:write(e); +for e,t in ipairs(h.tok)do +if t=="TK_KEYWORD"or t=="TK_NAME"or t=="TK_STRING"then +local t=d[s[e]]; +if t then +a:write(t); else -a:write(s[t]); +a:write(s[e]); end else -a:write(s[t]); +a:write(s[e]); end end a:write("]",string.rep("=",r+1),"]"); @@ -3110,21 +3253,21 @@ o("OK!"); end local i=require"minichunkspy" -function compile_string(a,t) -local a=string.dump(loadstring(a,t)); +function compile_string(t,a) +local o=string.dump(loadstring(t,a)); if((not e.debug)or e.compile_strip)and e.compile_strip~=false then -local a=i.disassemble(a); -local function t(e) +local t=i.disassemble(o); +local function a(e) e.source_lines,e.locals,e.upvalues={},{},{}; -for a,e in ipairs(e.prototypes)do -t(e); +for t,e in ipairs(e.prototypes)do +a(e); end end s("Stripping debug info..."); -t(a.body); -return i.assemble(a); -end -return a; +a(t.body); +return i.assemble(t); +end +return o; end function compile_file(a,e) local o,a=io.open(a); @@ -3163,12 +3306,12 @@ t("Can't open output file for writing: "..tostring(i)); return; end -local n=o:read("*a"); +local i=o:read("*a"); o:close(); -local i,o=n:match("^(#.-\n)(.+)$"); -local o=o or n; -if i then -e:write(i) +local n,o=i:match("^(#.-\n)(.+)$"); +local o=o or i; +if n then +e:write(n) end local i,n=io.open(a..".pregzip","wb+"); if not i then