2
# (c) Software Lab. Alexander Burger
4
(setq *OS (java (java "java.lang.System" "getProperty" "os.name")))
6
############ lib.l ############
10
(Prg (del (assoc Key *Run) '*Run))
11
((num? Key) (quit "Bad Key" Key))
16
(when (lt0 (link Key))
17
(link (+ (eval (pop 'Prg) 1))) ) )
25
(while (atom (car Prg))
27
(cons (pop 'Prg) (eval (pop 'Prg) 1)) ) ) ) )
29
(NIL (quit "Key conflict" Key)) ) )
32
(if2 N (assoc -1 *Run)
34
(push '*Run (list -1 (+ N) '(bye)))
44
(let ("X" (pop '"Z") "Y" (pop '"Z") "P" (filter pat? "X"))
45
(if2 "P" (diff "X" "P")
46
(list "Y" (cons 'job (lit (env @)) (fill "Z" "P")))
47
(cons "Y" (fill "Z" "P"))
48
(list "Y" (cons 'job (lit (env @)) "Z"))
56
(list '@ (list 'pass (box (getd "F")))) ) )
60
(getd (cadr (cadr (getd "F")))) ) )
64
(setq "C" (cdr "X") "X" (car "X")) )
66
(prog1 (val "X") (set "X"))
68
(cdr (asoq "X" (val "C")))
70
(delq (asoq "X" (val "C")) (val "C")) ) ) ) )
73
(let ("Old" (car "Lst") "New" (name "Old"))
77
"Old" (fill (cdr "Lst") "Old") )
80
(de daemon ("X" . Prg)
84
(or (pair (getd "X")) (expr "X")) )
86
(method (car "X") (cdr "X")) )
88
(method (car "X") (get (or (cddr "X") *Class) (cadr "X"))) ) )
89
(con @ (append Prg (cdr @))) ) )
91
(de patch ("Lst" "Pat" . "Prg")
92
(bind (fish pat? "Pat")
96
((match "Pat" (car "Lst"))
97
(set "Lst" (run "Prg")) )
101
(T (atom (cdr "Lst"))
102
(when (match "Pat" (cdr "Lst"))
103
(con "Lst" (run "Prg")) ) )
104
(setq "Lst" (cdr "Lst")) ) ) ) )
108
(de cache ("Var" "Str" . Prg)
110
((setq "Var" (car (idx "Var" "Str" T)))
111
(set "Str" "Str" "Str" (run Prg 1)) )
112
((n== "Var" (val "Var"))
113
(set "Var" (run Prg 1)) )
114
(NIL (val "Var")) ) )
122
(and (gt0 N) (space (- N (length V))))
124
(and (lt0 N) (args) (space (- 0 N (length V)))) ) )
137
(de script (File . @)
141
(unless (idx '*Once (file) T)
145
(when (== "Pil" '"Pil")
146
(call 'mkdir "-p" (setq "Pil" `(pack (sys "HOME") "/.pil/"))) )
152
(push '*Bye '(call 'rm "-r" *Tmp))
153
(call 'mkdir "-p" (setq *Tmp (pil "tmp/" *Pid "/"))) )
177
'((X) (not (idx 'R X T)))
183
(if (assoc (car X) (made))
184
(conc @ (cons (cdr X)))
185
(link (list (car X) (cdr X))) ) ) ) )
189
(cons (val "Sym") (getl "Sym")) )
192
(if (and (str? X) (= S X))
198
(loc S (cdr X)) ) ) ) )
202
(let L (val (setq *Class (car Lst)))
207
(cons (car L) (recurse (cdr L))) ) ) ) ) )
209
(de object ("Sym" "Val" . @)
213
(put "Sym" (next) (next)) )
217
(setq *Class (car X)) )
221
(put *Class (car X) (cdr X)) )
224
(apply meta X This) )
232
((lt0 N) (quit "Bad argument" N))
242
(setq B (>> 1 B) A (>> 2 A))
244
(and F (> N B) (inc 'B))
247
# (Knuth Vol.2, p.442)
248
(de ** (X N) # N th power of X
253
(T (=0 (setq N (>> 1 N)))
255
(setq X (* X X)) ) ) )
257
(de accu (Var Key Val)
259
(if (assoc Key (val Var))
260
(con @ (+ Val (cdr @)))
261
(push Var (cons Key Val)) ) ) )
263
### Pretty Printing ###
265
T NIL if ifn when unless while until do case state for
266
with catch finally ! setq default push job use let let?
267
prog1 recur redef =: in out tab new )
268
(de *PP1 let let? for redef)
269
(de *PP2 setq default)
273
(setq N (abs (space (or N 0))))
276
(if (or (atom X) (>= 12 (size X)))
278
(while (== 'quote (car X))
284
((memq (print (pop 'X)) *PP)
287
(if (and (pair (car X)) (pair (cdar X)))
288
(when (>= 12 (size (car X)))
293
(when (or (atom (car X)) (>= 12 (size (car X))))
295
(print (pop 'X)) ) ) )
300
(pretty (cadr X) N (car X))
301
(NIL (setq X (cddr X)) (space)) ) )
302
((or (atom (car X)) (>= 12 (size (car X))))
304
(print (pop 'X)) ) ) )
305
((and (memq (car Z) *PP3) (>= 12 (size (head 2 X))))
307
(print (pop 'X) (pop 'X)) ) )
310
(T (== Z X) (prin " ."))
311
(T (atom X) (prin " . ") (print X))
313
(pretty (pop 'X) (+ 3 N))
320
(and (pair "X") (setq C (cdr "X")))
322
(printsp (if C 'dm 'de))
326
(method (if (pair "X") (car "X") "X") C)
329
((atom "X") (prin ". ") (print "X"))
340
(T (== Z "X") (prin " ."))
346
(pretty (pop '"X") 3) )
352
(setq "X" (pass get "X"))
354
(print "X" (val "X"))
361
(println (cdr X) (car X)) ) )
371
(recurse (+ 3 N) (cddr X))
374
(recurse (+ 3 N) (cadr X)) ) ) )
377
(T (atom X) (println X))
379
(println '+-- (pop 'X))
383
(append Y (cons (if X "| " " "))) ) )
386
(T (== Z X) (println '*))
388
(mapc prin Y) ) ) ) ) )
395
(if (cdr Prg) (cons 'and Prg) (car Prg))
396
(list 'quit "'assert' failed" (lit (car Prg))) ) ) ) )
398
############ lib/misc.l ############
402
(de *Day . (Mon Tue Wed Thu Fri Sat Sun .))
403
(de *Mon . (Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec .))
404
(de *mon . (jan feb mar apr may jun jul aug sep oct nov dec .))
412
(de *DateFmt @Y "-" @M "-" @D)
413
(de *DayFmt "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday" "Sunday")
414
(de *MonFmt "January" "February" "March" "April" "May" "June" "July" "August" "September" "October" "November" "December")
416
(de locale (Ctry Lang App) # "DE" "de" ["app/loc/"]
417
(load (if (setq *Ctry Ctry) (pack "@loc/" @ ".l") "@loc/NIL.l"))
418
(ifn (setq *Lang Lang)
424
("loc" (pack "@loc/" Lang))
425
(and App ("loc" (pack App Lang))) ) )
428
(set (car (idx '*Uni S)) (val S)) ) ) ) )
433
(while (setq X (read))
436
(set (link @) (name (read))) ) ) ) ) )
443
'((X) (need X (chop (next)) " "))
445
(need X (chop (next)) " ") ) ) )
453
(let (S (chop (next)) N (>> 1 (+ X (length S))))
456
(setq R (- X N)) ) ) )
459
(need (>> 1 (+ X (length S))) S " ") ) ) ) )
462
(setq Lst (split Lst " " "^J"))
466
(if (>= (length (car Lst)) Max)
467
(link (pop 'Lst) "^J")
473
(T (>= (+ (length (car Lst)) (sum length (made))) Max)
475
(link " " (pop 'Lst)) ) ) ) ) ) ) ) )
479
(pack (need N (chop Val) "0")) )
483
(pack (format N 2 *Sep0 *Sep3) " " Cur)
484
(format N 2 *Sep0 *Sep3) ) )
487
(if (> *Scl (default D 3))
488
(format (*/ N (** 10 (- *Scl D))) D *Sep0 *Sep3)
489
(format N *Scl *Sep0 *Sep3) ) )
495
(let (S (and (lt0 X) '-) L (& 1 X) A (cons 0 I))
496
(until (=0 (setq X (>> 1 X)))
500
((setq X (filter '((C) (not (sp? C))) (chop X)))
501
(let (S (and (= '- (car X)) (pop 'X)) N 0)
503
(setq N (| (format C) (>> -1 N))) )
504
(if S (- N) N) ) ) ) )
510
(let (S (and (lt0 X) '-) L (& 7 X) A (cons 0 I))
511
(until (=0 (setq X (>> 3 X)))
515
((setq X (filter '((C) (not (sp? C))) (chop X)))
516
(let (S (and (= '- (car X)) (pop 'X)) N 0)
518
(setq N (| (format C) (>> -3 N))) )
519
(if S (- N) N) ) ) ) )
521
# Hexadecimal notation
525
(let (S (and (lt0 X) '-) L (hex1 X) A (cons 0 I))
526
(until (=0 (setq X (>> 4 X)))
530
((setq X (filter '((C) (not (sp? C))) (chop X)))
531
(let (S (and (= '- (car X)) (pop 'X)) N 0)
533
(setq C (- (char C) `(char "0")))
534
(and (> C 9) (dec 'C 7))
535
(and (> C 22) (dec 'C 32))
536
(setq N (| C (>> -4 N))) )
537
(if S (- N) N) ) ) ) )
541
(and (> C 9) (inc 'C 7))
542
(char (+ C `(char "0"))) ) )
545
(de balance ("Var" "Lst" "Flg")
546
(unless "Flg" (set "Var"))
547
(let "Len" (length "Lst")
550
(let ("N" (>> 1 (inc "Len")) "L" (nth "Lst" "N"))
551
(idx "Var" (car "L") T)
552
(recurse "Lst" (dec "N"))
553
(recurse (cdr "L") (- "Len" "N")) ) ) ) ) )
557
(setq *Allow (cons NIL (car Lst)))
558
(balance *Allow (sort (cdr Lst))) )
563
(Flg (idx *Allow X T))
564
((member X (cdr *Allow))
565
(conc *Allow (cons X)) ) )
572
((and *CtryCode (pre? (pack *CtryCode " ") S))
573
(pack 0 (cdddr (chop S))) )
580
(ifn (sub? (car L) " -")
584
(and (= '- (pop 'L)) (on F))
586
(NIL (sub? (car L) " -")
587
(link (if F '- " ")) ) ) ) ) ) ) )
589
((= "+" (car S)) (pack (cdr S)))
592
((and *CtryCode (= "0" (car S)))
593
(pack *CtryCode " " (cdr S)) ) ) )
599
(pack (car @) C (pad 2 (cadr @)) C (pad 2 (caddr @))) ) )
605
(length (setq S (split (chop S) C))) )
607
(format (car S)) # Year
608
(or (format (cadr S)) 0) # Month
609
(or (format (caddr S)) 0) ) ) # Day
614
(% (/ @ 100) 100) # Month
622
(pad 2 (% (car @) 100)) ) ) )
626
(when (setq D (date D))
628
(@Y (if F (pad 2 (% (car D) 100)) (pad 4 (car D)))
630
@D (pad 2 (caddr D)) )
631
(pack (fill *DateFmt)) ) ) )
636
(match *DateFmt (chop S))
640
(or (format @D) 0) ) ) ) )
644
(unless (match *DateFmt (setq S (chop S)))
647
(cdr (setq S (split S ".")))
648
(>= 2 (length (car S))) )
655
@M (head 2 (nth (car S) 3))
656
@Y (nth (car S) 5) ) ) )
658
(setq @D (format @D))
661
(@Y (car (date (date))))
662
((setq X (format @Y)))
665
(* 100 (/ (car (date (date))) 100)) ) )
668
(@M (cadr (date (date))))
669
((setq X (format @M)) 0)
670
((n0 X) (cadr (date (date))))
678
(inc (% (inc Dat) 7)) ) )
685
(_week (date (car (date Dat)) 1 4))
690
(/ (- Dat (% (inc Dat) 7)) 7) )
697
(date Y (inc M) 1) ) ) )
702
(setq Tim (time Tim))
703
(pack (pad 2 (car Tim)) ":" (pad 2 (cadr Tim))
705
(and F (pad 2 (caddr Tim))) ) ) )
708
(setq S (split (chop S) ":"))
709
(unless (or (cdr S) (>= 2 (length (car S))))
713
(head 2 (nth (car S) 3))
714
(nth (car S) 5) ) ) )
715
(when (format (car S))
717
(or (format (cadr S)) 0)
718
(or (format (caddr S)) 0) ) ) )
721
(and (=T Dat) (setq Dat (date T)))
722
(default Dat (date) Tim (time T))
723
(pack (dat$ Dat "-") " " (tim$ Tim T)) )
727
(pack (flip (member '/ (flip (chop F))))) )
730
(pack (stem (chop F) '/)) )
740
# Echo here-documents
747
(bind (fish pat? Pat)
748
(unless (match Pat (run Prg 1))
750
(quit "'test' failed" Pat) ) ) )
752
############ lib/pilog.l ############
762
(=: T (conc (: T) (cons (cdr CL))))
763
(=: T (cons (cdr CL)))
768
(conc (get *Rule T) (get *Rule T)) )
772
(=: T (cons (cdr CL) (: T))) ) )
776
(=: T (conc (: T) (cons (cdr CL)))) ) )
782
(delete (cdr X) (get (car X) T)) ) ) )
787
(for ((N . L) (get S T) L)
795
(println '(repeat)) ) )
798
### Pilog Interpreter ###
803
(cons (cons 0 (next)) 1 (next)) ) )
804
(while (and "CL" (pat? (car "CL")))
808
(cons 1 (eval (pop '"CL"))) ) ) )
811
(conc (list 1 (0) NIL "CL" NIL) "Env") ) ) ) )
816
(de pilog ("CL" . "Prg")
817
(for ("Q" (goal "CL") (prove "Q"))
818
(bind @ (run "Prg")) ) )
820
(de solve ("CL" . "Prg")
823
(for ("Q" (goal "CL") (prove "Q"))
824
(link (bind @ (run "Prg"))) )
825
(for ("Q" (goal "CL") (prove "Q"))
828
(de query ("Q" "Dbg")
831
(NIL (prove "Q" "Dbg"))
832
(T (=T (setq "R" @)) T)
844
(while (nor (pat? (car "CL")) (lst? (car "CL")))
845
(link (pop '"CL")) ) )
846
(query (goal "CL") "L") ) )
854
(be not @P (1 -> @P) T (fail))
860
(be or @L (@C box (-> @L)) (_or @C))
862
(be _or (@C) (3 pop (-> @C)))
863
(be _or (@C) (@ not (val (-> @C))) T (fail))
866
(be nil (@X) (@ not (-> @X)))
870
(be different (@X @X) T (fail))
873
(be append (NIL @X @X))
874
(be append ((@A . @X) @Y (@A . @Z)) (append @X @Y @Z))
876
(be member (@X (@X . @)))
877
(be member (@X (@ . @Y)) (member @X @Y))
879
(be delete (@A (@A . @Z) @Z))
880
(be delete (@A (@X . @Y) (@X . @Z))
883
(be permute ((@X) (@X)))
884
(be permute (@L (@X . @Y))
889
(@ not (idx (-> @B) (-> @X) T)) )
891
(be asserta (@C) (@ asserta (-> @C)))
893
(be assertz (@C) (@ assertz (-> @C)))
897
(@ retract (list (car (-> @C)) (cdr (-> @C)))) )
899
(be clause ("@H" "@B")
900
("@A" get (-> "@H") T)
903
(be show (@X) (@ show (-> @X)))
907
(@V apply get (-> @L))
911
(@Lst box (apply get (-> @L)))
914
(be _lst (@Val @Lst) (@ not (val (-> @Lst))) T (fail))
915
(be _lst (@Val @Lst) (@Val pop (-> @Lst)))
919
(@Lst box (apply get (-> @L)))
922
(be _map (@Val @Lst) (@ not (val (-> @Lst))) T (fail))
923
(be _map (@Val @Lst) (@Val prog1 (val (-> @Lst)) (pop (-> @Lst))))
930
(isa (-> @Typ) (apply get (-> @L))) ) )
937
("same" (car L) (cdr L)) ) ) ) )
946
("same" (get X (car L)) (cdr L)) )
949
'((Y) ("same" (get Y (car L)) (cdr L)))
951
(T ("same" (apply get (car L) X) (cdr L))) ) )
956
(apply get (-> @L)) ) )
963
("range" (car L) (cdr L)) ) ) ) )
970
(<= (car N) X (cdr N))
971
(>= (car N) X (cdr N)) )
975
(<= (car N) Y (cdr N))
976
(>= (car N) Y (cdr N)) ) )
979
("range" (get X (car L)) (cdr L)) )
982
'((Y) ("range" (get Y (car L)) (cdr L)))
984
(T ("range" (apply get (car L) X) (cdr L))) ) )
991
("head" (car L) (cdr L)) ) ) ) )
998
(find '((Y) (pre? S Y)) X) ) )
1000
("head" (get X (car L)) (cdr L)) )
1003
'((Y) ("head" (get Y (car L)) (cdr L)))
1005
(T ("head" (apply get (car L) X) (cdr L))) ) )
1012
("fold" (car L) (cdr L)) ) ) ) )
1020
(find '((Y) (pre? P (fold Y))) X) ) ) )
1022
("fold" (get X (car L)) (cdr L)) )
1025
'((Y) ("fold" (get Y (car L)) (cdr L)))
1027
(T ("fold" (apply get (car L) X) (cdr L))) ) )
1034
("part" (car L) (cdr L)) ) ) ) )
1042
(find '((Y) (sub? P (fold Y))) X) ) ) )
1044
("part" (get X (car L)) (cdr L)) )
1047
'((Y) ("part" (get Y (car L)) (cdr L)))
1049
(T ("part" (apply get (car L) X) (cdr L))) ) )
1056
("tolr" (car L) (cdr L)) ) ) ) )
1062
(or (sub? S X) (pre? (ext:Snx S) (ext:Snx X)))
1066
(or (sub? S Y) (pre? P (ext:Snx Y))) )
1069
("tolr" (get X (car L)) (cdr L)) )
1072
'((Y) ("tolr" (get Y (car L)) (cdr L)))
1074
(T ("tolr" (apply get (car L) X) (cdr L))) ) )
1077
(be _remote ((@Obj . @))
1078
(@ not (val (-> @Sockets 2)))
1082
(be _remote ((@Obj . @))
1083
(@Obj let (Box (-> @Sockets 2) Lst (val Box))
1087
(NIL (set Box (setq Lst (cdr Lst)))) ) ) )
1091
############ lib/xm.l ############
1093
# Check or write header
1096
(prinl "<?xml version=\"1.0\" encoding=\"utf-8\"?>")
1099
(head '("<" "?" "x" "m" "l") (till ">"))
1102
# Generate/Parse XML data
1106
(space (default N 0))
1109
(prin " " (car X) "=\"")
1114
((or (cdr Lst) (pair (car Lst)))
1117
(prinl "</" Tag ">") )
1127
(prinl "</" Tag ">") ) ) )
1129
(unless (= "<" (char))
1131
(_xml (till " /<>" T)) ) )
1140
(NIL (skip) (quit "XML parse error"))
1141
(T (member @ '`(chop "/>")))
1142
(NIL (setq X (intern (till "=" T))))
1144
(unless (= "\"" (char))
1145
(quit "XML parse error" X) )
1146
(link (cons X (pack (xmlEsc (till "\"")))))
1149
(prog (char) (and L (link L)))
1152
(NIL (skip) (quit "XML parse error" Tok))
1153
(T (and (= "<" (setq X (char))) (= "/" (peek)))
1155
(unless (= Tok (till " /<>" T))
1156
(quit "Unbalanced XML" Tok) )
1159
(and (_xml (till " /<>" T)) (link @))
1161
(pack (xmlEsc (trim (cons X (till "^J<"))))) ) ) ) ) ) ) ) )
1167
(ifn (match '("&" @X ";" @Z) L)
1171
((= @X '`(chop "quot")) "\"")
1172
((= @X '`(chop "amp")) "&")
1173
((= @X '`(chop "lt")) "<")
1174
((= @X '`(chop "gt")) ">")
1175
((= @X '`(chop "apos")) "'")
1178
(if (= "x" (cadr @X))
1180
(format (cdr @X)) ) ) )
1182
(setq L @Z) ) ) ) ) )
1186
(if (member C '`(chop "\"&<"))
1187
(prin "&#" (char C) ";")
1193
(while (and (setq Lst (cddr Lst)) (args))
1194
(setq Lst (assoc (next) Lst)) )
1197
(de attr (Lst Key . @)
1200
Lst (assoc Key (cddr Lst))
1202
(cdr (assoc Key (cadr Lst))) )
1204
############ lib/xmlrpc.l ############
1206
# (xmlrpc "localhost" 8080 "foo.bar" 'int 41 'string "abc" ..)
1207
(de xmlrpc (Host Port Meth . @)
1208
(let? Sock (connect Host Port)
1209
(let Xml (tmp 'xmlrpc)
1213
(list 'methodCall NIL
1214
(list 'methodName NIL Meth)
1220
(list 'value NIL (list (next) NIL (next))) ) ) ) ) ) ) )
1223
(prinl "POST /RPC2 HTTP/1.0^M")
1224
(prinl "Host: " Host "^M")
1225
(prinl "User-Agent: PicoLisp^M")
1226
(prinl "Content-Type: text/xml^M")
1227
(prinl "Accept-Charset: utf-8^M")
1228
(prinl "Content-Length: " (car (info Xml)) "^M")
1234
(let? L (and (xml?) (xml))
1235
(when (== 'methodResponse (car L))
1237
(car (body L 'params 'param 'value)) ) ) ) ) )
1238
(close Sock) ) ) ) )
1241
(or (format Str) (intern Str)) )
1243
(de xmlrpcValue (Lst)
1247
((i4 int) (format X))
1249
(double (format X *Scl))
1251
(when (== 'data (car X))
1254
(and (== 'value (car L)) (xmlrpcValue (caddr L))) )
1259
(when (== 'member (car L))
1261
(xmlrpcKey (caddr (assoc 'name L)))
1262
(xmlrpcValue (caddr (assoc 'value L))) ) ) )
1263
(cddr Lst) ) ) ) ) )
1265
############ lib/http.l ############
1268
(de client (Host Port How . Prg)
1269
(let? Sock (connect Host Port)
1273
(prinl "GET /" How " HTTP/1.0^M")
1274
(prinl "POST /" (car How) " HTTP/1.0^M")
1275
(prinl "Content-Length: " (size (cdr How)) "^M") )
1276
(prinl "User-Agent: PicoLisp^M")
1277
(prinl "Host: " Host "^M")
1278
(prinl "Accept-Charset: utf-8^M")
1280
(and (pair How) (prin (cdr @)))
1282
(in Sock (run Prg 1)) )
1285
############ Native Java ############
1287
(de javac (Cls Ext Impl . @)
1288
(let (J (pack "tmp/" Cls ".java") C (pack "tmp/" Cls ".class"))
1289
(call 'mkdir "-p" "tmp/")
1292
(prinl "import " (next) ";") )
1293
(prinl "public class " Cls
1294
(and Ext (pack " extends " @))
1295
(and Impl (pack " implements " (glue ", " Impl)))
1299
(call "javac" "-O" "-g:none" J)
1300
(push1 '*Bye (list 'call "rm" J C)) ) )
1305
############ lib/debug.l ############
1308
(de doc (Sym Browser)
1309
(let (L (chop Sym) C (car L))
1311
(member C '("*" "+"))
1316
((>= "z" C "a") (setq C (uppc C)))
1318
(call (or Browser (sys "BROWSER") 'w3m)
1321
(and (= `(char '/) (char (path "@"))) "//")
1323
C ".html#" Sym ) ) ) )
1325
(de more ("M" "Fun")
1328
((default "Fun" print) (pop '"M"))
1329
(println (type "M"))
1331
"Fun" (list '(X) (list 'pp 'X (lit "M")))
1332
"M" (mapcar car (filter pair (val "M"))) ) )
1335
(T (atom "M") (prinl))
1337
("Fun" (pop '"M")) ) ) )
1339
(de depth (Idx) #> (max . average)
1349
(recurse (cadr Idx) N)
1350
(recurse (cddr Idx) N) ) ) ) )
1351
(or (=0 C) (*/ D C)) ) ) )
1357
'(("X") (match S (chop "X")))
1361
(de who ("X" . "*Prg")
1362
(let (*Dbg NIL "Who" '("Who" @ @@ @@@))
1363
(make (mapc "who" (all))) ) )
1366
(unless (or (ext? "Y") (memq "Y" "Who"))
1368
(ifn (= `(char "+") (char "Y"))
1369
(and (pair (val "Y")) ("nest" @) (link "Y"))
1372
(and ("match" "Z") (link "Y"))
1373
(when ("nest" (cdr "Z"))
1374
(link (cons (car "Z") "Y")) ) ) )
1378
(and ("match" "Z") (link "Y"))
1379
(when ("nest" (car "Z"))
1380
(link (cons (cdr "Z") "Y")) ) ) )
1388
(let "Z" (setq "Y" (strip "Y"))
1390
(T (atom "Y") (and (sym? "Y") ("who" "Y")))
1391
(and (sym? (car "Y")) ("who" (car "Y")))
1392
(and (pair (car "Y")) ("nst1" @))
1393
(T (== "Z" (setq "Y" (cdr "Y")))) ) ) )
1396
(let "Z" (setq "Y" (strip "Y"))
1398
(T (atom "Y") ("match" "Y"))
1399
(T (or ("match" (car "Y")) ("nst2" (car "Y")))
1401
(T (== "Z" (setq "Y" (cdr "Y")))) ) ) )
1406
((str? "X") (and (str? "D") (= "X" "D")))
1407
((sym? "X") (== "X" "D"))
1408
(T (match "X" "D")) )
1411
(let *Dbg (up 2 *Dbg) (run "*Prg")) ) ) )
1419
(= `(char "+") (char "Y"))
1425
# Class dependencies
1434
(dep1 (+ 3 N) "X") )
1442
(= `(char "+") (char "X"))
1443
(memq "C" (type "X")) )
1446
(dep2 (+ 3 N) "X") ) ) )
1455
(set Lst (cons '! (car Lst))) ) )
1460
(if (and (pair (car L)) (flg? (caar L)))
1471
(map _dbg (cdr L)) ) )
1477
(map _dbg (cdr Lst)) ) )
1478
((job use let let? recur)
1479
(map _dbg (cdr Lst)) )
1486
(and (pair (car Lst)) (map _dbg (cdar Lst)))
1488
(T (map _dbg Lst)) )
1491
(de d () (let *Dbg NIL (dbg ^)))
1494
(ifn (traced? "X" C)
1497
(setq C (cdr "X") "X" (car "X")) )
1499
(dbg (if C (method "X" C) (getd "X")))
1500
(quit "Can't debug" "X") ) )
1509
(when (pair (car L))
1510
(when (== '! (caar L))
1516
(de u () (let *Dbg NIL (ubg ^)))
1521
(setq C (cdr "X") "X" (car "X")) )
1523
(ubg (if C (method "X" C) (getd "X")))
1524
(quit "Can't unbug" "X") ) ) )
1535
(== '$ (caadr "X")) ) )
1537
# Convert ((X Y) A B) --> ((X Y) ($ foo (X Y) A B))
1541
(setq C (cdr "X") "X" (car "X")) )
1543
(unless (traced? "X" C)
1544
(or (method "X" C) (quit "Can't trace" "X"))
1548
(list '$ (cons "X" C) (car @))
1550
(unless (traced? "X")
1551
(and (sym? (getd "X")) (quit "Can't trace" "X"))
1552
(and (num? (getd "X")) (expr "X"))
1556
(conc (list '$ "X") (getd "X")) ) ) ) )
1559
# Convert ((X Y) ($ foo (X Y) A B)) --> ((X Y) A B)
1563
(setq C (cdr "X") "X" (car "X")) )
1565
(when (traced? "X" C)
1568
(cdddr (cadr (method "X" C))) ) )
1570
(let X (set "X" (cddr (cadr (getd "X"))))
1574
(= 2 (length (car X)))
1583
what who can dep d e debug u unbug trace untrace )
1591
(= `(char "*") (char "X"))
1593
((= `(char "+") (char "X"))
1600
(cons (car "Y") "X") ) )
1603
(trace "X") ) ) ) ) ) )
1608
(make (while (args) (link "-C" (next))))
1609
'ps "-H" "-o" "pid,ppid,start,size,pcpu,wchan,cmd" ) )
1617
(format (*/ (- (usec) U) 1000) 3)
1620
############ lib/lint.l ############
1624
(push1 '*NoLint (cons X V))
1625
(or (memq X *NoLint) (push '*NoLint X)) ) )
1629
(memq S '(NIL ^ @ @@ @@@ This T))
1630
(member (char S) '(`(char '*) `(char '+))) ) )
1635
(member (char S) '(`(char '*) `(char '_))) ) )
1639
(car (setq S (split (chop S) ':)))
1648
((memq "X" "*L") (setq "*Use" (delq "X" "*Use")))
1649
((local? "X") (lint2 (val "X")))
1654
(member (cons "*X" "X") *NoLint)
1656
(push '"*Bnd" "X") ) ) ) ) )
1661
(; (lint1 (cadr "X")))
1663
(let F (fun? (cdr "X"))
1664
(if (or (and (pair F) (not (fin @))) (== '@ F))
1665
(use "*L" (lintFun (cdr "X")))
1666
(lint2 (cdr "X")) ) ) )
1668
(let "*X" (cadr "X")
1669
(lintFun (cddr "X")) ) )
1671
(let recurse (cdr "X")
1672
(lintFun recurse) ) )
1677
(while (num? (car "Y"))
1679
(while (and (car "Y") (sym? @))
1680
(lintVar (pop '"Y"))
1682
(mapc lint1 "Y") ) ) )
1685
(lintVar (cadr "X"))
1686
(mapc lint1 (cddr "X")) ) )
1689
(if (atom (cadr "X"))
1690
(lintVar (cadr "X"))
1691
(for (L (cadr "X") L (cddr L))
1693
(extract '((X F) (and F X))
1697
(lint1 (cadr L)) ) )
1698
(mapc lint1 (cddr "X")) ) )
1701
(if (atom (cadr "X"))
1702
(lintVar (cadr "X"))
1703
(mapc lintVar (cadr "X")) )
1704
(mapc lint1 (cddr "X")) ) )
1709
((atom "Y") # (for X (1 2 ..) ..)
1712
(lintLoop (cdddr "X")) )
1713
((atom (cdr "Y")) # (for (I . X) (1 2 ..) ..)
1717
(lintLoop (cdddr "X")) )
1718
((atom (car "Y")) # (for (X (1 2 ..) ..) ..)
1721
(mapc lint1 (cddr "Y"))
1722
(lintLoop (cddr "X")) )
1723
(T # (for ((I . L) (1 2 ..) ..) ..)
1724
(lintVar (caar "Y"))
1726
(lintVar (cdar "Y"))
1727
(mapc lint1 (cddr "Y"))
1728
(lintLoop (cddr "X")) ) ) ) ) )
1732
(mapc lint1 (cdr "X")) ) )
1735
(mapc lint1 "X") ) )
1737
(lintLoop (cdr "X")) )
1740
(lintLoop (cddr "X")) )
1742
(lint1 (last (cddr "X"))) )
1743
((dec inc pop push push1 queue fifo val idx accu)
1748
(_lintq '(T NIL .)) )
1755
(mapc lint2 (cdr "X")) )
1756
((memq (car "X") "*L")
1757
(setq "*Use" (delq (car "X") "*Use"))
1758
(mapc lint2 (cdr "X")) )
1759
((fun? (val (car "X")))
1761
(mapc lint1 (cdr "X"))
1762
(when (local? (car "X"))
1763
(lint2 (val (car "X"))) )
1764
(let "Y" (car (getd (pop '"X")))
1765
(while (and (pair "X") (pair "Y"))
1768
(if (or (== '@ "Y") (= "Prg" "Y") (= "*Prg" "Y"))
1776
(memq (car "X") *NoLint)
1777
(memq (car "X") "*Def")
1778
(push '"*Def" (car "X")) )
1779
(mapc lint1 (cdr "X")) ) ) ) ) ) ) )
1785
(and (memq X "*L") (setq "*Use" (delq X "*Use"))) )
1787
(lint2 (cdr X) (cons X Mark)) ) ) )
1791
((or (not (sym? X)) (memq X '(NIL ^ meth quote T)))
1796
(member (cons "*X" X) *NoLint)
1799
(push '"*L" X) ) ) )
1804
(not (member (cons "*X" X) *NoLint))
1805
(push '"*Dup" X) ) )
1807
(de lintLoop ("Lst")
1809
(if (and (pair "Y") (or (=T (car "Y")) (not (car "Y"))))
1810
(mapc lint1 (cdr "Y"))
1816
(lint1 (if Flg (strip X) X)) )
1821
(let "A" (and (pair "Lst") (car "Lst"))
1823
(lintDup (car "A") (cdr "A"))
1824
(lintVar (pop '"A") T) )
1827
(mapc lint1 (cdr "Lst")) ) )
1830
(let ("*L" NIL "*Var" NIL "*Dup" NIL "*Def" NIL "*Bnd" NIL "*Use" NIL)
1832
(setq "C" (cdr "X") "X" (car "X")) )
1835
(let "*X" (cons "X" "C")
1836
(lintFun (method "X" "C")) ) )
1837
((pair (val "X")) # Function
1839
(lintFun (val "X")) ) )
1840
((info "X") # File name
1842
(in "X" (while (read) (lint1 @))) ) )
1843
(T (quit "Can't lint" "X")) )
1844
(when (or "*Var" "*Dup" "*Def" "*Bnd" "*Use")
1847
(and "*Var" (link (cons 'var "*Var")))
1848
# Duplicate parameters
1849
(and "*Dup" (link (cons 'dup "*Dup")))
1850
# Undefined functions
1851
(and "*Def" (link (cons 'def "*Def")))
1853
(and "*Bnd" (<> `(char '_) (char "X")) (link (cons 'bnd "*Bnd")))
1855
(and "*Use" (link (cons 'use "*Use"))) ) ) ) )
1862
((= `(char "+") (char "X"))
1867
(lint (car "Y") "X")
1868
(link (cons (cons (car "Y") "X") @)) ) ) )
1869
((and (not (global? "X")) (pair (getd "X")) (lint "X"))
1870
(link (cons "X" @)) ) ) )
1872
(and (lint (next)) (link (cons (arg) @))) ) ) ) )