1 #!/usr/bin/env lua5.2 |
1 #!/usr/bin/lua5.2 |
2 package.preload['optlex']=(function(...) |
2 package.preload['optlex']=(function(...) |
3 local _ENV=_ENV; |
3 local _ENV=_ENV; |
4 local function a(t,...) |
4 local function e(t,...) |
5 local e=package.loaded[t]or _ENV[t]or{_NAME=t}; |
5 local e=package.loaded[t]or _ENV[t]or{_NAME=t}; |
6 package.loaded[t]=e; |
6 package.loaded[t]=e; |
7 for t=1,select("#",...)do |
7 for t=1,select("#",...)do |
8 (select(t,...))(e); |
8 (select(t,...))(e); |
9 end |
9 end |
10 _ENV=e; |
10 _ENV=e; |
11 _M=e; |
11 _M=e; |
12 return e; |
12 return e; |
13 end |
13 end |
14 local h=_G |
14 local s=_G |
15 local m=require"string" |
15 local u=require"string" |
16 a"optlex" |
16 local i=u.match |
17 local i=m.match |
17 local e=u.sub |
18 local e=m.sub |
18 local r=u.find |
19 local r=m.find |
19 local l=u.rep |
20 local l=m.rep |
|
21 local c |
20 local c |
22 error=h.error |
21 error=s.error |
23 warn={} |
22 warn={} |
24 local n,o,d |
23 local n,o,d |
25 local k={ |
24 local q={ |
26 TK_KEYWORD=true, |
25 TK_KEYWORD=true, |
27 TK_NAME=true, |
26 TK_NAME=true, |
28 TK_NUMBER=true, |
27 TK_NUMBER=true, |
29 TK_STRING=true, |
28 TK_STRING=true, |
30 TK_LSTRING=true, |
29 TK_LSTRING=true, |
31 TK_OP=true, |
30 TK_OP=true, |
32 TK_EOS=true, |
31 TK_EOS=true, |
33 } |
32 } |
34 local v={ |
33 local b={ |
35 TK_COMMENT=true, |
34 TK_COMMENT=true, |
36 TK_LCOMMENT=true, |
35 TK_LCOMMENT=true, |
37 TK_EOL=true, |
36 TK_EOL=true, |
38 TK_SPACE=true, |
37 TK_SPACE=true, |
39 } |
38 } |
40 local s |
39 local h |
41 local function q(e) |
40 local function k(e) |
42 local t=n[e-1] |
41 local t=n[e-1] |
43 if e<=1 or t=="TK_EOL"then |
42 if e<=1 or t=="TK_EOL"then |
44 return true |
43 return true |
45 elseif t==""then |
44 elseif t==""then |
46 return q(e-1) |
45 return k(e-1) |
47 end |
46 end |
48 return false |
47 return false |
49 end |
48 end |
50 local function j(t) |
49 local function g(e) |
51 local e=n[t+1] |
50 local t=n[e+1] |
52 if t>=#n or e=="TK_EOL"or e=="TK_EOS"then |
51 if e>=#n or t=="TK_EOL"or t=="TK_EOS"then |
53 return true |
52 return true |
54 elseif e==""then |
53 elseif t==""then |
55 return j(t+1) |
54 return g(e+1) |
56 end |
55 end |
57 return false |
56 return false |
58 end |
57 end |
59 local function T(t) |
58 local function E(a) |
60 local a=#i(t,"^%-%-%[=*%[") |
59 local t=#i(a,"^%-%-%[=*%[") |
61 local a=e(t,a+1,-(a-1)) |
60 local a=e(a,t+1,-(t-1)) |
62 local e,t=1,0 |
61 local e,t=1,0 |
63 while true do |
62 while true do |
64 local o,n,i,a=r(a,"([\r\n])([\r\n]?)",e) |
63 local a,n,i,o=r(a,"([\r\n])([\r\n]?)",e) |
65 if not o then break end |
64 if not a then break end |
66 e=o+1 |
65 e=a+1 |
67 t=t+1 |
66 t=t+1 |
68 if#a>0 and i~=a then |
67 if#o>0 and i~=o then |
69 e=e+1 |
68 e=e+1 |
70 end |
69 end |
71 end |
70 end |
72 return t |
71 return t |
73 end |
72 end |
74 local function b(s,h) |
73 local function v(s,h) |
75 local a=i |
74 local a=i |
76 local t,e=n[s],n[h] |
75 local t,e=n[s],n[h] |
77 if t=="TK_STRING"or t=="TK_LSTRING"or |
76 if t=="TK_STRING"or t=="TK_LSTRING"or |
78 e=="TK_STRING"or e=="TK_LSTRING"then |
77 e=="TK_STRING"or e=="TK_LSTRING"then |
79 return"" |
78 return"" |
193 n=t.."e"..a |
192 n=t.."e"..a |
194 end |
193 end |
195 end |
194 end |
196 end |
195 end |
197 if n and n~=o[r]then |
196 if n and n~=o[r]then |
198 if s then |
197 if h then |
199 c("<number> (line "..d[r]..") "..o[r].." -> "..n) |
198 c("<number> (line "..d[r]..") "..o[r].." -> "..n) |
200 s=s+1 |
199 h=h+1 |
201 end |
200 end |
202 o[r]=n |
201 o[r]=n |
203 end |
202 end |
204 end |
203 end |
205 local function I(u) |
204 local function z(m) |
206 local t=o[u] |
205 local t=o[m] |
207 local n=e(t,1,1) |
206 local n=e(t,1,1) |
208 local f=(n=="'")and'"'or"'" |
207 local f=(n=="'")and'"'or"'" |
209 local t=e(t,2,-2) |
208 local t=e(t,2,-2) |
210 local a=1 |
209 local a=1 |
211 local l,h=0,0 |
210 local l,s=0,0 |
212 while a<=#t do |
211 while a<=#t do |
213 local u=e(t,a,a) |
212 local c=e(t,a,a) |
214 if u=="\\"then |
213 if c=="\\"then |
215 local o=a+1 |
214 local o=a+1 |
216 local d=e(t,o,o) |
215 local d=e(t,o,o) |
217 local s=r("abfnrtv\\\n\r\"\'0123456789",d,1,true) |
216 local h=r("abfnrtv\\\n\r\"\'0123456789",d,1,true) |
218 if not s then |
217 if not h then |
219 t=e(t,1,a-1)..e(t,o) |
218 t=e(t,1,a-1)..e(t,o) |
220 a=a+1 |
219 a=a+1 |
221 elseif s<=8 then |
220 elseif h<=8 then |
222 a=a+2 |
221 a=a+2 |
223 elseif s<=10 then |
222 elseif h<=10 then |
224 local i=e(t,o,o+1) |
223 local i=e(t,o,o+1) |
225 if i=="\r\n"or i=="\n\r"then |
224 if i=="\r\n"or i=="\n\r"then |
226 t=e(t,1,a).."\n"..e(t,o+2) |
225 t=e(t,1,a).."\n"..e(t,o+2) |
227 elseif s==10 then |
226 elseif h==10 then |
228 t=e(t,1,a).."\n"..e(t,o+1) |
227 t=e(t,1,a).."\n"..e(t,o+1) |
229 end |
228 end |
230 a=a+2 |
229 a=a+2 |
231 elseif s<=12 then |
230 elseif h<=12 then |
232 if d==n then |
231 if d==n then |
233 l=l+1 |
232 l=l+1 |
234 a=a+2 |
233 a=a+2 |
235 else |
234 else |
236 h=h+1 |
235 s=s+1 |
237 t=e(t,1,a-1)..e(t,o) |
236 t=e(t,1,a-1)..e(t,o) |
238 a=a+1 |
237 a=a+1 |
239 end |
238 end |
240 else |
239 else |
241 local i=i(t,"^(%d%d?%d?)",o) |
240 local i=i(t,"^(%d%d?%d?)",o) |
242 o=a+1+#i |
241 o=a+1+#i |
243 local d=i+0 |
242 local d=i+0 |
244 local s=m.char(d) |
243 local h=u.char(d) |
245 local r=r("\a\b\f\n\r\t\v",s,1,true) |
244 local r=r("\a\b\f\n\r\t\v",h,1,true) |
246 if r then |
245 if r then |
247 i="\\"..e("abfnrtv",r,r) |
246 i="\\"..e("abfnrtv",r,r) |
248 elseif d<32 then |
247 elseif d<32 then |
249 i="\\"..d |
248 i="\\"..d |
250 elseif s==n then |
249 elseif h==n then |
251 i="\\"..s |
250 i="\\"..h |
252 l=l+1 |
251 l=l+1 |
253 elseif s=="\\"then |
252 elseif h=="\\"then |
254 i="\\\\" |
253 i="\\\\" |
255 else |
254 else |
256 i=s |
255 i=h |
257 if s==f then |
256 if h==f then |
258 h=h+1 |
257 s=s+1 |
259 end |
258 end |
260 end |
259 end |
261 t=e(t,1,a-1)..i..e(t,o) |
260 t=e(t,1,a-1)..i..e(t,o) |
262 a=a+#i |
261 a=a+#i |
263 end |
262 end |
264 else |
263 else |
265 a=a+1 |
264 a=a+1 |
266 if u==f then |
265 if c==f then |
267 h=h+1 |
266 s=s+1 |
268 end |
267 end |
269 end |
268 end |
270 end |
269 end |
271 if l>h then |
270 if l>s then |
272 a=1 |
271 a=1 |
273 while a<=#t do |
272 while a<=#t do |
274 local o,s,i=r(t,"([\'\"])",a) |
273 local o,s,i=r(t,"([\'\"])",a) |
275 if not o then break end |
274 if not o then break end |
276 if i==n then |
275 if i==n then |
381 if not i(n,t)then a=e end |
380 if not i(n,t)then a=e end |
382 e=e-1 |
381 e=e-1 |
383 end |
382 end |
384 if a then |
383 if a then |
385 t=l("=",a-2) |
384 t=l("=",a-2) |
386 h,u="--["..t.."[","]"..t.."]" |
385 h,d="--["..t.."[","]"..t.."]" |
387 end |
386 end |
388 end |
387 end |
389 o[d]=h..n..u |
388 o[u]=h..n..d |
390 end |
389 end |
391 local function p(n) |
390 local function p(a) |
392 local t=o[n] |
391 local t=o[a] |
393 local a=i(t,"%s*$") |
392 local i=i(t,"%s*$") |
394 if#a>0 then |
393 if#i>0 then |
395 t=e(t,1,-(a+1)) |
394 t=e(t,1,-(i+1)) |
396 end |
395 end |
397 o[n]=t |
396 o[a]=t |
398 end |
397 end |
399 local function x(o,a) |
398 local function A(o,a) |
400 if not o then return false end |
399 if not o then return false end |
401 local t=i(a,"^%-%-%[=*%[") |
400 local t=i(a,"^%-%-%[=*%[") |
402 local t=#t |
401 local t=#t |
403 local i=e(a,-t,-1) |
402 local i=e(a,-t,-1) |
404 local e=e(a,t+1,-(t-1)) |
403 local e=e(a,t+1,-(t-1)) |
405 if r(e,o,1,true)then |
404 if r(e,o,1,true)then |
406 return true |
405 return true |
407 end |
406 end |
408 end |
407 end |
409 function optimize(t,r,a,i) |
408 function optimize(t,i,r,a) |
410 local m=t["opt-comments"] |
409 local m=t["opt-comments"] |
411 local u=t["opt-whitespace"] |
410 local u=t["opt-whitespace"] |
412 local f=t["opt-emptylines"] |
411 local f=t["opt-emptylines"] |
413 local y=t["opt-eols"] |
412 local y=t["opt-eols"] |
414 local z=t["opt-strings"] |
413 local I=t["opt-strings"] |
415 local E=t["opt-numbers"] |
414 local T=t["opt-numbers"] |
416 local _=t.KEEP |
415 local O=t.KEEP |
417 s=t.DETAILS and 0 |
416 h=t.DETAILS and 0 |
418 c=c or h.print |
417 c=c or s.print |
419 if y then |
418 if y then |
420 m=true |
419 m=true |
421 u=true |
420 u=true |
422 f=true |
421 f=true |
423 end |
422 end |
424 n,o,d |
423 n,o,d |
425 =r,a,i |
424 =i,r,a |
426 local t=1 |
425 local t=1 |
427 local a,r |
426 local a,r |
428 local h |
427 local s |
429 local function i(a,i,e) |
428 local function i(i,a,e) |
430 e=e or t |
429 e=e or t |
431 n[e]=a or"" |
430 n[e]=i or"" |
432 o[e]=i or"" |
431 o[e]=a or"" |
433 end |
432 end |
434 while true do |
433 while true do |
435 a,r=n[t],o[t] |
434 a,r=n[t],o[t] |
436 local s=q(t) |
435 local h=k(t) |
437 if s then h=nil end |
436 if h then s=nil end |
438 if a=="TK_EOS"then |
437 if a=="TK_EOS"then |
439 break |
438 break |
440 elseif a=="TK_KEYWORD"or |
439 elseif a=="TK_KEYWORD"or |
441 a=="TK_NAME"or |
440 a=="TK_NAME"or |
442 a=="TK_OP"then |
441 a=="TK_OP"then |
443 h=t |
442 s=t |
444 elseif a=="TK_NUMBER"then |
443 elseif a=="TK_NUMBER"then |
445 if E then |
444 if T then |
446 A(t) |
445 x(t) |
447 end |
446 end |
448 h=t |
447 s=t |
449 elseif a=="TK_STRING"or |
448 elseif a=="TK_STRING"or |
450 a=="TK_LSTRING"then |
449 a=="TK_LSTRING"then |
451 if z then |
450 if I then |
452 if a=="TK_STRING"then |
451 if a=="TK_STRING"then |
453 I(t) |
452 z(t) |
454 else |
453 else |
455 O(t) |
454 _(t) |
456 end |
455 end |
457 end |
456 end |
458 h=t |
457 s=t |
459 elseif a=="TK_COMMENT"then |
458 elseif a=="TK_COMMENT"then |
460 if m then |
459 if m then |
461 if t==1 and e(r,1,1)=="#"then |
460 if t==1 and e(r,1,1)=="#"then |
462 p(t) |
461 p(t) |
463 else |
462 else |
830 else |
828 else |
831 e.oldname=e.name |
829 e.oldname=e.name |
832 end |
830 end |
833 end |
831 end |
834 if r then |
832 if r then |
835 s[#s+1]="self" |
833 n[#n+1]="self" |
836 end |
834 end |
837 local e=f(o) |
835 local e=f(o) |
838 end |
836 end |
839 return _M; |
837 return{optimize=optimize} |
840 end) |
838 end) |
841 package.preload['llex']=(function(...) |
839 package.preload['llex']=(function(...) |
842 local _ENV=_ENV; |
840 local _ENV=_ENV; |
843 local function a(t,...) |
841 local function e(t,...) |
844 local e=package.loaded[t]or _ENV[t]or{_NAME=t}; |
842 local e=package.loaded[t]or _ENV[t]or{_NAME=t}; |
845 package.loaded[t]=e; |
843 package.loaded[t]=e; |
846 for t=1,select("#",...)do |
844 for t=1,select("#",...)do |
847 (select(t,...))(e); |
845 (select(t,...))(e); |
848 end |
846 end |
849 _ENV=e; |
847 _ENV=e; |
850 _M=e; |
848 _M=e; |
851 return e; |
849 return e; |
852 end |
850 end |
853 local d=_G |
851 local y=_G |
854 local h=require"string" |
852 local s=require"string" |
855 a"llex" |
853 local l=s.find |
856 local u=h.find |
854 local c=s.match |
857 local c=h.match |
855 local n=s.sub |
858 local i=h.sub |
856 local e='' |
859 local f={} |
857 local r='' |
860 for e in h.gmatch([[ |
858 local a=1 |
|
859 local d=1 |
|
860 local m={} |
|
861 local w={} |
|
862 local p={} |
|
863 local i='' |
|
864 local v={} |
|
865 for e in s.gmatch([[ |
861 and break do else elseif end false for function if in |
866 and break do else elseif end false for function if in |
862 local nil not or repeat return then true until while]],"%S+")do |
867 local nil not or repeat return then true until while]],"%S+")do |
863 f[e]=true |
868 v[e]=true |
864 end |
869 end |
865 local e, |
|
866 r, |
|
867 a, |
|
868 n, |
|
869 s |
|
870 local function o(a,t) |
870 local function o(a,t) |
871 local e=#tok+1 |
871 local e=#m+1 |
872 tok[e]=a |
872 m[e]=a |
873 seminfo[e]=t |
873 w[e]=t |
874 tokln[e]=s |
874 p[e]=d |
875 end |
875 end |
876 local function l(t,h) |
876 local function h(t,s) |
877 local n=i |
877 local n=n |
878 local i=n(e,t,t) |
878 local i=n(e,t,t) |
879 t=t+1 |
879 t=t+1 |
880 local e=n(e,t,t) |
880 local e=n(e,t,t) |
881 if(e=="\n"or e=="\r")and(e~=i)then |
881 if(e=="\n"or e=="\r")and(e~=i)then |
882 t=t+1 |
882 t=t+1 |
883 i=i..e |
883 i=i..e |
884 end |
884 end |
885 if h then o("TK_EOL",i)end |
885 if s then o("TK_EOL",i)end |
886 s=s+1 |
886 d=d+1 |
887 a=t |
887 a=t |
888 return t |
888 return t |
889 end |
889 end |
890 function init(i,t) |
890 function init(i,t) |
891 e=i |
891 e=i |
892 r=t |
892 r=t |
893 a=1 |
893 local t,n,e,i=l(e,"^(#[^\r\n]*)(\r?\n?)") |
894 s=1 |
894 if t then |
895 tok={} |
|
896 seminfo={} |
|
897 tokln={} |
|
898 local i,n,e,t=u(e,"^(#[^\r\n]*)(\r?\n?)") |
|
899 if i then |
|
900 a=a+#e |
895 a=a+#e |
901 o("TK_COMMENT",e) |
896 o("TK_COMMENT",e) |
902 if#t>0 then l(a,true)end |
897 if#i>0 then h(a,true)end |
903 end |
898 end |
904 end |
899 end |
905 function chunkid() |
900 function chunkid() |
906 if r and c(r,"^[=@]")then |
901 if r and c(r,"^[=@]")then |
907 return i(r,2) |
902 return n(r,2) |
908 end |
903 end |
909 return"[string]" |
904 return"[string]" |
910 end |
905 end |
911 function errorline(a,t) |
906 function errorline(t,a) |
912 local e=error or d.error |
907 local e=error or y.error |
913 e(h.format("%s:%d: %s",chunkid(),t or s,a)) |
908 e(s.format("%s:%d: %s",chunkid(),a or d,t)) |
914 end |
909 end |
915 local r=errorline |
910 local r=errorline |
916 local function m(t) |
911 local function u(t) |
917 local i=i |
912 local i=n |
918 local n=i(e,t,t) |
913 local n=i(e,t,t) |
919 t=t+1 |
914 t=t+1 |
920 local o=#c(e,"=*",t) |
915 local o=#c(e,"=*",t) |
921 t=t+o |
916 t=t+o |
922 a=t |
917 a=t |
923 return(i(e,t,t)==n)and o or(-o)-1 |
918 return(i(e,t,t)==n)and o or(-o)-1 |
924 end |
919 end |
925 local function w(d,h) |
920 local function f(d,s) |
926 local t=a+1 |
921 local t=a+1 |
927 local i=i |
922 local n=n |
928 local o=i(e,t,t) |
923 local o=n(e,t,t) |
929 if o=="\r"or o=="\n"then |
924 if o=="\r"or o=="\n"then |
930 t=l(t) |
925 t=h(t) |
931 end |
926 end |
932 local o=t |
927 local o=t |
933 while true do |
928 while true do |
934 local o,u,s=u(e,"([\r\n%]])",t) |
929 local o,c,l=l(e,"([\r\n%]])",t) |
935 if not o then |
930 if not o then |
936 r(d and"unfinished long string"or |
931 r(d and"unfinished long string"or |
937 "unfinished long comment") |
932 "unfinished long comment") |
938 end |
933 end |
939 t=o |
934 t=o |
940 if s=="]"then |
935 if l=="]"then |
941 if m(t)==h then |
936 if u(t)==s then |
942 n=i(e,n,a) |
937 i=n(e,i,a) |
943 a=a+1 |
938 a=a+1 |
944 return n |
939 return i |
945 end |
940 end |
946 t=a |
941 t=a |
947 else |
942 else |
948 n=n.."\n" |
943 i=i.."\n" |
949 t=l(t) |
944 t=h(t) |
950 end |
945 end |
951 end |
946 end |
952 end |
947 end |
953 local function y(d) |
948 local function b(u) |
954 local t=a |
949 local t=a |
955 local s=u |
950 local s=l |
956 local h=i |
951 local d=n |
957 while true do |
952 while true do |
958 local i,u,o=s(e,"([\n\r\\\"\'])",t) |
953 local n,l,o=s(e,"([\n\r\\\"\'])",t) |
959 if i then |
954 if n then |
960 if o=="\n"or o=="\r"then |
955 if o=="\n"or o=="\r"then |
961 r("unfinished string") |
956 r("unfinished string") |
962 end |
957 end |
963 t=i |
958 t=n |
964 if o=="\\"then |
959 if o=="\\"then |
965 t=t+1 |
960 t=t+1 |
966 o=h(e,t,t) |
961 o=d(e,t,t) |
967 if o==""then break end |
962 if o==""then break end |
968 i=s("abfnrtv\n\r",o,1,true) |
963 n=s("abfnrtv\n\r",o,1,true) |
969 if i then |
964 if n then |
970 if i>7 then |
965 if n>7 then |
971 t=l(t) |
966 t=h(t) |
972 else |
967 else |
973 t=t+1 |
968 t=t+1 |
974 end |
969 end |
975 elseif s(o,"%D")then |
970 elseif s(o,"%D")then |
976 t=t+1 |
971 t=t+1 |
981 r("escape sequence too large") |
976 r("escape sequence too large") |
982 end |
977 end |
983 end |
978 end |
984 else |
979 else |
985 t=t+1 |
980 t=t+1 |
986 if o==d then |
981 if o==u then |
987 a=t |
982 a=t |
988 return h(e,n,t-1) |
983 return d(e,i,t-1) |
989 end |
984 end |
990 end |
985 end |
991 else |
986 else |
992 break |
987 break |
993 end |
988 end |
994 end |
989 end |
995 r("unfinished string") |
990 r("unfinished string") |
996 end |
991 end |
997 function llex() |
992 function llex() |
998 local s=u |
993 local s=l |
999 local u=c |
994 local d=c |
1000 while true do |
995 while true do |
1001 local t=a |
996 local t=a |
1002 while true do |
997 while true do |
1003 local c,p,h=s(e,"^([_%a][_%w]*)",t) |
998 local c,m,l=s(e,"^([_%a][_%w]*)",t) |
1004 if c then |
999 if c then |
1005 a=t+#h |
1000 a=t+#l |
1006 if f[h]then |
1001 if v[l]then |
1007 o("TK_KEYWORD",h) |
1002 o("TK_KEYWORD",l) |
1008 else |
1003 else |
1009 o("TK_NAME",h) |
1004 o("TK_NAME",l) |
1010 end |
1005 end |
1011 break |
1006 break |
1012 end |
1007 end |
1013 local h,f,c=s(e,"^(%.?)%d",t) |
1008 local l,m,c=s(e,"^(%.?)%d",t) |
1014 if h then |
1009 if l then |
1015 if c=="."then t=t+1 end |
1010 if c=="."then t=t+1 end |
1016 local c,l,n=s(e,"^%d*[%.%d]*([eE]?)",t) |
1011 local u,h,i=s(e,"^%d*[%.%d]*([eE]?)",t) |
1017 t=l+1 |
1012 t=h+1 |
1018 if#n==1 then |
1013 if#i==1 then |
1019 if u(e,"^[%+%-]",t)then |
1014 if d(e,"^[%+%-]",t)then |
1020 t=t+1 |
1015 t=t+1 |
1021 end |
1016 end |
1022 end |
1017 end |
1023 local n,t=s(e,"^[_%w]*",t) |
1018 local i,t=s(e,"^[_%w]*",t) |
1024 a=t+1 |
1019 a=t+1 |
1025 local e=i(e,h,t) |
1020 local e=n(e,l,t) |
1026 if not d.tonumber(e)then |
1021 if not y.tonumber(e)then |
1027 r("malformed number") |
1022 r("malformed number") |
1028 end |
1023 end |
1029 o("TK_NUMBER",e) |
1024 o("TK_NUMBER",e) |
1030 break |
1025 break |
1031 end |
1026 end |
1032 local d,c,f,h=s(e,"^((%s)[ \t\v\f]*)",t) |
1027 local m,w,c,l=s(e,"^((%s)[ \t\v\f]*)",t) |
1033 if d then |
1028 if m then |
1034 if h=="\n"or h=="\r"then |
1029 if l=="\n"or l=="\r"then |
1035 l(t,true) |
1030 h(t,true) |
1036 else |
1031 else |
1037 a=c+1 |
1032 a=w+1 |
1038 o("TK_SPACE",f) |
1033 o("TK_SPACE",c) |
1039 end |
1034 end |
1040 break |
1035 break |
1041 end |
1036 end |
1042 local h=u(e,"^%p",t) |
1037 local h=d(e,"^%p",t) |
1043 if h then |
1038 if h then |
1044 n=t |
1039 i=t |
1045 local d=s("-[\"\'.=<>~",h,1,true) |
1040 local l=s("-[\"\'.=<>~",h,1,true) |
1046 if d then |
1041 if l then |
1047 if d<=2 then |
1042 if l<=2 then |
1048 if d==1 then |
1043 if l==1 then |
1049 local r=u(e,"^%-%-(%[?)",t) |
1044 local r=d(e,"^%-%-(%[?)",t) |
1050 if r then |
1045 if r then |
1051 t=t+2 |
1046 t=t+2 |
1052 local h=-1 |
1047 local h=-1 |
1053 if r=="["then |
1048 if r=="["then |
1054 h=m(t) |
1049 h=u(t) |
1055 end |
1050 end |
1056 if h>=0 then |
1051 if h>=0 then |
1057 o("TK_LCOMMENT",w(false,h)) |
1052 o("TK_LCOMMENT",f(false,h)) |
1058 else |
1053 else |
1059 a=s(e,"[\n\r]",t)or(#e+1) |
1054 a=s(e,"[\n\r]",t)or(#e+1) |
1060 o("TK_COMMENT",i(e,n,a-1)) |
1055 o("TK_COMMENT",n(e,i,a-1)) |
1061 end |
1056 end |
1062 break |
1057 break |
1063 end |
1058 end |
1064 else |
1059 else |
1065 local e=m(t) |
1060 local e=u(t) |
1066 if e>=0 then |
1061 if e>=0 then |
1067 o("TK_LSTRING",w(true,e)) |
1062 o("TK_LSTRING",f(true,e)) |
1068 elseif e==-1 then |
1063 elseif e==-1 then |
1069 o("TK_OP","[") |
1064 o("TK_OP","[") |
1070 else |
1065 else |
1071 r("invalid long string delimiter") |
1066 r("invalid long string delimiter") |
1072 end |
1067 end |
1073 break |
1068 break |
1074 end |
1069 end |
1075 elseif d<=5 then |
1070 elseif l<=5 then |
1076 if d<5 then |
1071 if l<5 then |
1077 a=t+1 |
1072 a=t+1 |
1078 o("TK_STRING",y(h)) |
1073 o("TK_STRING",b(h)) |
1079 break |
1074 break |
1080 end |
1075 end |
1081 h=u(e,"^%.%.?%.?",t) |
1076 h=d(e,"^%.%.?%.?",t) |
1082 else |
1077 else |
1083 h=u(e,"^%p=?",t) |
1078 h=d(e,"^%p=?",t) |
1084 end |
1079 end |
1085 end |
1080 end |
1086 a=t+#h |
1081 a=t+#h |
1087 o("TK_OP",h) |
1082 o("TK_OP",h) |
1088 break |
1083 break |
1089 end |
1084 end |
1090 local e=i(e,t,t) |
1085 local e=n(e,t,t) |
1091 if e~=""then |
1086 if e~=""then |
1092 a=t+1 |
1087 a=t+1 |
1093 o("TK_OP",e) |
1088 o("TK_OP",e) |
1094 break |
1089 break |
1095 end |
1090 end |
1096 o("TK_EOS","") |
1091 o("TK_EOS","") |
1097 return |
1092 return |
1098 end |
1093 end |
1099 end |
1094 end |
1100 end |
1095 end |
1101 d.print(_M) |
1096 return{ |
1102 d.assert(d.type(_M)=="table") |
1097 llex=llex, |
1103 return _M |
1098 init=init, |
|
1099 chunkid=chunkid, |
|
1100 tok=m, |
|
1101 tokln=p, |
|
1102 seminfo=w |
|
1103 } |
1104 end) |
1104 end) |
1105 package.preload['lparser']=(function(...) |
1105 package.preload['lparser']=(function(...) |
1106 local _ENV=_ENV; |
1106 local _ENV=_ENV; |
1107 local function a(t,...) |
1107 local function e(t,...) |
1108 local e=package.loaded[t]or _ENV[t]or{_NAME=t}; |
1108 local e=package.loaded[t]or _ENV[t]or{_NAME=t}; |
1109 package.loaded[t]=e; |
1109 package.loaded[t]=e; |
1110 for t=1,select("#",...)do |
1110 for t=1,select("#",...)do |
1111 (select(t,...))(e); |
1111 (select(t,...))(e); |
1112 end |
1112 end |
1113 _ENV=e; |
1113 _ENV=e; |
1114 _M=e; |
1114 _M=e; |
1115 return e; |
1115 return e; |
1116 end |
1116 end |
1117 local R=_G |
1117 local U=_G |
1118 local v=require"string" |
1118 local b=require"string" |
1119 a"lparser" |
1119 local D={} |
1120 local E, |
1120 local T, |
1121 j, |
1121 j, |
1122 T, |
1122 A, |
1123 S, |
1123 C, |
|
1124 d, |
1124 r, |
1125 r, |
1125 d, |
1126 P, |
1126 B, |
1127 t,k,l,y, |
1127 t,x,s,m, |
|
1128 p, |
1128 p, |
1129 a, |
1129 a, |
1130 K, |
1130 W, |
1131 q, |
1131 q, |
1132 N, |
1132 N, |
1133 l, |
1133 u, |
1134 b, |
1134 g, |
1135 A |
1135 E |
1136 local w,u,y,_,z,g |
1136 local f,n,w,_,x,v |
1137 local e=v.gmatch |
1137 local e=b.gmatch |
1138 local O={} |
1138 local H={} |
1139 for e in e("else elseif end until <eof>","%S+")do |
1139 for e in e("else elseif end until <eof>","%S+")do |
1140 O[e]=true |
1140 H[e]=true |
1141 end |
1141 end |
1142 local G={} |
1142 local Y={} |
1143 for e in e("if while do for repeat function local return break","%S+")do |
1143 for e in e("if while do for repeat function local return break","%S+")do |
1144 G[e]=e.."_stat" |
1144 Y[e]=e.."_stat" |
1145 end |
1145 end |
1146 local I={} |
1146 local S={} |
1147 local Q={} |
1147 local V={} |
1148 for e,a,t in e([[ |
1148 for e,a,t in e([[ |
1149 {+ 6 6}{- 6 6}{* 7 7}{/ 7 7}{% 7 7} |
1149 {+ 6 6}{- 6 6}{* 7 7}{/ 7 7}{% 7 7} |
1150 {^ 10 9}{.. 5 4} |
1150 {^ 10 9}{.. 5 4} |
1151 {~= 3 3}{== 3 3} |
1151 {~= 3 3}{== 3 3} |
1152 {< 3 3}{<= 3 3}{> 3 3}{>= 3 3} |
1152 {< 3 3}{<= 3 3}{> 3 3}{>= 3 3} |
1153 {and 2 2}{or 1 1} |
1153 {and 2 2}{or 1 1} |
1154 ]],"{(%S+)%s(%d+)%s(%d+)}")do |
1154 ]],"{(%S+)%s(%d+)%s(%d+)}")do |
1155 I[e]=a+0 |
1155 S[e]=a+0 |
1156 Q[e]=t+0 |
1156 V[e]=t+0 |
1157 end |
1157 end |
1158 local X={["not"]=true,["-"]=true, |
1158 local Z={["not"]=true,["-"]=true, |
1159 ["#"]=true,} |
1159 ["#"]=true,} |
1160 local Z=8 |
1160 local ee=8 |
1161 local function o(e,a) |
1161 local function o(t,a) |
1162 local t=error or R.error |
1162 local e=error or U.error |
1163 t(v.format("(source):%d: %s",a or s,e)) |
1163 e(b.format("(source):%d: %s",a or l,t)) |
1164 end |
1164 end |
1165 local function e() |
1165 local function e() |
1166 B=T[r] |
1166 P=A[d] |
1167 t,x,s,m |
1167 t,k,l,y |
1168 =E[r],j[r],T[r],S[r] |
1168 =T[d],j[d],A[d],C[d] |
1169 r=r+1 |
1169 d=d+1 |
1170 end |
1170 end |
1171 local function J() |
1171 local function X() |
1172 return E[r] |
1172 return T[d] |
1173 end |
1173 end |
1174 local function h(a) |
1174 local function s(a) |
1175 local e=t |
1175 local e=t |
1176 if e~="<number>"and e~="<string>"then |
1176 if e~="<number>"and e~="<string>"then |
1177 if e=="<name>"then e=x end |
1177 if e=="<name>"then e=k end |
1178 e="'"..e.."'" |
1178 e="'"..e.."'" |
1179 end |
1179 end |
1180 o(a.." near "..e) |
1180 o(a.." near "..e) |
1181 end |
1181 end |
1182 local function c(e) |
1182 local function c(e) |
1183 h("'"..e.."' expected") |
1183 s("'"..e.."' expected") |
1184 end |
1184 end |
1185 local function i(a) |
1185 local function o(a) |
1186 if t==a then e();return true end |
1186 if t==a then e();return true end |
1187 end |
1187 end |
1188 local function D(e) |
1188 local function L(e) |
1189 if t~=e then c(e)end |
1189 if t~=e then c(e)end |
1190 end |
1190 end |
1191 local function o(t) |
1191 local function i(t) |
1192 D(t);e() |
1192 L(t);e() |
1193 end |
1193 end |
1194 local function V(e,t) |
1194 local function F(e,t) |
1195 if not e then h(t)end |
1195 if not e then s(t)end |
1196 end |
1196 end |
1197 local function n(e,a,t) |
1197 local function h(e,a,t) |
1198 if not i(e)then |
1198 if not o(e)then |
1199 if t==s then |
1199 if t==l then |
1200 c(e) |
1200 c(e) |
1201 else |
1201 else |
1202 h("'"..e.."' expected (to close '"..a.."' at line "..t..")") |
1202 s("'"..e.."' expected (to close '"..a.."' at line "..t..")") |
1203 end |
1203 end |
1204 end |
1204 end |
1205 end |
1205 end |
1206 local function f() |
1206 local function c() |
1207 D("<name>") |
1207 L("<name>") |
1208 local t=x |
1208 local t=k |
1209 p=m |
1209 p=y |
1210 e() |
1210 e() |
1211 return t |
1211 return t |
1212 end |
1212 end |
1213 local function U(e,t) |
1213 local function I(e,t) |
1214 e.k="VK" |
1214 e.k="VK" |
1215 end |
1215 end |
1216 local function L(e) |
1216 local function R(e) |
1217 U(e,f()) |
1217 I(e,c()) |
1218 end |
1218 end |
1219 local function c(o,i) |
1219 local function m(o,i) |
1220 local t=a.bl |
1220 local e=a.bl |
1221 local e |
1221 local t |
1222 if t then |
1222 if e then |
1223 e=t.locallist |
1223 t=e.locallist |
1224 else |
1224 else |
1225 e=a.locallist |
1225 t=a.locallist |
1226 end |
1226 end |
1227 local t=#l+1 |
1227 local e=#u+1 |
1228 l[t]={ |
1228 u[e]={ |
1229 name=o, |
1229 name=o, |
1230 xref={p}, |
1230 xref={p}, |
1231 decl=p, |
1231 decl=p, |
1232 } |
1232 } |
1233 if i or o=="_ENV"then |
1233 if i or o=="_ENV"then |
1234 l[t].preserve=true |
1234 u[e].preserve=true |
1235 end |
1235 end |
1236 local a=#b+1 |
1236 local a=#g+1 |
1237 b[a]=t |
1237 g[a]=e |
1238 A[a]=e |
1238 E[a]=t |
1239 end |
1239 end |
1240 local function k(e) |
1240 local function z(e) |
1241 local t=#b |
1241 local t=#g |
1242 while e>0 do |
1242 while e>0 do |
1243 e=e-1 |
1243 e=e-1 |
1244 local e=t-e |
1244 local t=t-e |
1245 local a=b[e] |
1245 local a=g[t] |
1246 local t=l[a] |
1246 local e=u[a] |
1247 local o=t.name |
1247 local o=e.name |
1248 t.act=m |
1248 e.act=y |
1249 b[e]=nil |
1249 g[t]=nil |
1250 local i=A[e] |
1250 local i=E[t] |
1251 A[e]=nil |
1251 E[t]=nil |
1252 local e=i[o] |
1252 local t=i[o] |
1253 if e then |
1253 if t then |
1254 t=l[e] |
1254 e=u[t] |
1255 t.rem=-a |
1255 e.rem=-a |
1256 end |
1256 end |
1257 i[o]=a |
1257 i[o]=a |
1258 end |
1258 end |
1259 end |
1259 end |
1260 local function H() |
1260 local function O() |
1261 local t=a.bl |
1261 local t=a.bl |
1262 local e |
1262 local e |
1263 if t then |
1263 if t then |
1264 e=t.locallist |
1264 e=t.locallist |
1265 else |
1265 else |
1266 e=a.locallist |
1266 e=a.locallist |
1267 end |
1267 end |
1268 for t,e in R.pairs(e)do |
1268 for t,e in U.pairs(e)do |
1269 local e=l[e] |
1269 local e=u[e] |
1270 e.rem=m |
1270 e.rem=y |
1271 end |
1271 end |
1272 end |
1272 end |
1273 local function m(e,t) |
1273 local function y(e,t) |
1274 if v.sub(e,1,1)=="("then |
1274 if b.sub(e,1,1)=="("then |
1275 return |
1275 return |
1276 end |
1276 end |
1277 c(e,t) |
1277 m(e,t) |
1278 end |
1278 end |
1279 local function R(o,a) |
1279 local function U(o,a) |
1280 local t=o.bl |
1280 local t=o.bl |
1281 local e |
1281 local e |
1282 if t then |
1282 if t then |
1283 e=t.locallist |
1283 e=t.locallist |
1284 while e do |
1284 while e do |
1325 local e=q[e].xref |
1325 local e=q[e].xref |
1326 e[#e+1]=p |
1326 e[#e+1]=p |
1327 end |
1327 end |
1328 else |
1328 else |
1329 local e=o.id |
1329 local e=o.id |
1330 local e=l[e].xref |
1330 local e=u[e].xref |
1331 e[#e+1]=p |
1331 e[#e+1]=p |
1332 end |
1332 end |
1333 end |
1333 end |
1334 local function p(t) |
1334 local function p(t) |
1335 local e={} |
1335 local e={} |
1336 e.isbreakable=t |
1336 e.isbreakable=t |
1337 e.prev=a.bl |
1337 e.prev=a.bl |
1338 e.locallist={} |
1338 e.locallist={} |
1339 a.bl=e |
1339 a.bl=e |
1340 end |
1340 end |
1341 local function v() |
1341 local function b() |
1342 local e=a.bl |
1342 local e=a.bl |
1343 H() |
1343 O() |
1344 a.bl=e.prev |
1344 a.bl=e.prev |
1345 end |
1345 end |
1346 local function Y() |
1346 local function B() |
1347 local e |
1347 local e |
1348 if not a then |
1348 if not a then |
1349 e=K |
1349 e=W |
1350 else |
1350 else |
1351 e={} |
1351 e={} |
1352 end |
1352 end |
1353 e.prev=a |
1353 e.prev=a |
1354 e.bl=nil |
1354 e.bl=nil |
1355 e.locallist={} |
1355 e.locallist={} |
1356 a=e |
1356 a=e |
1357 end |
1357 end |
1358 local function F() |
1358 local function G() |
1359 H() |
1359 O() |
1360 a=a.prev |
1360 a=a.prev |
1361 end |
1361 end |
1362 local function H(a) |
1362 local function U(t) |
1363 local t={} |
1363 local a={} |
1364 e() |
1364 e() |
1365 L(t) |
1365 R(a) |
1366 a.k="VINDEXED" |
1366 t.k="VINDEXED" |
1367 end |
1367 end |
1368 local function M(t) |
1368 local function K(t) |
1369 e() |
1369 e() |
1370 u(t) |
1370 n(t) |
1371 o("]") |
1371 i("]") |
1372 end |
1372 end |
1373 local function R(e) |
1373 local function M(e) |
1374 local e,a={},{} |
1374 local e,a={},{} |
1375 if t=="<name>"then |
1375 if t=="<name>"then |
1376 L(e) |
1376 R(e) |
1377 else |
1377 else |
1378 M(e) |
1378 K(e) |
1379 end |
1379 end |
1380 o("=") |
1380 i("=") |
1381 u(a) |
1381 n(a) |
1382 end |
1382 end |
1383 local function C(e) |
1383 local function O(e) |
1384 if e.v.k=="VVOID"then return end |
1384 if e.v.k=="VVOID"then return end |
1385 e.v.k="VVOID" |
1385 e.v.k="VVOID" |
1386 end |
1386 end |
1387 local function C(e) |
1387 local function O(e) |
1388 u(e.v) |
1388 n(e.v) |
1389 end |
1389 end |
1390 local function W(a) |
1390 local function J(a) |
1391 local s=s |
1391 local n=l |
1392 local e={} |
1392 local e={} |
1393 e.v={} |
1393 e.v={} |
1394 e.t=a |
1394 e.t=a |
1395 a.k="VRELOCABLE" |
1395 a.k="VRELOCABLE" |
1396 e.v.k="VVOID" |
1396 e.v.k="VVOID" |
1397 o("{") |
1397 i("{") |
1398 repeat |
1398 repeat |
1399 if t=="}"then break end |
1399 if t=="}"then break end |
1400 local t=t |
1400 local t=t |
1401 if t=="<name>"then |
1401 if t=="<name>"then |
1402 if J()~="="then |
1402 if X()~="="then |
1403 C(e) |
1403 O(e) |
1404 else |
1404 else |
1405 R(e) |
1405 M(e) |
1406 end |
1406 end |
1407 elseif t=="["then |
1407 elseif t=="["then |
1408 R(e) |
1408 M(e) |
1409 else |
1409 else |
1410 C(e) |
1410 O(e) |
1411 end |
1411 end |
1412 until not i(",")and not i(";") |
1412 until not o(",")and not o(";") |
1413 n("}","{",s) |
1413 h("}","{",n) |
1414 end |
1414 end |
1415 local function J() |
1415 local function X() |
1416 local o=0 |
1416 local i=0 |
1417 if t~=")"then |
1417 if t~=")"then |
1418 repeat |
1418 repeat |
1419 local t=t |
1419 local t=t |
1420 if t=="<name>"then |
1420 if t=="<name>"then |
1421 c(f()) |
1421 m(c()) |
1422 o=o+1 |
1422 i=i+1 |
1423 elseif t=="..."then |
1423 elseif t=="..."then |
1424 e() |
1424 e() |
1425 a.is_vararg=true |
1425 a.is_vararg=true |
1426 else |
1426 else |
1427 h("<name> or '...' expected") |
1427 s("<name> or '...' expected") |
1428 end |
1428 end |
1429 until a.is_vararg or not i(",") |
1429 until a.is_vararg or not o(",") |
1430 end |
1430 end |
1431 k(o) |
1431 z(i) |
1432 end |
1432 end |
1433 local function C(r) |
1433 local function M(n) |
1434 local a={} |
1434 local a={} |
1435 local i=s |
1435 local i=l |
1436 local o=t |
1436 local o=t |
1437 if o=="("then |
1437 if o=="("then |
1438 if i~=B then |
1438 if i~=P then |
1439 h("ambiguous syntax (function call x new statement)") |
1439 s("ambiguous syntax (function call x new statement)") |
1440 end |
1440 end |
1441 e() |
1441 e() |
1442 if t==")"then |
1442 if t==")"then |
1443 a.k="VVOID" |
1443 a.k="VVOID" |
1444 else |
1444 else |
1445 w(a) |
1445 f(a) |
1446 end |
1446 end |
1447 n(")","(",i) |
1447 h(")","(",i) |
1448 elseif o=="{"then |
1448 elseif o=="{"then |
1449 W(a) |
1449 J(a) |
1450 elseif o=="<string>"then |
1450 elseif o=="<string>"then |
1451 U(a,x) |
1451 I(a,k) |
1452 e() |
1452 e() |
1453 else |
1453 else |
1454 h("function arguments expected") |
1454 s("function arguments expected") |
1455 return |
1455 return |
1456 end |
1456 end |
1457 r.k="VCALL" |
1457 n.k="VCALL" |
1458 end |
1458 end |
1459 local function B(a) |
1459 local function P(a) |
1460 local t=t |
1460 local t=t |
1461 if t=="("then |
1461 if t=="("then |
1462 local t=s |
1462 local t=l |
1463 e() |
1463 e() |
1464 u(a) |
1464 n(a) |
1465 n(")","(",t) |
1465 h(")","(",t) |
1466 elseif t=="<name>"then |
1466 elseif t=="<name>"then |
|
1467 Q(a) |
|
1468 else |
|
1469 s("unexpected symbol") |
|
1470 end |
|
1471 end |
|
1472 local function O(a) |
1467 P(a) |
1473 P(a) |
1468 else |
|
1469 h("unexpected symbol") |
|
1470 end |
|
1471 end |
|
1472 local function R(a) |
|
1473 B(a) |
|
1474 while true do |
1474 while true do |
1475 local t=t |
1475 local t=t |
1476 if t=="."then |
1476 if t=="."then |
1477 H(a) |
1477 U(a) |
1478 elseif t=="["then |
1478 elseif t=="["then |
1479 local e={} |
1479 local e={} |
1480 M(e) |
1480 K(e) |
1481 elseif t==":"then |
1481 elseif t==":"then |
1482 local t={} |
1482 local t={} |
1483 e() |
1483 e() |
1484 L(t) |
1484 R(t) |
1485 C(a) |
1485 M(a) |
1486 elseif t=="("or t=="<string>"or t=="{"then |
1486 elseif t=="("or t=="<string>"or t=="{"then |
1487 C(a) |
1487 M(a) |
1488 else |
1488 else |
1489 return |
1489 return |
1490 end |
1490 end |
1491 end |
1491 end |
1492 end |
1492 end |
1493 local function L(o) |
1493 local function R(o) |
1494 local t=t |
1494 local t=t |
1495 if t=="<number>"then |
1495 if t=="<number>"then |
1496 o.k="VKNUM" |
1496 o.k="VKNUM" |
1497 elseif t=="<string>"then |
1497 elseif t=="<string>"then |
1498 U(o,x) |
1498 I(o,k) |
1499 elseif t=="nil"then |
1499 elseif t=="nil"then |
1500 o.k="VNIL" |
1500 o.k="VNIL" |
1501 elseif t=="true"then |
1501 elseif t=="true"then |
1502 o.k="VTRUE" |
1502 o.k="VTRUE" |
1503 elseif t=="false"then |
1503 elseif t=="false"then |
1504 o.k="VFALSE" |
1504 o.k="VFALSE" |
1505 elseif t=="..."then |
1505 elseif t=="..."then |
1506 V(a.is_vararg==true, |
1506 F(a.is_vararg==true, |
1507 "cannot use '...' outside a vararg function"); |
1507 "cannot use '...' outside a vararg function"); |
1508 o.k="VVARARG" |
1508 o.k="VVARARG" |
1509 elseif t=="{"then |
1509 elseif t=="{"then |
1510 W(o) |
1510 J(o) |
1511 return |
1511 return |
1512 elseif t=="function"then |
1512 elseif t=="function"then |
1513 e() |
1513 e() |
1514 z(o,false,s) |
1514 x(o,false,l) |
1515 return |
1515 return |
1516 else |
1516 else |
1517 R(o) |
1517 O(o) |
1518 return |
1518 return |
1519 end |
1519 end |
1520 e() |
1520 e() |
1521 end |
1521 end |
1522 local function x(o,n) |
1522 local function k(o,n) |
1523 local a=t |
1523 local a=t |
1524 local i=X[a] |
1524 local i=Z[a] |
1525 if i then |
1525 if i then |
1526 e() |
1526 e() |
1527 x(o,Z) |
1527 k(o,ee) |
1528 else |
1528 else |
1529 L(o) |
1529 R(o) |
1530 end |
1530 end |
1531 a=t |
1531 a=t |
1532 local t=I[a] |
1532 local t=S[a] |
1533 while t and t>n do |
1533 while t and t>n do |
1534 local o={} |
1534 local o={} |
1535 e() |
1535 e() |
1536 local e=x(o,Q[a]) |
1536 local e=k(o,V[a]) |
1537 a=e |
1537 a=e |
1538 t=I[a] |
1538 t=S[a] |
1539 end |
1539 end |
1540 return a |
1540 return a |
1541 end |
1541 end |
1542 function u(e) |
1542 function n(e) |
1543 x(e,0) |
1543 k(e,0) |
1544 end |
1544 end |
1545 local function I(e) |
1545 local function I(e) |
1546 local t={} |
1546 local t={} |
1547 local e=e.v.k |
1547 local e=e.v.k |
1548 V(e=="VLOCAL"or e=="VUPVAL"or e=="VGLOBAL" |
1548 F(e=="VLOCAL"or e=="VUPVAL"or e=="VGLOBAL" |
1549 or e=="VINDEXED","syntax error") |
1549 or e=="VINDEXED","syntax error") |
1550 if i(",")then |
1550 if o(",")then |
1551 local e={} |
1551 local e={} |
1552 e.v={} |
1552 e.v={} |
1553 R(e.v) |
1553 O(e.v) |
1554 I(e) |
1554 I(e) |
1555 else |
1555 else |
1556 o("=") |
1556 i("=") |
1557 w(t) |
1557 f(t) |
1558 return |
1558 return |
1559 end |
1559 end |
1560 t.k="VNONRELOC" |
1560 t.k="VNONRELOC" |
1561 end |
1561 end |
1562 local function x(e,t) |
1562 local function k(e,t) |
1563 o("do") |
1563 i("do") |
1564 p(false) |
1564 p(false) |
1565 k(e) |
1565 z(e) |
1566 y() |
1566 w() |
1567 v() |
1567 b() |
1568 end |
1568 end |
1569 local function U(e) |
1569 local function R(e) |
1570 local t=d |
1570 local t=r |
1571 m("(for index)") |
1571 y("(for index)") |
1572 m("(for limit)") |
1572 y("(for limit)") |
1573 m("(for step)") |
1573 y("(for step)") |
1574 c(e) |
1574 m(e) |
1575 o("=") |
1575 i("=") |
1576 _() |
1576 _() |
1577 o(",") |
1577 i(",") |
1578 _() |
1578 _() |
1579 if i(",")then |
1579 if o(",")then |
1580 _() |
1580 _() |
1581 else |
1581 else |
1582 end |
1582 end |
1583 x(1,true) |
1583 k(1,true) |
1584 end |
1584 end |
1585 local function M(e) |
1585 local function M(e) |
1586 local t={} |
1586 local t={} |
1587 m("(for generator)") |
1587 y("(for generator)") |
1588 m("(for state)") |
1588 y("(for state)") |
1589 m("(for control)") |
1589 y("(for control)") |
1590 c(e) |
1590 m(e) |
1591 local e=1 |
1591 local e=1 |
1592 while i(",")do |
1592 while o(",")do |
1593 c(f()) |
1593 m(c()) |
1594 e=e+1 |
1594 e=e+1 |
1595 end |
1595 end |
1596 o("in") |
1596 i("in") |
1597 local a=d |
1597 local a=r |
1598 w(t) |
1598 f(t) |
1599 x(e,false) |
1599 k(e,false) |
1600 end |
1600 end |
1601 local function L(e) |
1601 local function F(e) |
1602 local a=false |
1602 local a=false |
1603 P(e) |
1603 Q(e) |
1604 while t=="."do |
1604 while t=="."do |
1605 H(e) |
1605 U(e) |
1606 end |
1606 end |
1607 if t==":"then |
1607 if t==":"then |
1608 a=true |
1608 a=true |
1609 H(e) |
1609 U(e) |
1610 end |
1610 end |
1611 return a |
1611 return a |
1612 end |
1612 end |
1613 function _() |
1613 function _() |
1614 local e={} |
1614 local e={} |
1615 u(e) |
1615 n(e) |
1616 end |
1616 end |
1617 local function x() |
1617 local function k() |
1618 local e={} |
1618 local e={} |
1619 u(e) |
1619 n(e) |
1620 end |
1620 end |
1621 local function _() |
1621 local function S() |
1622 e() |
1622 e() |
1623 x() |
1623 k() |
1624 o("then") |
1624 i("then") |
1625 y() |
1625 w() |
1626 end |
1626 end |
1627 local function C() |
1627 local function P() |
1628 local t,e={} |
1628 local t,e={} |
1629 c(f()) |
1629 m(c()) |
1630 t.k="VLOCAL" |
1630 t.k="VLOCAL" |
1631 k(1) |
1631 z(1) |
1632 z(e,false,s) |
1632 x(e,false,l) |
1633 end |
1633 end |
1634 local function H() |
1634 local function U() |
1635 local e=0 |
1635 local e=0 |
1636 local t={} |
1636 local t={} |
1637 repeat |
1637 repeat |
1638 c(f()) |
1638 m(c()) |
1639 e=e+1 |
1639 e=e+1 |
1640 until not i(",") |
1640 until not o(",") |
1641 if i("=")then |
1641 if o("=")then |
1642 w(t) |
1642 f(t) |
1643 else |
1643 else |
1644 t.k="VVOID" |
1644 t.k="VVOID" |
1645 end |
1645 end |
1646 k(e) |
1646 z(e) |
1647 end |
1647 end |
1648 function w(e) |
1648 function f(e) |
1649 u(e) |
1649 n(e) |
1650 while i(",")do |
1650 while o(",")do |
1651 u(e) |
1651 n(e) |
1652 end |
1652 end |
1653 end |
1653 end |
1654 function z(a,t,e) |
1654 function x(a,t,e) |
1655 Y() |
1655 B() |
1656 o("(") |
1656 i("(") |
1657 if t then |
1657 if t then |
1658 m("self",true) |
1658 y("self",true) |
1659 k(1) |
1659 z(1) |
1660 end |
1660 end |
1661 J() |
1661 X() |
1662 o(")") |
1662 i(")") |
1663 g() |
1663 v() |
1664 n("end","function",e) |
1664 h("end","function",e) |
1665 F() |
1665 G() |
1666 end |
1666 end |
1667 function y() |
1667 function w() |
1668 p(false) |
1668 p(false) |
1669 g() |
|
1670 v() |
1669 v() |
|
1670 b() |
1671 end |
1671 end |
1672 function for_stat() |
1672 function for_stat() |
1673 local o=d |
1673 local o=r |
1674 p(true) |
1674 p(true) |
1675 e() |
1675 e() |
1676 local a=f() |
1676 local a=c() |
1677 local e=t |
1677 local e=t |
1678 if e=="="then |
1678 if e=="="then |
1679 U(a) |
1679 R(a) |
1680 elseif e==","or e=="in"then |
1680 elseif e==","or e=="in"then |
1681 M(a) |
1681 M(a) |
1682 else |
1682 else |
1683 h("'=' or 'in' expected") |
1683 s("'=' or 'in' expected") |
1684 end |
1684 end |
1685 n("end","for",o) |
1685 h("end","for",o) |
1686 v() |
1686 b() |
1687 end |
1687 end |
1688 function while_stat() |
1688 function while_stat() |
1689 local t=d |
1689 local t=r |
1690 e() |
1690 e() |
1691 x() |
1691 k() |
1692 p(true) |
1692 p(true) |
1693 o("do") |
1693 i("do") |
1694 y() |
1694 w() |
1695 n("end","while",t) |
1695 h("end","while",t) |
1696 v() |
1696 b() |
1697 end |
1697 end |
1698 function repeat_stat() |
1698 function repeat_stat() |
1699 local t=d |
1699 local t=r |
1700 p(true) |
1700 p(true) |
1701 p(false) |
1701 p(false) |
1702 e() |
1702 e() |
1703 g() |
|
1704 n("until","repeat",t) |
|
1705 x() |
|
1706 v() |
1703 v() |
1707 v() |
1704 h("until","repeat",t) |
|
1705 k() |
|
1706 b() |
|
1707 b() |
1708 end |
1708 end |
1709 function if_stat() |
1709 function if_stat() |
1710 local a=d |
1710 local a=r |
1711 local o={} |
1711 local o={} |
1712 _() |
1712 S() |
1713 while t=="elseif"do |
1713 while t=="elseif"do |
1714 _() |
1714 S() |
1715 end |
1715 end |
1716 if t=="else"then |
1716 if t=="else"then |
1717 e() |
1717 e() |
1718 y() |
1718 w() |
1719 end |
1719 end |
1720 n("end","if",a) |
1720 h("end","if",a) |
1721 end |
1721 end |
1722 function return_stat() |
1722 function return_stat() |
1723 local a={} |
1723 local a={} |
1724 e() |
1724 e() |
1725 local e=t |
1725 local e=t |
1726 if O[e]or e==";"then |
1726 if H[e]or e==";"then |
1727 else |
1727 else |
1728 w(a) |
1728 f(a) |
1729 end |
1729 end |
1730 end |
1730 end |
1731 function break_stat() |
1731 function break_stat() |
1732 local t=a.bl |
1732 local t=a.bl |
1733 e() |
1733 e() |
1734 while t and not t.isbreakable do |
1734 while t and not t.isbreakable do |
1735 t=t.prev |
1735 t=t.prev |
1736 end |
1736 end |
1737 if not t then |
1737 if not t then |
1738 h("no loop to break") |
1738 s("no loop to break") |
1739 end |
1739 end |
1740 end |
1740 end |
1741 function expr_stat() |
1741 function expr_stat() |
1742 local e={} |
1742 local e={} |
1743 e.v={} |
1743 e.v={} |
1744 R(e.v) |
1744 O(e.v) |
1745 if e.v.k=="VCALL"then |
1745 if e.v.k=="VCALL"then |
1746 else |
1746 else |
1747 e.prev=nil |
1747 e.prev=nil |
1748 I(e) |
1748 I(e) |
1749 end |
1749 end |
1750 end |
1750 end |
1751 function function_stat() |
1751 function function_stat() |
1752 local t=d |
1752 local a=r |
1753 local o,a={},{} |
1753 local o,t={},{} |
1754 e() |
1754 e() |
1755 local e=L(o) |
1755 local e=F(o) |
1756 z(a,e,t) |
1756 x(t,e,a) |
1757 end |
1757 end |
1758 function do_stat() |
1758 function do_stat() |
1759 local t=d |
1759 local t=r |
1760 e() |
1760 e() |
1761 y() |
1761 w() |
1762 n("end","do",t) |
1762 h("end","do",t) |
1763 end |
1763 end |
1764 function local_stat() |
1764 function local_stat() |
1765 e() |
1765 e() |
1766 if i("function")then |
1766 if o("function")then |
1767 C() |
1767 P() |
1768 else |
1768 else |
1769 H() |
1769 U() |
1770 end |
1770 end |
1771 end |
1771 end |
1772 local function o() |
1772 local function i() |
1773 d=s |
1773 r=l |
1774 local e=t |
1774 local e=t |
1775 local t=G[e] |
1775 local t=Y[e] |
1776 if t then |
1776 if t then |
1777 _M[t]() |
1777 D[t]() |
1778 if e=="return"or e=="break"then return true end |
1778 if e=="return"or e=="break"then return true end |
1779 else |
1779 else |
1780 expr_stat() |
1780 expr_stat() |
1781 end |
1781 end |
1782 return false |
1782 return false |
1783 end |
1783 end |
1784 function g() |
1784 function v() |
1785 local e=false |
1785 local e=false |
1786 while not e and not O[t]do |
1786 while not e and not H[t]do |
1787 e=o() |
1787 e=i() |
1788 i(";") |
1788 o(";") |
1789 end |
1789 end |
1790 end |
1790 end |
1791 function parser() |
1791 function parser() |
1792 Y() |
1792 B() |
1793 a.is_vararg=true |
1793 a.is_vararg=true |
1794 e() |
1794 e() |
1795 g() |
1795 v() |
1796 D("<eof>") |
1796 L("<eof>") |
1797 F() |
1797 G() |
1798 return q,l |
1798 return q,u |
1799 end |
1799 end |
1800 function init(e,o,n) |
1800 function init(e,o,n) |
1801 r=1 |
1801 d=1 |
1802 K={} |
1802 W={} |
1803 local t=1 |
1803 local t=1 |
1804 E,j,T,S={},{},{},{} |
1804 T,j,A,C={},{},{},{} |
1805 for a=1,#e do |
1805 for a=1,#e do |
1806 local e=e[a] |
1806 local e=e[a] |
1807 local i=true |
1807 local i=true |
1808 if e=="TK_KEYWORD"or e=="TK_OP"then |
1808 if e=="TK_KEYWORD"or e=="TK_OP"then |
1809 e=o[a] |
1809 e=o[a] |
1843 end |
1863 end |
1844 _ENV=e; |
1864 _ENV=e; |
1845 _M=e; |
1865 _M=e; |
1846 return e; |
1866 return e; |
1847 end |
1867 end |
1848 local c,t,u=string,table,math |
1868 local m,t,u=string,table,math |
1849 local a,w,n,e=ipairs,setmetatable,type,assert |
1869 local a,v,n,e=ipairs,setmetatable,type,assert |
1850 local a=__END_OF_GLOBALS__ |
1870 local a=__END_OF_GLOBALS__ |
1851 local l,i,f=c.char,c.byte,c.sub |
1871 local c,l,i=m.char,m.byte,m.sub |
1852 local E,d,_=u.frexp,u.ldexp,u.abs |
1872 local w,d,g=u.frexp,u.ldexp,u.abs |
1853 local y=t.concat |
1873 local p=t.concat |
1854 local a=u.huge |
1874 local a=u.huge |
1855 local x=a-a |
1875 local k=a-a |
1856 local o=false |
1876 local o=false |
1857 local h=4 |
1877 local r=4 |
1858 local s=4 |
1878 local s=4 |
1859 local r=8 |
1879 local h=8 |
1860 local t={} |
1880 local t={} |
1861 local function v() |
1881 local function y() |
1862 t[#t+1] |
1882 t[#t+1] |
1863 ={o,h,s,r} |
1883 ={o,r,s,h} |
1864 end |
1884 end |
1865 local function p() |
1885 local function b() |
1866 o,h,s,r |
1886 o,r,s,h |
1867 =unpack(t[#t]) |
1887 =unpack(t[#t]) |
1868 t[#t]=nil |
1888 t[#t]=nil |
1869 end |
1889 end |
1870 local function t(e,t) |
1890 local function t(e,t) |
1871 return e.new(e,t) |
1891 return e.new(e,t) |
1872 end |
1892 end |
1873 local m={} |
1893 local f={} |
1874 local t=t{ |
1894 local t=t{ |
1875 new= |
1895 new= |
1876 function(e,a) |
1896 function(e,a) |
1877 local a=a or{} |
1897 local a=a or{} |
1878 local t=m[e]or{ |
1898 local t=f[e]or{ |
1879 __index=e, |
1899 __index=e, |
1880 __call=t |
1900 __call=t |
1881 } |
1901 } |
1882 m[e]=t |
1902 f[e]=t |
1883 return w(a,t) |
1903 return v(a,t) |
1884 end, |
1904 end, |
1885 } |
1905 } |
1886 local q=t{ |
1906 local j=t{ |
1887 unpack=function(t,t,e)return nil,e end, |
1907 unpack=function(t,t,e)return nil,e end, |
1888 pack=function(e,e)return""end |
1908 pack=function(e,e)return""end |
1889 } |
1909 } |
1890 local m={} |
1910 local f={} |
1891 local function b(e) |
1911 local function v(e) |
1892 local t=m[e]or t{ |
1912 local t=f[e]or t{ |
1893 unpack=function(o,a,t) |
1913 unpack=function(o,a,t) |
1894 return f(a,t,t+e-1),t+e |
1914 return i(a,t,t+e-1),t+e |
1895 end, |
1915 end, |
1896 pack=function(a,t)return f(t,1,e)end |
1916 pack=function(a,t)return i(t,1,e)end |
1897 } |
1917 } |
1898 m[e]=t |
1918 f[e]=t |
1899 return t |
1919 return t |
1900 end |
1920 end |
1901 local w=t{ |
1921 local q=t{ |
1902 unpack=function(a,t,e) |
1922 unpack=function(a,t,e) |
1903 return i(t,e,e),e+1 |
1923 return l(t,e,e),e+1 |
1904 end, |
1924 end, |
1905 pack=function(t,e)return l(e)end |
1925 pack=function(t,e)return c(e)end |
1906 } |
1926 } |
1907 local i=t{ |
1927 local i=t{ |
1908 unpack= |
1928 unpack= |
1909 function(t,e,a) |
1929 function(t,e,n) |
1910 local e,t,n,i=i(e,a,a+3) |
1930 local i,e,t,a=l(e,n,n+3) |
1911 if o then e,t,n,i=i,n,t,e end |
1931 if o then i,e,t,a=a,t,e,i end |
1912 return e+t*256+n*256^2+i*256^3,a+4 |
1932 return i+e*256+t*256^2+a*256^3,n+4 |
1913 end, |
1933 end, |
1914 pack= |
1934 pack= |
1915 function(t,s) |
1935 function(t,s) |
1916 e(n(s)=="number", |
1936 e(n(s)=="number", |
1917 "unexpected value type to pack as an uint32") |
1937 "unexpected value type to pack as an uint32") |
1918 local t,a,i,e |
1938 local i,a,t,e |
1919 e=s%2^32 |
1939 e=s%2^32 |
|
1940 i=e%256;e=(e-i)/256 |
|
1941 a=e%256;e=(e-a)/256 |
1920 t=e%256;e=(e-t)/256 |
1942 t=e%256;e=(e-t)/256 |
1921 a=e%256;e=(e-a)/256 |
1943 if o then i,a,t,e=e,t,a,i end |
1922 i=e%256;e=(e-i)/256 |
1944 return c(i,a,t,e) |
1923 if o then t,a,i,e=e,i,a,t end |
|
1924 return l(t,a,i,e) |
|
1925 end |
1945 end |
1926 } |
1946 } |
1927 local j=t{ |
1947 local x=t{ |
1928 unpack= |
1948 unpack= |
1929 function(a,e,t) |
1949 function(a,e,t) |
1930 local a=i:unpack(e,t) |
1950 local a=i:unpack(e,t) |
1931 local e=i:unpack(e,t+4) |
1951 local e=i:unpack(e,t+4) |
1932 if o then a,e=e,a end |
1952 if o then a,e=e,a end |
1940 local t=(t-e)/2^32 |
1960 local t=(t-e)/2^32 |
1941 if o then e,t=t,e end |
1961 if o then e,t=t,e end |
1942 return i:pack(e)..i:pack(t) |
1962 return i:pack(e)..i:pack(t) |
1943 end |
1963 end |
1944 } |
1964 } |
1945 local function z(a,e) |
1965 local function E(e,a) |
1946 local t=i:unpack(a,e) |
1966 local t=i:unpack(e,a) |
1947 local e=i:unpack(a,e+4) |
1967 local e=i:unpack(e,a+4) |
1948 if o then t,e=e,t end |
1968 if o then t,e=e,t end |
1949 local a=e%2^20 |
1969 local a=e%2^20 |
1950 local t=t |
1970 local t=t |
1951 local o=t+a*2^32 |
1971 local o=t+a*2^32 |
1952 e=(e-a)/2^20 |
1972 e=(e-a)/2^20 |
1953 local t=e%2^11 |
1973 local t=e%2^11 |
1954 local e=e<=t and 1 or-1 |
1974 local e=e<=t and 1 or-1 |
1955 return e,t,o |
1975 return e,t,o |
1956 end |
1976 end |
1957 local function l(a,n,t) |
1977 local function c(n,a,t) |
1958 local e=t%2^32 |
1978 local e=t%2^32 |
1959 local s=(t-e)/2^32 |
1979 local t=(t-e)/2^32 |
1960 local t=e |
1980 local e=e |
1961 local e=((a<0 and 2^11 or 0)+n)*2^20+s |
1981 local t=((n<0 and 2^11 or 0)+a)*2^20+t |
1962 if o then t,e=e,t end |
1982 if o then e,t=t,e end |
1963 return i.pack(nil,t)..i.pack(nil,e) |
1983 return i.pack(nil,e)..i.pack(nil,t) |
1964 end |
1984 end |
1965 local function k(e) |
1985 local function _(e) |
1966 if e~=e then return e end |
1986 if e~=e then return e end |
1967 if e==0 then e=1/e end |
1987 if e==0 then e=1/e end |
1968 return e>0 and 1 or-1 |
1988 return e>0 and 1 or-1 |
1969 end |
1989 end |
1970 local m=d(1,-1022-52) |
1990 local l=d(1,-1022-52) |
1971 local f=m*2^52 |
1991 local f=l*2^52 |
1972 local g=d(2^52-1,-1022-52) |
1992 local z=d(2^52-1,-1022-52) |
1973 local f=d(2^53-1,1023-52) |
1993 local f=d(2^53-1,1023-52) |
1974 e(m~=0 and m/2==0) |
1994 e(l~=0 and l/2==0) |
1975 e(f~=a) |
1995 e(f~=a) |
1976 e(f*2==a) |
1996 e(f*2==a) |
1977 local l=t{ |
1997 local d=t{ |
1978 unpack= |
1998 unpack= |
1979 function(t,e,i) |
1999 function(t,e,i) |
1980 local n,o,t=z(e,i) |
2000 local n,o,t=E(e,i) |
1981 local e |
2001 local e |
1982 if o==0 then |
2002 if o==0 then |
1983 e=d(t,-1022-52) |
2003 e=d(t,-1022-52) |
1984 elseif o==2047 then |
2004 elseif o==2047 then |
1985 e=t==0 and a or x |
2005 e=t==0 and a or k |
1986 else |
2006 else |
1987 e=d(2^52+t,o-1023-52) |
2007 e=d(2^52+t,o-1023-52) |
1988 end |
2008 end |
1989 e=n*e |
2009 e=n*e |
1990 return e,i+8 |
2010 return e,i+8 |
1991 end, |
2011 end, |
1992 pack= |
2012 pack= |
1993 function(t,e) |
2013 function(t,e) |
1994 if e~=e then |
2014 if e~=e then |
1995 return l(1,2047,2^52-1) |
2015 return c(1,2047,2^52-1) |
1996 end |
2016 end |
1997 local o=k(e) |
2017 local o=_(e) |
1998 e=_(e) |
2018 e=g(e) |
1999 if e==a then return l(o,2047,0)end |
2019 if e==a then return c(o,2047,0)end |
2000 if e==0 then return l(o,0,0)end |
2020 if e==0 then return c(o,0,0)end |
2001 local a,t |
2021 local t,a |
2002 if e<=g then |
2022 if e<=z then |
2003 a=0 |
2023 t=0 |
2004 t=e/m |
2024 a=e/l |
2005 else |
2025 else |
2006 local e,o=E(e) |
2026 local o,e=w(e) |
2007 t=(2*e-1)*2^52 |
2027 a=(2*o-1)*2^52 |
2008 a=o+1022 |
2028 t=e+1022 |
2009 end |
2029 end |
2010 return l(o,a,t) |
2030 return c(o,t,a) |
2011 end |
2031 end |
2012 } |
2032 } |
2013 local a=w |
2033 local a=q |
2014 local d={ |
2034 local l={ |
2015 [4]=i, |
2035 [4]=i, |
2016 [8]=j |
2036 [8]=x |
2017 } |
2037 } |
2018 local w={ |
2038 local w={ |
2019 [4]=float, |
2039 [4]=float, |
2020 [8]=l |
2040 [8]=d |
2021 } |
2041 } |
2022 local m=t{ |
2042 local c=t{ |
2023 unpack=function(a,t,e) |
2043 unpack=function(a,t,e) |
2024 return d[h]:unpack(t,e) |
2044 return l[r]:unpack(t,e) |
2025 end, |
2045 end, |
2026 pack=function(t,e) |
2046 pack=function(t,e) |
2027 return d[h]:pack(e) |
2047 return l[r]:pack(e) |
2028 end, |
2048 end, |
2029 } |
2049 } |
2030 local i=t{ |
2050 local i=t{ |
2031 unpack=function(a,t,e) |
2051 unpack=function(a,e,t) |
2032 return d[s]:unpack(t,e) |
2052 return l[s]:unpack(e,t) |
2033 end, |
2053 end, |
2034 pack=function(t,e) |
2054 pack=function(t,e) |
2035 return d[s]:pack(e) |
2055 return l[s]:pack(e) |
2036 end, |
2056 end, |
2037 } |
2057 } |
2038 local j=t{ |
2058 local g=t{ |
2039 unpack=function(a,t,e) |
2059 unpack=function(a,t,e) |
2040 return w[r]:unpack(t,e) |
2060 return w[h]:unpack(t,e) |
2041 end, |
2061 end, |
2042 pack=function(t,e) |
2062 pack=function(t,e) |
2043 return w[r]:pack(e) |
2063 return w[h]:pack(e) |
2044 end, |
2064 end, |
2045 } |
2065 } |
2046 local g=b(4) |
2066 local k=v(4) |
2047 local f=t{ |
2067 local f=t{ |
2048 unpack= |
2068 unpack= |
2049 function(o,s,t) |
2069 function(t,s,o) |
2050 local i={} |
|
2051 local e,a=1,1 |
|
2052 while o[e]do |
|
2053 local n=o[e] |
|
2054 local o=n.name |
|
2055 if not o then o,a=a,a+1 end |
|
2056 i[o],t=n:unpack(s,t) |
|
2057 e=e+1 |
|
2058 end |
|
2059 return i,t |
|
2060 end, |
|
2061 pack= |
|
2062 function(t,n) |
|
2063 local i={} |
2070 local i={} |
2064 local e,a=1,1 |
2071 local e,a=1,1 |
2065 while t[e]do |
2072 while t[e]do |
2066 local o=t[e] |
2073 local n=t[e] |
2067 local t=o.name |
2074 local t=n.name |
2068 if not t then t,a=a,a+1 end |
2075 if not t then t,a=a,a+1 end |
2069 i[e]=o:pack(n[t]) |
2076 i[t],o=n:unpack(s,o) |
2070 e=e+1 |
2077 e=e+1 |
2071 end |
2078 end |
2072 return y(i) |
2079 return i,o |
|
2080 end, |
|
2081 pack= |
|
2082 function(a,n) |
|
2083 local i={} |
|
2084 local e,t=1,1 |
|
2085 while a[e]do |
|
2086 local o=a[e] |
|
2087 local a=o.name |
|
2088 if not a then a,t=t,t+1 end |
|
2089 i[e]=o:pack(n[a]) |
|
2090 e=e+1 |
|
2091 end |
|
2092 return p(i) |
2073 end |
2093 end |
2074 } |
2094 } |
2075 local l=t{ |
2095 local d=t{ |
2076 unpack= |
2096 unpack= |
2077 function(n,a,e) |
2097 function(n,t,e) |
2078 local o,e=i:unpack(a,e) |
2098 local o,e=i:unpack(t,e) |
2079 local t={} |
2099 local a={} |
2080 local i=n.type |
2100 local i=n.type |
2081 for o=1,o do |
2101 for o=1,o do |
2082 t[o],e=i:unpack(a,e) |
2102 a[o],e=i:unpack(t,e) |
2083 end |
2103 end |
2084 return t,e |
2104 return a,e |
2085 end, |
2105 end, |
2086 pack= |
2106 pack= |
2087 function(o,a) |
2107 function(o,a) |
2088 local t=#a |
2108 local t=#a |
2089 local e={i:pack(t)} |
2109 local e={i:pack(t)} |
2090 local o=o.type |
2110 local o=o.type |
2091 for t=1,t do |
2111 for t=1,t do |
2092 e[#e+1]=o:pack(a[t]) |
2112 e[#e+1]=o:pack(a[t]) |
2093 end |
2113 end |
2094 return y(e) |
2114 return p(e) |
2095 end |
2115 end |
2096 } |
2116 } |
2097 local k=t{ |
2117 local q=t{ |
2098 unpack= |
2118 unpack= |
2099 function(o,a,t) |
2119 function(o,a,t) |
2100 local t,a=i:unpack(a,t) |
2120 local t,a=i:unpack(a,t) |
2101 e(t==0 or t==1, |
2121 e(t==0 or t==1, |
2102 "unpacked an unexpected value "..t.." for a Boolean") |
2122 "unpacked an unexpected value "..t.." for a Boolean") |
2107 e(n(t)=="boolean", |
2127 e(n(t)=="boolean", |
2108 "unexpected value type to pack as a Boolean") |
2128 "unexpected value type to pack as a Boolean") |
2109 return i:pack(t and 1 or 0) |
2129 return i:pack(t and 1 or 0) |
2110 end |
2130 end |
2111 } |
2131 } |
2112 local m=t{ |
2132 local c=t{ |
2113 unpack= |
2133 unpack= |
2114 function(t,o,e) |
2134 function(t,a,e) |
2115 local t,e=m:unpack(o,e) |
2135 local t,e=c:unpack(a,e) |
2116 local a=nil |
2136 local o=nil |
2117 if t>0 then |
2137 if t>0 then |
2118 local t=t-1 |
2138 local t=t-1 |
2119 a=o:sub(e,e+t-1) |
2139 o=a:sub(e,e+t-1) |
2120 end |
2140 end |
2121 return a,e+t |
2141 return o,e+t |
2122 end, |
2142 end, |
2123 pack= |
2143 pack= |
2124 function(a,t) |
2144 function(a,t) |
2125 e(n(t)=="nil"or n(t)=="string", |
2145 e(n(t)=="nil"or n(t)=="string", |
2126 "unexpected value type to pack as a String") |
2146 "unexpected value type to pack as a String") |
2127 if t==nil then |
2147 if t==nil then |
2128 return m:pack(0) |
2148 return c:pack(0) |
2129 end |
2149 end |
2130 return m:pack(#t+1)..t.."\000" |
2150 return c:pack(#t+1)..t.."\000" |
2131 end |
2151 end |
2132 } |
2152 } |
2133 local y=f{ |
2153 local p=f{ |
2134 b(4){name="signature"}, |
2154 v(4){name="signature"}, |
2135 a{name="version"}, |
2155 a{name="version"}, |
2136 a{name="format"}, |
2156 a{name="format"}, |
2137 a{name="endianness"}, |
2157 a{name="endianness"}, |
2138 a{name="sizeof_int"}, |
2158 a{name="sizeof_int"}, |
2139 a{name="sizeof_size_t"}, |
2159 a{name="sizeof_size_t"}, |
2140 a{name="sizeof_insn"}, |
2160 a{name="sizeof_insn"}, |
2141 a{name="sizeof_Number"}, |
2161 a{name="sizeof_Number"}, |
2142 a{name="integral_flag"}, |
2162 a{name="integral_flag"}, |
2143 } |
2163 } |
2144 local b={ |
2164 local v={ |
2145 [0]=q, |
2165 [0]=j, |
2146 [1]=k, |
2166 [1]=q, |
2147 [3]=j, |
2167 [3]=g, |
2148 [4]=m, |
2168 [4]=c, |
2149 } |
2169 } |
2150 local b=t{ |
2170 local g=t{ |
2151 unpack= |
2171 unpack= |
2152 function(i,o,t) |
2172 function(i,o,t) |
2153 local t,i=a:unpack(o,t) |
2173 local t,i=a:unpack(o,t) |
2154 local a=b[t] |
2174 local a=v[t] |
2155 e(a,"unknown constant type "..t.." to unpack") |
2175 e(a,"unknown constant type "..t.." to unpack") |
2156 local a,o=a:unpack(o,i) |
2176 local a,o=a:unpack(o,i) |
2157 if t==3 then |
2177 if t==3 then |
2158 e(n(a)=="number") |
2178 e(n(a)=="number") |
2159 end |
2179 end |
2163 },o |
2183 },o |
2164 end, |
2184 end, |
2165 pack= |
2185 pack= |
2166 function(t,e) |
2186 function(t,e) |
2167 local e,t=e.type,e.value |
2187 local e,t=e.type,e.value |
2168 return a:pack(e)..b[e]:pack(t) |
2188 return a:pack(e)..v[e]:pack(t) |
2169 end |
2189 end |
2170 } |
2190 } |
2171 local k=f{ |
2191 local v=f{ |
2172 m{name="name"}, |
2192 c{name="name"}, |
2173 i{name="startpc"}, |
2193 i{name="startpc"}, |
2174 i{name="endpc"} |
2194 i{name="endpc"} |
2175 } |
2195 } |
2176 local a=f{ |
2196 local a=f{ |
2177 m{name="name"}, |
2197 c{name="name"}, |
2178 i{name="line"}, |
2198 i{name="line"}, |
2179 i{name="last_line"}, |
2199 i{name="last_line"}, |
2180 a{name="num_upvalues"}, |
2200 a{name="num_upvalues"}, |
2181 a{name="num_parameters"}, |
2201 a{name="num_parameters"}, |
2182 a{name="is_vararg"}, |
2202 a{name="is_vararg"}, |
2183 a{name="max_stack_size"}, |
2203 a{name="max_stack_size"}, |
2184 l{name="insns",type=g}, |
2204 d{name="insns",type=k}, |
2185 l{name="constants",type=b}, |
2205 d{name="constants",type=g}, |
2186 l{name="prototypes",type=nil}, |
2206 d{name="prototypes",type=nil}, |
2187 l{name="source_lines",type=i}, |
2207 d{name="source_lines",type=i}, |
2188 l{name="locals",type=k}, |
2208 d{name="locals",type=v}, |
2189 l{name="upvalues",type=m}, |
2209 d{name="upvalues",type=c}, |
2190 } |
2210 } |
2191 e(a[10].name=="prototypes", |
2211 e(a[10].name=="prototypes", |
2192 "missed the function prototype list") |
2212 "missed the function prototype list") |
2193 a[10].type=a |
2213 a[10].type=a |
2194 local a=t{ |
2214 local a=t{ |
2195 unpack= |
2215 unpack= |
2196 function(i,l,t) |
2216 function(i,d,t) |
2197 local i={} |
2217 local n={} |
2198 local t,n=y:unpack(l,t) |
2218 local t,i=p:unpack(d,t) |
2199 e(t.signature=="\027Lua","signature check failed") |
2219 e(t.signature=="\027Lua","signature check failed") |
2200 e(t.version==81,"version mismatch") |
2220 e(t.version==81,"version mismatch") |
2201 e(t.format==0,"format mismatch") |
2221 e(t.format==0,"format mismatch") |
2202 e(t.endianness==0 or |
2222 e(t.endianness==0 or |
2203 t.endianness==1,"endianness mismatch") |
2223 t.endianness==1,"endianness mismatch") |
2204 e(d[t.sizeof_int],"int size unsupported") |
2224 e(l[t.sizeof_int],"int size unsupported") |
2205 e(d[t.sizeof_size_t],"size_t size unsupported") |
2225 e(l[t.sizeof_size_t],"size_t size unsupported") |
2206 e(t.sizeof_insn==4,"insn size unsupported") |
2226 e(t.sizeof_insn==4,"insn size unsupported") |
2207 e(w[t.sizeof_Number],"number size unsupported") |
2227 e(w[t.sizeof_Number],"number size unsupported") |
2208 e(t.integral_flag==0,"integral flag mismatch; only floats supported") |
2228 e(t.integral_flag==0,"integral flag mismatch; only floats supported") |
2209 v() |
2229 y() |
2210 o=t.endianness==0 |
2230 o=t.endianness==0 |
2211 h=t.sizeof_size_t |
2231 r=t.sizeof_size_t |
2212 s=t.sizeof_int |
2232 s=t.sizeof_int |
2213 r=t.sizeof_Number |
2233 h=t.sizeof_Number |
2214 i.header=t |
2234 n.header=t |
2215 i.body,n=a:unpack(l,n) |
2235 n.body,i=a:unpack(d,i) |
2216 p() |
2236 b() |
2217 return i,n |
2237 return n,i |
2218 end, |
2238 end, |
2219 pack= |
2239 pack= |
2220 function(e,t) |
2240 function(e,t) |
2221 local i |
2241 local i |
2222 v() |
2242 y() |
2223 local e=t.header |
2243 local e=t.header |
2224 o=e.endianness==0 |
2244 o=e.endianness==0 |
2225 h=e.sizeof_size_t |
2245 r=e.sizeof_size_t |
2226 s=e.sizeof_int |
2246 s=e.sizeof_int |
2227 r=e.sizeof_Number |
2247 h=e.sizeof_Number |
2228 i=y:pack(t.header)..a:pack(t.body) |
2248 i=p:pack(t.header)..a:pack(t.body) |
2229 p() |
2249 b() |
2230 return i |
2250 return i |
2231 end |
2251 end |
2232 } |
2252 } |
2233 local function o(e) |
2253 local function o(e) |
2234 if n(e)=="function"then |
2254 if n(e)=="function"then |
2235 return o(c.dump(e)) |
2255 return o(m.dump(e)) |
2236 end |
2256 end |
2237 local t=a:unpack(e,1) |
2257 local t=a:unpack(e,1) |
2238 local a=a:pack(t) |
2258 local a=a:pack(t) |
2239 if e==a then return true end |
2259 if e==a then return true end |
2240 local t |
2260 local t |
2317 function vio:close()\ |
2337 function vio:close()\ |
2318 \9self.pos, self.data = nil, nil;\ |
2338 \9self.pos, self.data = nil, nil;\ |
2319 end\ |
2339 end\ |
2320 \ |
2340 \ |
2321 "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)..\"]\", \ |
2341 "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)..\"]\", \ |
2322 \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\ |
2342 \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,\ |
|
2343 u,v,l,l=\ |
|
2344 assert,error,ipairs,pairs,tostring,type,setmetatable,io,math,table.sort,\ |
|
2345 math.max,string.char,io.open,_G;\ |
|
2346 Œ ‰ p(n)\ |
|
2347 Œ l={};\ |
|
2348 Œ e=e({},l)\ |
|
2349 ‰ l:__index(l)\ |
|
2350 Œ n=n(l);e[l]=n\ |
2323 ‘ n\ |
2351 ‘ n\ |
2324 †\ |
2352 †\ |
2325 ‘ e\ |
2353 ‘ e\ |
2326 †\ |
2354 †\ |
2327 Œ ‰ l(n,l)l=l 1\ |
2355 Œ ‰ l(n,l)\ |
2328 h({n},l+1)†\ |
2356 l=l 1\ |
2329 Œ ‰ _(n)Œ l={}l.outbs=n\ |
2357 h({n},l+1)\ |
2330 l.wnd={}l.™=1\ |
2358 †\ |
|
2359 Œ ‰ _(n)\ |
|
2360 Œ l={}\ |
|
2361 l.outbs=n\ |
|
2362 l.wnd={}\ |
|
2363 l.™=1\ |
2331 ‘ l\ |
2364 ‘ l\ |
2332 †\ |
2365 †\ |
2333 Œ ‰ t(l,e)Œ n=l.™\ |
2366 Œ ‰ t(l,e)\ |
2334 l.outbs(e)l.wnd[n]=e\ |
2367 Œ n=l.™\ |
|
2368 l.outbs(e)\ |
|
2369 l.wnd[n]=e\ |
2335 l.™=n%32768+1\ |
2370 l.™=n%32768+1\ |
2336 †\ |
2371 †\ |
2337 Œ ‰ n(l)‘ i(l,'unexpected end of file')†\ |
2372 Œ ‰ n(l)\ |
2338 Œ ‰ o(n,l)‘ n%(l+l)>=l\ |
2373 ‘ i(l,'unexpected end of file')\ |
2339 †\ |
2374 †\ |
2340 Œ a=p(‰(l)‘ 2^l †)Œ c=e({},{__mode='k'})Œ ‰ g(o)Œ l=1\ |
2375 Œ ‰ o(n,l)\ |
2341 Œ e={}‰ e:–()Œ n\ |
2376 ‘ n%(l+l)>=l\ |
|
2377 †\ |
|
2378 Œ a=p(‰(l)‘ 2^l †)\ |
|
2379 Œ c=e({},{__mode='k'})\ |
|
2380 Œ ‰ g(o)\ |
|
2381 Œ l=1\ |
|
2382 Œ e={}\ |
|
2383 ‰ e:–()\ |
|
2384 Œ n\ |
2342 Š l<=#o ’\ |
2385 Š l<=#o ’\ |
2343 n=o:byte(l)l=l+1\ |
2386 n=o:byte(l)\ |
|
2387 l=l+1\ |
2344 †\ |
2388 †\ |
2345 ‘ n\ |
2389 ‘ n\ |
2346 †\ |
2390 †\ |
2347 ‘ e\ |
2391 ‘ e\ |
2348 †\ |
2392 †\ |
2349 Œ l\ |
2393 Œ l\ |
2350 Œ ‰ s(d)Œ n,l,o=0,0,{};‰ o:˜()‘ l\ |
2394 Œ ‰ s(d)\ |
2351 †\ |
2395 Œ n,l,o=0,0,{};\ |
2352 ‰ o:–(e)e=e 1\ |
2396 ‰ o:˜()\ |
|
2397 ‘ l\ |
|
2398 †\ |
|
2399 ‰ o:–(e)\ |
|
2400 e=e 1\ |
2353 • l<e ƒ\ |
2401 • l<e ƒ\ |
2354 Œ e=d:–()Š Ž e ’ ‘ †\ |
2402 Œ e=d:–()\ |
|
2403 Š Ž e ’ ‘ †\ |
2355 n=n+a[l]*e\ |
2404 n=n+a[l]*e\ |
2356 l=l+8\ |
2405 l=l+8\ |
2357 †\ |
2406 †\ |
2358 Œ o=a[e]Œ a=n%o\ |
2407 Œ o=a[e]\ |
|
2408 Œ a=n%o\ |
2359 n=(n-a)/o\ |
2409 n=(n-a)/o\ |
2360 l=l-e\ |
2410 l=l-e\ |
2361 ‘ a\ |
2411 ‘ a\ |
2362 †\ |
2412 †\ |
2363 c[o]=“\ |
2413 c[o]=“\ |
2364 ‘ o\ |
2414 ‘ o\ |
2365 †\ |
2415 †\ |
2366 Œ ‰ f(l)‘ c[l] l s(g(l))†\ |
2416 Œ ‰ f(l)\ |
2367 Œ ‰ s(l)Œ n\ |
2417 ‘ c[l] l s(g(l))\ |
|
2418 †\ |
|
2419 Œ ‰ s(l)\ |
|
2420 Œ n\ |
2368 Š y.type(l)=='file'’\ |
2421 Š y.type(l)=='file'’\ |
2369 n=‰(n)l:write(v(n))†\ |
2422 n=‰(n)l:write(v(n))†\ |
2370 … d(l)=='function'’\ |
2423 … d(l)=='function'’\ |
2371 n=l\ |
2424 n=l\ |
2372 †\ |
2425 †\ |
2373 ‘ n\ |
2426 ‘ n\ |
2374 †\ |
2427 †\ |
2375 Œ ‰ d(e,o)Œ l={}Š o ’\ |
2428 Œ ‰ d(e,o)\ |
|
2429 Œ l={}\ |
|
2430 Š o ’\ |
2376 ˆ e,n ‹ m(e)ƒ\ |
2431 ˆ e,n ‹ m(e)ƒ\ |
2377 Š n~=0 ’\ |
2432 Š n~=0 ’\ |
2378 l[#l+1]={›=e,—=n}†\ |
2433 l[#l+1]={›=e,—=n}\ |
|
2434 †\ |
2379 †\ |
2435 †\ |
2380 „\ |
2436 „\ |
2381 ˆ n=1,#e-2,2 ƒ\ |
2437 ˆ n=1,#e-2,2 ƒ\ |
2382 Œ o,n,e=e[n],e[n+1],e[n+2]Š n~=0 ’\ |
2438 Œ o,n,e=e[n],e[n+1],e[n+2]\ |
|
2439 Š n~=0 ’\ |
2383 ˆ e=o,e-1 ƒ\ |
2440 ˆ e=o,e-1 ƒ\ |
2384 l[#l+1]={›=e,—=n}†\ |
2441 l[#l+1]={›=e,—=n}\ |
2385 †\ |
2442 †\ |
2386 †\ |
2443 †\ |
2387 †\ |
2444 †\ |
2388 w(l,‰(n,l)‘ n.—==l.— n.›<l.› n.—<l.—\ |
2445 †\ |
2389 †)Œ e=1\ |
2446 w(l,‰(n,l)\ |
|
2447 ‘ n.—==l.— n.›<l.› n.—<l.—\ |
|
2448 †)\ |
|
2449 Œ e=1\ |
2390 Œ o=0\ |
2450 Œ o=0\ |
2391 ˆ n,l ‹ b(l)ƒ\ |
2451 ˆ n,l ‹ b(l)ƒ\ |
2392 Š l.—~=o ’\ |
2452 Š l.—~=o ’\ |
2393 e=e*a[l.—-o]o=l.—\ |
2453 e=e*a[l.—-o]\ |
|
2454 o=l.—\ |
2394 †\ |
2455 †\ |
2395 l.code=e\ |
2456 l.code=e\ |
2396 e=e+1\ |
2457 e=e+1\ |
2397 †\ |
2458 †\ |
2398 Œ e=r.huge\ |
2459 Œ e=r.huge\ |
2399 Œ c={}ˆ n,l ‹ b(l)ƒ\ |
2460 Œ c={}\ |
2400 e=r.min(e,l.—)c[l.code]=l.›\ |
2461 ˆ n,l ‹ b(l)ƒ\ |
2401 †\ |
2462 e=r.min(e,l.—)\ |
2402 Œ ‰ o(n,e)Œ l=0\ |
2463 c[l.code]=l.›\ |
|
2464 †\ |
|
2465 Œ ‰ o(n,e)\ |
|
2466 Œ l=0\ |
2403 ˆ e=1,e ƒ\ |
2467 ˆ e=1,e ƒ\ |
2404 Œ e=n%2\ |
2468 Œ e=n%2\ |
2405 n=(n-e)/2\ |
2469 n=(n-e)/2\ |
2406 l=l*2+e\ |
2470 l=l*2+e\ |
2407 †\ |
2471 †\ |
2408 ‘ l\ |
2472 ‘ l\ |
2409 †\ |
2473 †\ |
2410 Œ d=p(‰(l)‘ a[e]+o(l,e)†)‰ l:–(a)Œ o,l=1,0\ |
2474 Œ d=p(\ |
|
2475 ‰(l)‘ a[e]+o(l,e)†)\ |
|
2476 ‰ l:–(a)\ |
|
2477 Œ o,l=1,0\ |
2411 • 1 ƒ\ |
2478 • 1 ƒ\ |
2412 Š l==0 ’\ |
2479 Š l==0 ’\ |
2413 o=d[n(a:–(e))]l=l+e\ |
2480 o=d[n(a:–(e))]\ |
|
2481 l=l+e\ |
2414 „\ |
2482 „\ |
2415 Œ n=n(a:–())l=l+1\ |
2483 Œ n=n(a:–())\ |
|
2484 l=l+1\ |
2416 o=o*2+n\ |
2485 o=o*2+n\ |
2417 †\ |
2486 †\ |
2418 Œ l=c[o]Š l ’\ |
2487 Œ l=c[o]\ |
|
2488 Š l ’\ |
2419 ‘ l\ |
2489 ‘ l\ |
2420 †\ |
2490 †\ |
2421 †\ |
2491 †\ |
2422 †\ |
2492 †\ |
2423 ‘ l\ |
2493 ‘ l\ |
2424 †\ |
2494 †\ |
2425 Œ ‰ b(l)Œ a=2^1\ |
2495 Œ ‰ b(l)\ |
|
2496 Œ a=2^1\ |
2426 Œ e=2^2\ |
2497 Œ e=2^2\ |
2427 Œ c=2^3\ |
2498 Œ c=2^3\ |
2428 Œ d=2^4\ |
2499 Œ d=2^4\ |
2429 Œ n=l:–(8)Œ n=l:–(8)Œ n=l:–(8)Œ n=l:–(8)Œ t=l:–(32)Œ t=l:–(8)Œ t=l:–(8)Š o(n,e)’\ |
2500 Œ n=l:–(8)\ |
2430 Œ n=l:–(16)Œ e=0\ |
2501 Œ n=l:–(8)\ |
|
2502 Œ n=l:–(8)\ |
|
2503 Œ n=l:–(8)\ |
|
2504 Œ t=l:–(32)\ |
|
2505 Œ t=l:–(8)\ |
|
2506 Œ t=l:–(8)\ |
|
2507 Š o(n,e)’\ |
|
2508 Œ n=l:–(16)\ |
|
2509 Œ e=0\ |
2431 ˆ n=1,n ƒ\ |
2510 ˆ n=1,n ƒ\ |
2432 e=l:–(8)†\ |
2511 e=l:–(8)\ |
|
2512 †\ |
2433 †\ |
2513 †\ |
2434 Š o(n,c)’\ |
2514 Š o(n,c)’\ |
2435 • l:–(8)~=0 ƒ †\ |
2515 • l:–(8)~=0 ƒ †\ |
2436 †\ |
2516 †\ |
2437 Š o(n,d)’\ |
2517 Š o(n,d)’\ |
2438 • l:–(8)~=0 ƒ †\ |
2518 • l:–(8)~=0 ƒ †\ |
2439 †\ |
2519 †\ |
2440 Š o(n,a)’\ |
2520 Š o(n,a)’\ |
2441 l:–(16)†\ |
2521 l:–(16)\ |
2442 †\ |
2522 †\ |
2443 Œ ‰ p(l)Œ f=l:–(5)Œ i=l:–(5)Œ e=n(l:–(4))Œ a=e+4\ |
2523 †\ |
2444 Œ e={}Œ o={16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15}ˆ n=1,a ƒ\ |
2524 Œ ‰ p(l)\ |
2445 Œ l=l:–(3)Œ n=o[n]e[n]=l\ |
2525 Œ f=l:–(5)\ |
2446 †\ |
2526 Œ i=l:–(5)\ |
2447 Œ e=d(e,“)Œ ‰ r(o)Œ t={}Œ a\ |
2527 Œ e=n(l:–(4))\ |
|
2528 Œ a=e+4\ |
|
2529 Œ e={}\ |
|
2530 Œ o={\ |
|
2531 16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15}\ |
|
2532 ˆ n=1,a ƒ\ |
|
2533 Œ l=l:–(3)\ |
|
2534 Œ n=o[n]\ |
|
2535 e[n]=l\ |
|
2536 †\ |
|
2537 Œ e=d(e,“)\ |
|
2538 Œ ‰ r(o)\ |
|
2539 Œ t={}\ |
|
2540 Œ a\ |
2448 Œ c=0\ |
2541 Œ c=0\ |
2449 • c<o ƒ\ |
2542 • c<o ƒ\ |
2450 Œ o=e:–(l)Œ e\ |
2543 Œ o=e:–(l)\ |
|
2544 Œ e\ |
2451 Š o<=15 ’\ |
2545 Š o<=15 ’\ |
2452 e=1\ |
2546 e=1\ |
2453 a=o\ |
2547 a=o\ |
2454 … o==16 ’\ |
2548 … o==16 ’\ |
2455 e=3+n(l:–(2))… o==17 ’\ |
2549 e=3+n(l:–(2))\ |
2456 e=3+n(l:–(3))a=0\ |
2550 … o==17 ’\ |
|
2551 e=3+n(l:–(3))\ |
|
2552 a=0\ |
2457 … o==18 ’\ |
2553 … o==18 ’\ |
2458 e=11+n(l:–(7))a=0\ |
2554 e=11+n(l:–(7))\ |
|
2555 a=0\ |
2459 „\ |
2556 „\ |
2460 h'ASSERT'†\ |
2557 h'ASSERT'\ |
|
2558 †\ |
2461 ˆ l=1,e ƒ\ |
2559 ˆ l=1,e ƒ\ |
2462 t[c]=a\ |
2560 t[c]=a\ |
2463 c=c+1\ |
2561 c=c+1\ |
2464 †\ |
2562 †\ |
2465 †\ |
2563 †\ |
2466 Œ l=d(t,“)‘ l\ |
2564 Œ l=d(t,“)\ |
|
2565 ‘ l\ |
2467 †\ |
2566 †\ |
2468 Œ n=f+257\ |
2567 Œ n=f+257\ |
2469 Œ l=i+1\ |
2568 Œ l=i+1\ |
2470 Œ n=r(n)Œ l=r(l)‘ n,l\ |
2569 Œ n=r(n)\ |
|
2570 Œ l=r(l)\ |
|
2571 ‘ n,l\ |
2471 †\ |
2572 †\ |
2472 Œ a\ |
2573 Œ a\ |
2473 Œ o\ |
2574 Œ o\ |
2474 Œ c\ |
2575 Œ c\ |
2475 Œ r\ |
2576 Œ r\ |
2476 Œ ‰ h(e,n,l,d)Œ l=l:–(e)Š l<256 ’\ |
2577 Œ ‰ h(e,n,l,d)\ |
2477 t(n,l)… l==256 ’\ |
2578 Œ l=l:–(e)\ |
|
2579 Š l<256 ’\ |
|
2580 t(n,l)\ |
|
2581 … l==256 ’\ |
2478 ‘ “\ |
2582 ‘ “\ |
2479 „\ |
2583 „\ |
2480 Š Ž a ’\ |
2584 Š Ž a ’\ |
2481 Œ l={[257]=3}Œ e=1\ |
2585 Œ l={[257]=3}\ |
|
2586 Œ e=1\ |
2482 ˆ n=258,285,4 ƒ\ |
2587 ˆ n=258,285,4 ƒ\ |
2483 ˆ n=n,n+3 ƒ l[n]=l[n-1]+e †\ |
2588 ˆ n=n,n+3 ƒ l[n]=l[n-1]+e †\ |
2484 Š n~=258 ’ e=e*2 †\ |
2589 Š n~=258 ’ e=e*2 †\ |
2485 †\ |
2590 †\ |
2486 l[285]=258\ |
2591 l[285]=258\ |
2487 a=l\ |
2592 a=l\ |
2488 †\ |
2593 †\ |
2489 Š Ž o ’\ |
2594 Š Ž o ’\ |
2490 Œ l={}ˆ e=257,285 ƒ\ |
2595 Œ l={}\ |
2491 Œ n=u(e-261,0)l[e]=(n-(n%4))/4\ |
2596 ˆ e=257,285 ƒ\ |
|
2597 Œ n=u(e-261,0)\ |
|
2598 l[e]=(n-(n%4))/4\ |
2492 †\ |
2599 †\ |
2493 l[285]=0\ |
2600 l[285]=0\ |
2494 o=l\ |
2601 o=l\ |
2495 †\ |
2602 †\ |
2496 Œ a=a[l]Œ l=o[l]Œ l=e:–(l)Œ o=a+l\ |
2603 Œ a=a[l]\ |
|
2604 Œ l=o[l]\ |
|
2605 Œ l=e:–(l)\ |
|
2606 Œ o=a+l\ |
2497 Š Ž c ’\ |
2607 Š Ž c ’\ |
2498 Œ e={[0]=1}Œ l=1\ |
2608 Œ e={[0]=1}\ |
|
2609 Œ l=1\ |
2499 ˆ n=1,29,2 ƒ\ |
2610 ˆ n=1,29,2 ƒ\ |
2500 ˆ n=n,n+1 ƒ e[n]=e[n-1]+l †\ |
2611 ˆ n=n,n+1 ƒ e[n]=e[n-1]+l †\ |
2501 Š n~=1 ’ l=l*2 †\ |
2612 Š n~=1 ’ l=l*2 †\ |
2502 †\ |
2613 †\ |
2503 c=e\ |
2614 c=e\ |
2504 †\ |
2615 †\ |
2505 Š Ž r ’\ |
2616 Š Ž r ’\ |
2506 Œ n={}ˆ e=0,29 ƒ\ |
2617 Œ n={}\ |
2507 Œ l=u(e-2,0)n[e]=(l-(l%2))/2\ |
2618 ˆ e=0,29 ƒ\ |
|
2619 Œ l=u(e-2,0)\ |
|
2620 n[e]=(l-(l%2))/2\ |
2508 †\ |
2621 †\ |
2509 r=n\ |
2622 r=n\ |
2510 †\ |
2623 †\ |
2511 Œ l=d:–(e)Œ a=c[l]Œ l=r[l]Œ l=e:–(l)Œ l=a+l\ |
2624 Œ l=d:–(e)\ |
|
2625 Œ a=c[l]\ |
|
2626 Œ l=r[l]\ |
|
2627 Œ l=e:–(l)\ |
|
2628 Œ l=a+l\ |
2512 ˆ e=1,o ƒ\ |
2629 ˆ e=1,o ƒ\ |
2513 Œ l=(n.™-1-l)%32768+1\ |
2630 Œ l=(n.™-1-l)%32768+1\ |
2514 t(n,i(n.wnd[l],'invalid distance'))†\ |
2631 t(n,i(n.wnd[l],'invalid distance'))\ |
|
2632 †\ |
2515 †\ |
2633 †\ |
2516 ‘ ‡\ |
2634 ‘ ‡\ |
2517 †\ |
2635 †\ |
2518 Œ ‰ u(l,a)Œ i=l:–(1)Œ e=l:–(2)Œ r=0\ |
2636 Œ ‰ u(l,a)\ |
|
2637 Œ i=l:–(1)\ |
|
2638 Œ e=l:–(2)\ |
|
2639 Œ r=0\ |
2519 Œ o=1\ |
2640 Œ o=1\ |
2520 Œ c=2\ |
2641 Œ c=2\ |
2521 Œ f=3\ |
2642 Œ f=3\ |
2522 Š e==r ’\ |
2643 Š e==r ’\ |
2523 l:–(l:˜())Œ e=l:–(16)Œ o=n(l:–(16))ˆ e=1,e ƒ\ |
2644 l:–(l:˜())\ |
2524 Œ l=n(l:–(8))t(a,l)†\ |
2645 Œ e=l:–(16)\ |
|
2646 Œ o=n(l:–(16))\ |
|
2647 ˆ e=1,e ƒ\ |
|
2648 Œ l=n(l:–(8))\ |
|
2649 t(a,l)\ |
|
2650 †\ |
2525 … e==o e==c ’\ |
2651 … e==o e==c ’\ |
2526 Œ n,o\ |
2652 Œ n,o\ |
2527 Š e==c ’\ |
2653 Š e==c ’\ |
2528 n,o=p(l)„\ |
2654 n,o=p(l)\ |
2529 n=d{0,8,144,9,256,7,280,8,288,}o=d{0,5,32,}†\ |
2655 „\ |
2530 ” h(l,a,n,o);†\ |
2656 n=d{0,8,144,9,256,7,280,8,288,}\ |
|
2657 o=d{0,5,32,}\ |
|
2658 †\ |
|
2659 ” h(\ |
|
2660 l,a,n,o\ |
|
2661 );\ |
|
2662 †\ |
2531 ‘ i~=0\ |
2663 ‘ i~=0\ |
2532 †\ |
2664 †\ |
2533 Œ ‰ e(l)Œ n,l=f(l.œ),_(s(l.š)) ” u(n,l)†\ |
2665 Œ ‰ e(l)\ |
2534 ‘ ‰(n)Œ l=f(n.œ)Œ n=s(n.š)b(l)e{œ=l,š=n}l:–(l:˜())l:–()†\ |
2666 Œ n,l=f(l.œ)\ |
|
2667 ,_(s(l.š))\ |
|
2668 ” u(n,l)\ |
|
2669 †\ |
|
2670 ‘ ‰(n)\ |
|
2671 Œ l=f(n.œ)\ |
|
2672 Œ n=s(n.š)\ |
|
2673 b(l)\ |
|
2674 e{œ=l,š=n}\ |
|
2675 l:–(l:˜())\ |
|
2676 l:–()\ |
|
2677 †\ |
2535 ]===], '@gunzip.lua')), getfenv())()"e["squish.debug"]="package.preload['minichunkspy']=(function(...)local _ENV=_ENV;local function module(name,...)local t=package.loaded[name]or _ENV[name]or{_NAME=name};package.loaded[name]=t;for i=1,select(\"#\",...)do(select(i,...))(t);end\ |
2678 ]===], '@gunzip.lua')), getfenv())()"e["squish.debug"]="package.preload['minichunkspy']=(function(...)local _ENV=_ENV;local function module(name,...)local t=package.loaded[name]or _ENV[name]or{_NAME=name};package.loaded[name]=t;for i=1,select(\"#\",...)do(select(i,...))(t);end\ |
2536 _ENV=t;_M=t;return t;end\ |
2679 _ENV=t;_M=t;return t;end\ |
2537 local string,table,math=string,table,math\ |
2680 local string,table,math=string,table,math\ |
2538 local ipairs,setmetatable,type,assert=ipairs,setmetatable,type,assert\ |
2681 local ipairs,setmetatable,type,assert=ipairs,setmetatable,type,assert\ |
2539 local _=__END_OF_GLOBALS__\ |
2682 local _=__END_OF_GLOBALS__\ |
2960 ["opt-numbers"]=e.minify_numbers; |
3103 ["opt-numbers"]=e.minify_numbers; |
2961 } |
3104 } |
2962 local function i(e) |
3105 local function i(e) |
2963 t("minify: "..e);os.exit(1); |
3106 t("minify: "..e);os.exit(1); |
2964 end |
3107 end |
2965 local function u(t) |
3108 local function l(e) |
2966 local e=io.open(t,"rb") |
3109 local t=io.open(e,"rb") |
2967 if not e then i("cannot open \""..t.."\" for reading")end |
3110 if not t then i("cannot open \""..e.."\" for reading")end |
2968 local a=e:read("*a") |
3111 local a=t:read("*a") |
2969 if not a then i("cannot read from \""..t.."\"")end |
3112 if not a then i("cannot read from \""..e.."\"")end |
2970 e:close() |
3113 t:close() |
2971 return a |
3114 return a |
2972 end |
3115 end |
2973 local function l(t,a) |
3116 local function u(e,a) |
2974 local e=io.open(t,"wb") |
3117 local t=io.open(e,"wb") |
2975 if not e then i("cannot open \""..t.."\" for writing")end |
3118 if not t then i("cannot open \""..e.."\" for writing")end |
2976 local a=e:write(a) |
3119 local a=t:write(a) |
2977 if not a then i("cannot write to \""..t.."\"")end |
3120 if not a then i("cannot write to \""..e.."\"")end |
2978 e:close() |
3121 t:close() |
2979 end |
3122 end |
2980 function minify_string(e) |
3123 function minify_string(e) |
2981 a.init(e) |
3124 a.init(e) |
2982 a.llex() |
3125 a.llex() |
2983 local t,e,a |
3126 local t,e,a |
2984 =a.tok,a.seminfo,a.tokln |
3127 =a.tok,a.seminfo,a.tokln |
2985 if n["opt-locals"]then |
3128 if n["opt-locals"]then |
2986 r.print=print |
3129 r.print=print |
2987 d.init(t,e,a) |
3130 d.init(t,e,a) |
2988 local a,o=d.parser() |
3131 local o,a=d.parser() |
2989 r.optimize(n,t,e,a,o) |
3132 r.optimize(n,t,e,o,a) |
2990 end |
3133 end |
2991 h.print=print |
3134 h.print=print |
2992 t,e,a |
3135 t,e,a |
2993 =h.optimize(n,t,e,a) |
3136 =h.optimize(n,t,e,a) |
2994 local e=table.concat(e) |
3137 local e=table.concat(e) |
3013 local n={"and","break","do","else","elseif", |
3156 local n={"and","break","do","else","elseif", |
3014 "end","false","for","function","if", |
3157 "end","false","for","function","if", |
3015 "in","local","nil","not","or","repeat", |
3158 "in","local","nil","not","or","repeat", |
3016 "return","then","true","until","while"} |
3159 "return","then","true","until","while"} |
3017 function uglify_file(l,o) |
3160 function uglify_file(l,o) |
3018 local s,a=io.open(l); |
3161 local r,a=io.open(l); |
3019 if not s then |
3162 if not r then |
3020 t("Can't open input file for reading: "..tostring(a)); |
3163 t("Can't open input file for reading: "..tostring(a)); |
3021 return; |
3164 return; |
3022 end |
3165 end |
3023 local a,r=io.open(o..".uglified","w+b"); |
3166 local a,s=io.open(o..".uglified","w+b"); |
3024 if not a then |
3167 if not a then |
3025 t("Can't open output file for writing: "..tostring(r)); |
3168 t("Can't open output file for writing: "..tostring(s)); |
3026 return; |
3169 return; |
3027 end |
3170 end |
3028 local t=s:read("*a"); |
3171 local s=r:read("*a"); |
3029 s:close(); |
3172 r:close(); |
3030 local r,s=t:match("^(#.-\n)(.+)$"); |
3173 local r,t=s:match("^(#.-\n)(.+)$"); |
3031 local s=s or t; |
3174 local t=t or s; |
3032 if r then |
3175 if r then |
3033 a:write(r) |
3176 a:write(r) |
3034 end |
3177 end |
3035 while i+#n<=255 and s:find("["..string.char(i).."-"..string.char(i+#n-1).."]")do |
3178 while i+#n<=255 and t:find("["..string.char(i).."-"..string.char(i+#n-1).."]")do |
3036 i=i+1; |
3179 i=i+1; |
3037 end |
3180 end |
3038 if i+#n>255 then |
3181 if i+#n>255 then |
3039 a:write(s); |
3182 a:write(t); |
3040 a:close(); |
3183 a:close(); |
3041 os.rename(o..".uglified",o); |
3184 os.rename(o..".uglified",o); |
3042 return; |
3185 return; |
3043 end |
3186 end |
3044 local d={} |
3187 local d={} |
3045 for t,e in ipairs(n)do |
3188 for t,e in ipairs(n)do |
3046 d[e]=string.char(i+t); |
3189 d[e]=string.char(i+t); |
3047 end |
3190 end |
3048 local r=0; |
3191 local r=0; |
3049 t:gsub("(=+)",function(e)r=math.max(r,#e);end); |
3192 s:gsub("(=+)",function(e)r=math.max(r,#e);end); |
3050 h.init(s,"@"..l); |
3193 h.init(t,"@"..l); |
3051 h.llex() |
3194 h.llex() |
3052 local s=h.seminfo; |
3195 local s=h.seminfo; |
3053 if e.uglify_level=="full"and i+#n<255 then |
3196 if e.uglify_level=="full"and i+#n<255 then |
3054 local e={}; |
3197 local e={}; |
3055 for o,a in ipairs(h.tok)do |
3198 for o,a in ipairs(h.tok)do |
3108 o("Uglifying "..out_fn.."..."); |
3251 o("Uglifying "..out_fn.."..."); |
3109 uglify_file(out_fn,out_fn); |
3252 uglify_file(out_fn,out_fn); |
3110 o("OK!"); |
3253 o("OK!"); |
3111 end |
3254 end |
3112 local i=require"minichunkspy" |
3255 local i=require"minichunkspy" |
3113 function compile_string(a,t) |
3256 function compile_string(t,a) |
3114 local a=string.dump(loadstring(a,t)); |
3257 local o=string.dump(loadstring(t,a)); |
3115 if((not e.debug)or e.compile_strip)and e.compile_strip~=false then |
3258 if((not e.debug)or e.compile_strip)and e.compile_strip~=false then |
3116 local a=i.disassemble(a); |
3259 local t=i.disassemble(o); |
3117 local function t(e) |
3260 local function a(e) |
3118 e.source_lines,e.locals,e.upvalues={},{},{}; |
3261 e.source_lines,e.locals,e.upvalues={},{},{}; |
3119 for a,e in ipairs(e.prototypes)do |
3262 for t,e in ipairs(e.prototypes)do |
3120 t(e); |
3263 a(e); |
3121 end |
3264 end |
3122 end |
3265 end |
3123 s("Stripping debug info..."); |
3266 s("Stripping debug info..."); |
3124 t(a.body); |
3267 a(t.body); |
3125 return i.assemble(a); |
3268 return i.assemble(t); |
3126 end |
3269 end |
3127 return a; |
3270 return o; |
3128 end |
3271 end |
3129 function compile_file(a,e) |
3272 function compile_file(a,e) |
3130 local o,a=io.open(a); |
3273 local o,a=io.open(a); |
3131 if not o then |
3274 if not o then |
3132 t("Can't open input file for reading: "..tostring(a)); |
3275 t("Can't open input file for reading: "..tostring(a)); |