-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdebug2.lisp
274 lines (253 loc) · 9.66 KB
/
debug2.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
(FILEHEADER DEBUG2)
(PRINT '(DEBUG PACKAGE 2))
(PRINT '(VERSION 0))
(DEFINEQ
(ADDINNAME
[LAMBDA (F)
(COND ((NLISTP F) F)
((EQ (CADR FN) 'IN)
(PROG (NEW (FN (CAR F)) (IFN (CADDR F)) ND)
(OR (GETD FN) (RETURN))
(SETQ NEW (INNAME FN IFN))
(COND ((MEMB FN (GETPROP IFN 'NAMESCHANGED))
(RETURN NEW)))
(SETQ ND (SUBST NEW FN (GETD IFN)))
(AND (EQUAL ND (GETD IFN)) (RETURN))
(OR (GETPROP IFN 'VIRGINFN)
(PUTPROP IFN 'VIRGINFN (GETD IFN)))
(PUTPROP IFN 'FNCELL ND)
(ADDPROP IFN 'NAMESCHANGED FN)
(PUTPROP NEW 'FNCELL (GETD FN))
(PUTPROP NEW 'ALIAS (CONS IFN FN))
(RETURN NEW])
(ADVISE
(LAMBDA (FN . L)
(PROG (WHEN WHAT
(BR (UNBREAK1 FN))
[NEW (GETD (SETQ FN (ADDINNAME FN]
(TMP (GETPROP FN 'ADVISED)))
(OR NEW (RETURN NIL))
(OR L (RETURN NIL))
(OR (GETPROP FN 'VIRGINFN)
(PUTPROP FN 'VIRGINFN NEW))
[OR TMP (PUTPROP FN 'ADVISED (SETQ TMP (CONS]
[COND ((CAR TMP))
(T (RPLACA TMP NEW)
(SETQ NEW (ADVISE-BODY NEW]
(NCONC1 TMP L)
(SETQ WHAT (CAR (LAST L)))
(SETQ WHEN (COND ((CDR L) (CAR L)) ('BEFORE)))
(PUTPROP FN 'FNCELL NEW)
(SETQ NEW (CADDR NEW))
(SETQ TMP
(SELECTQ WHEN
(BIND (CADR NEW))
(AFTER (CADDR NEW) (CAR (NTH NEW 5)))
(CADDR NEW)))
(AND WHAT (NCONC1 TMP WHAT))
(SETQ ADVISEDFNS (ADDLIST FN ADVISEDFNS))
(RETURN FN))))
(ADVISE-BODY
(LAMBDA (FN)
(PROG ((BDY (LAMBDAEQV FN)) FORM)
(SETQ FORM (CDDR BDY))
[RPLACA FORM
(SUBST (CAR FORM)
'FORM
'(PROG (!VALUE)
(PROGN)
(SETQ !VALUE FORM)
(PROGN)
(RETURN !VALUE]
(RETURN BDY))))
(BREAK
[NLAMBDA L (MAPCAR L '(LAMBDA (FN) (BREAK0 FN T])
(BREAK-BODY
(LAMBDA (NEW)
(PROG ((BDY (LAMBDAEQV NEW)))
(RPLACA (CDDR BDY)
(LIST 'BREAK1 (CADDR BDY) BRKWHEN FN BRKCOMS))
(RETURN BDY))))
(BREAK0
(LAMBDA (FN BRKWHEN BRKCOMS)
(SETQ FN (ADDINNAME FN))
(PROG ((NEW (GETD FN)) (TMP (GETPROP FN 'BROKEN)))
(OR NEW (RETURN NIL))
(OR (GETPROP FN 'VIRGINFN)
(PUTPROP FN 'VIRGINFN NEW))
(COND ((NULL TMP)
(PUTPROP FN 'BROKEN (LIST NEW BRKWHEN BRKCOMS)))
((NULL (CAR TMP)) (RPLACA TMP NEW))
(T (RETURN NIL)))
(SETQ NEW (BREAK-BODY NEW))
(PUTPROP FN 'FNCELL NEW)
(SETQ BROKENFNS (ADDLIST FN BROKENFNS))
(RETURN FN))))
(INNAME
(LAMBDA (F IN) (PACK (LIST F '-IN- IN))))
(LAMBDAEQV
[LAMBDA (NEW)
(SELECTQ (CAR NEW)
(FUNARG (LIST (CAR NEW)
(LAMBDAEQV (CADR NEW))
(CADDR NEW)))
[(LAMBDA NLAMBDA)
(LIST (CAR NEW)
(CADR NEW)
(COND ((CDDDR NEW)
(CONS 'PROGN (CDDR NEW)))
((CADDR NEW]
(LIST (COND ((EQ (CAR NEW) 'SUBR) 'LAMBDA)
(T 'NLAMBDA))
'ARGS
(LIST 'APPLY (LIST 'QUOTE NEW) 'ARGS])
(PUTD
(LAMBDA (FN DEF)
(COND ((GETD FN) (SAVEDEF FN) (PRIN2L-SP FN 'REDEFINED)))
(REMPROP FN 'TRACED)
(REMPROP FN 'VIRGINFN)
[COND ((GETPROP FN 'ADVISED)
(RPLACA (GETPROP FN 'ADVISED]
[COND ((GETPROP FN 'BROKEN)
(RPLACA (GETPROP FN 'BROKEN]
(PUTPROP FN 'FNCELL DEF)
(SET CURFILEFNS (ADDLIST FN (EVAL CURFILEFNS)))
DEF))
(READVISE
[NLAMBDA L
(MAPCAR (OR L ADVISEDFNS)
'(LAMBDA (FN)
(SETQ FN (THEINNAME FN))
(PROG ((OLD (GETPROP FN 'ADVISED)))
(COND ((AND OLD (NULL (CAR OLD)))
(PUTPROP FN 'ADVISED)
[MAPC
(CDR OLD)
'(LAMBDA
(ADV)
(APPLY 'ADVISED
(CONS FN ADV]
(RETURN FN))
(T (RETURN NIL])
(REBREAK
(NLAMBDA L (MAPCAR (OR L BROKENFNS) 'REBREAK1)))
(REBREAK1
[LAMBDA (FN)
(SETQ FN (ADDINNAME FN))
(PROG ((OLD (GETPROP FN 'BROKEN)))
(COND ((AND OLD (NULL (CAR OLD)))
(BREAK0 FN (CADR OLD) (CADDR OLD))
(RETURN FN))
(T (RETURN NIL])
(REMINNAME
[LAMBDA (FN TEMP)
(COND ((NLISTP FN)
[COND ((SETQ ALIAS (GETPROP FN 'ALIAS))
[PUTPROP
(CAR ALIAS)
'FNCELL
(SUBST (CDR ALIAS)
(INNAME (CDR ALIAS) (CAR ALIAS))
(GETD (CAR ALIAS]
(PUTPROP
(CAR ALIAS)
'NAMESCHANGED
(REMOVE
(CDR ALIAS)
(GETPROP (CAR ALIAS) 'NAMESCHANGED]
FN)
((EQ (CADR FN) 'IN)
(REMINNAME (INNAME (CAR FN) (CADDR FN])
(THEINNAME
[LAMBDA (X)
(COND ((NLISTP X) X)
((EQ (CADR X) 'IN) (INNAME (CAR X) (CADDR X])
(TRACE
[NLAMBDA L
(MAPCAR L
'(LAMBDA (FN IFN)
(SETQ IFN (THEINNAME FN))
(COND ((GETPROP IFN 'TRACED) NIL)
(T (OR (ADVISE FN
(LIST 'TRACE-PRINT
(KWOTE IFN)
T))
(RETURN))
(PUTPROP IFN 'TRACED T)
(ADVISE FN 'BIND
'(*TRACEN (ADD1 *TRACEN)))
(ADVISE FN 'AFTER
(LIST 'TRACE-PRINT (KWOTE IFN])
(TRACE-PRINT
[LAMBDA (FN FLG)
(AND (GREATERP *TRACEN 15) (SETQ *TRACEN -1))
(RPTQ *TRACEN (PROGN (PRIN1 'I) (SPACES 2)))
(PRINTLEVEL
(PRINTLEVEL *PRINTLEVEL)
(COND [FLG (PRIN1 "--]")
(SPACES 1)
(PRIN2 FN)
(SPACES 1)
(PRINT (PRVARS (*ARGLIST FN) (BINDENV FN]
(T (PRIN1 "[--")
(SPACES 1)
(PRIN2 FN)
(SPACES 1)
(PRINT !VALUE])
(UNADVISE
(NLAMBDA L (MAPCAR (OR L ADVISEDFNS) 'UNADVISE1)))
(UNADVISE1
(LAMBDA (FN)
(SETQ FN (THEINNAME FN))
(PROG ((OLD (GETPROP FN 'ADVISED)) (BR (UNBREAK1 FN)))
(OR OLD (RETURN NIL))
(OR (CAR OLD) (RETURN NIL))
(PUTPROP FN 'FNCELL (CAR OLD))
(RPLACA OLD NIL)
(COND (BR (REBREAK1 FN)) ((REMINNAME FN)))
(RETURN FN))))
(UNBREAK
(NLAMBDA L (MAPCAR (OR L BROKENFNS) 'UNBREAK1)))
(UNBREAK1
(LAMBDA (FN)
(SETQ FN (THEINNAME FN))
(PROG ((OLD (GETPROP FN 'BROKEN)))
(OR OLD (RETURN NIL))
(OR (CAR OLD) (RETURN NIL))
(PUTPROP FN 'FNCELL (CAR OLD))
(RPLACA OLD NIL)
(REMINNAME FN)
(RETURN FN))))
(UNTRACE
[NLAMBDA L
(MAPCAR [OR L
(REMOVE NIL
(MAPCAR ADVISEDFNS
'(LAMBDA
(X)
(AND (GETPROP X 'TRACED) X]
'(LAMBDA (FN)
(REMPROP FN 'TRACED)
(UNADVISE1 FN])
)
(PRINT 'DEBUG2FNS)
(RPAQQ DEBUG2FNS
(ADDINNAME ADVISE ADVISE-BODY BREAK BREAK-BODY BREAK0 INNAME LAMBDAEQV
PUTD READVISE REBREAK REBREAK1 REMINNAME THEINNAME TRACE TRACE-PRINT
UNADVISE UNADVISE1 UNBREAK UNBREAK1 UNTRACE))
(RPAQQ DEBUG2COMS (DEBUG PACKAGE 2))
(RPAQ DEBUG2GENNR 0)
(PRINT 'DEBUG2VARS)
[RPAQQ DEBUG2VARS
((P (RPAQ BROKENFNS) (RPAQ *BRKFLG))
(P (RPAQ ADVISEDFNS)
(RPAQ !ADVISEFLG)
(RPAQ *TRACEN -1)
(RPAQ *PRINTLEVEL 3]
(RPAQ BROKENFNS)
(RPAQ *BRKFLG)
(RPAQ ADVISEDFNS)
(RPAQ !ADVISEFLG)
(RPAQ *TRACEN -1)
(RPAQ *PRINTLEVEL 3)
STOP