~ubuntu-branches/ubuntu/quantal/gclcvs/quantal

« back to all changes in this revision

Viewing changes to lsp/gcl_top.lsp

  • Committer: Bazaar Package Importer
  • Author(s): Camm Maguire
  • Date: 2004-06-24 15:13:46 UTC
  • Revision ID: james.westby@ubuntu.com-20040624151346-xh0xaaktyyp7aorc
Tags: 2.7.0-26
C_GC_OFFSET is 2 on m68k-linux

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
;; Copyright (C) 1994 M. Hagiya, W. Schelter, T. Yuasa
 
2
 
 
3
;; This file is part of GNU Common Lisp, herein referred to as GCL
 
4
;;
 
5
;; GCL is free software; you can redistribute it and/or modify it under
 
6
;;  the terms of the GNU LIBRARY GENERAL PUBLIC LICENSE as published by
 
7
;; the Free Software Foundation; either version 2, or (at your option)
 
8
;; any later version.
 
9
;; 
 
10
;; GCL is distributed in the hope that it will be useful, but WITHOUT
 
11
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
12
;; FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public 
 
13
;; License for more details.
 
14
;; 
 
15
;; You should have received a copy of the GNU Library General Public License 
 
16
;; along with GCL; see the file COPYING.  If not, write to the Free Software
 
17
;; Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 
18
 
 
19
 
 
20
;;;;  top.lsp
 
21
;;;;
 
22
;;;;  Top-level loop, break loop, and error handlers
 
23
;;;;
 
24
;;;;  Revised on July 11, by Carl Hoffman.
 
25
 
 
26
 
 
27
(in-package "LISP")
 
28
;(export 'lisp)
 
29
(export '(+ ++ +++ - * ** *** / // ///))
 
30
(export '(break warn))
 
31
(export '*break-on-warnings*)
 
32
(export '*break-enable*)
 
33
 
 
34
(in-package 'system)
 
35
 
 
36
(export '*break-readtable*)
 
37
(export '(loc *debug-print-level*))
 
38
 
 
39
(export '(vs ihs-vs ihs-fun frs-vs frs-bds frs-ihs bds-var bds-val super-go))
 
40
 
 
41
(eval-when (compile) (proclaim '(optimize (safety 2) (space 3))
 
42
                               )
 
43
           (defvar *command-args* nil)
 
44
           )
 
45
 
 
46
(defvar +)
 
47
(defvar ++)
 
48
(defvar +++)
 
49
(defvar -)
 
50
(defvar *)
 
51
(defvar **)
 
52
(defvar ***)
 
53
(defvar /)
 
54
(defvar //)
 
55
(defvar ///)
 
56
 
 
57
 
 
58
;; setup file search and autoload
 
59
 
 
60
(defvar *fixed-load-path* nil)
 
61
(defvar *load-path* nil)
 
62
(defvar *load-types* '(".o" ".lsp" ".lisp"))
 
63
 
 
64
(defvar *lisp-initialized* nil)
 
65
(defvar *quit-tag* (cons nil nil))
 
66
(defvar *quit-tags* nil)
 
67
(defvar *break-level* '())
 
68
(defvar *break-env* nil)
 
69
(defvar *ihs-base* 1)
 
70
(defvar *ihs-top* 1)
 
71
(defvar *current-ihs* 1)
 
72
(defvar *frs-base* 0)
 
73
(defvar *frs-top* 0)
 
74
(defvar *break-enable* t)
 
75
(defvar *break-message* "")
 
76
 
 
77
(defvar *break-on-warnings* nil)
 
78
 
 
79
(defvar *break-readtable* nil)
 
80
 
 
81
(defvar *top-level-hook* nil)
 
82
 
 
83
 
 
84
(defvar *top-eof* (cons nil nil))
 
85
(defvar *no-prompt* nil)
 
86
 
 
87
(defun top-level ()
 
88
  (let ((+ nil) (++ nil) (+++ nil)
 
89
        (- nil) 
 
90
        (* nil) (** nil) (*** nil)
 
91
        (/ nil) (// nil) (/// nil)
 
92
        )
 
93
    (setq *lisp-initialized* t)
 
94
    (catch *quit-tag*
 
95
      (progn 
 
96
        (cond
 
97
         (*multiply-stacks* (setq *multiply-stacks* nil))
 
98
         ((probe-file "init.lsp") (load "init.lsp")))
 
99
        (let (*load-verbose*) (process-some-args *command-args*))
 
100
        )
 
101
      (and (functionp *top-level-hook*)(funcall   *top-level-hook*)))
 
102
 
 
103
    (loop
 
104
      (setq +++ ++ ++ + + -)
 
105
      (if *no-prompt* (setq *no-prompt* nil)
 
106
        (format t "~%~a>"
 
107
                (if (eq *package* (find-package 'user)) ""
 
108
                  (package-name *package*))))
 
109
      (reset-stack-limits)
 
110
      ;; have to exit and re-enter to multiply stacks
 
111
      (cond (*multiply-stacks* (Return-from top-level)))
 
112
      (when (catch *quit-tag*
 
113
              (setq - (locally (declare (notinline read))
 
114
                               (read *standard-input* nil *top-eof*)))
 
115
              (when (eq - *top-eof*) (bye))
 
116
              (let ((values (multiple-value-list
 
117
                             (locally (declare (notinline eval)) (eval -)))))
 
118
                (setq /// // // / / values *** ** ** * * (car /))
 
119
                (fresh-line)
 
120
                (dolist (val /)
 
121
                  (locally (declare (notinline prin1)) (prin1 val))
 
122
                  (terpri))
 
123
                nil))
 
124
        (setq *evalhook* nil *applyhook* nil)
 
125
        (terpri *error-output*)
 
126
        (break-current)))))
 
127
 
 
128
(defun process-some-args (args)
 
129
  (loop
 
130
   (let ((x (car args))
 
131
         y)
 
132
     (cond ((equal x "-load")
 
133
            (load (second args)))
 
134
           ((equal x "-eval")
 
135
            (eval (read-from-string (second args))))
 
136
           (t (setq y t)))
 
137
     (or y (setq args (cdr args)))
 
138
     (setq args (cdr args)))
 
139
   (or args (return nil))))  
 
140
  
 
141
 
 
142
 
 
143
 
 
144
 
 
145
(defun dbl-read (&optional (stream *standard-input*) (eof-error-p t)
 
146
                           (eof-value nil)  &aux tem  ch)
 
147
  (tagbody
 
148
   top
 
149
   (setq ch (read-char stream eof-error-p eof-value))
 
150
   (cond ((eql ch #\newline) (go top))
 
151
         ((eq ch eof-value) (return-from dbl-read eof-value)))
 
152
   (unread-char ch stream))
 
153
 
 
154
  (cond ((eql #\: ch)
 
155
         (setq tem
 
156
               (string-concatenate
 
157
                "("
 
158
                (read-line stream eof-error-p eof-value)")"))
 
159
         (read  (make-string-input-stream tem)
 
160
                                         eof-error-p eof-value))
 
161
        (t (read stream eof-error-p eof-value))))
 
162
 
 
163
 
 
164
(defun break-level (at &optional env)
 
165
  (let* ((*break-message* (if (stringp at) at *break-message*))
 
166
         (*quit-tags* (cons (cons *break-level* *quit-tag*) *quit-tags*))
 
167
         (*quit-tag* (cons nil nil))
 
168
         (*break-level* (if (not at) *break-level* (cons t *break-level*)))
 
169
         (*ihs-base* (1+ *ihs-top*))
 
170
         (*ihs-top* (1- (ihs-top)))
 
171
         (*current-ihs* *ihs-top*)
 
172
         (*frs-base* (or (sch-frs-base *frs-top* *ihs-base*) (1+ (frs-top))))
 
173
         (*frs-top* (frs-top))
 
174
         (*break-env* nil)
 
175
         (be *break-enable*)
 
176
         (*break-enable*
 
177
          (progn 
 
178
            (if (stringp at) nil be)))
 
179
                                        ;(*standard-input* *terminal-io*)
 
180
         (*readtable* (or *break-readtable* *readtable*))
 
181
         (*read-suppress* nil)
 
182
         (+ +) (++ ++) (+++ +++)
 
183
         (- -)
 
184
         (* *) (** **) (*** ***)
 
185
         (/ /) (// //) (/// ///)
 
186
         )
 
187
                                        ; (terpri *error-output*)
 
188
    (unless (or be (not (stringp at)))
 
189
      (simple-backtrace)
 
190
      (break-quit (length (cdr *break-level*))))
 
191
    (catch-fatal 1)
 
192
    (setq *interrupt-enable* t)
 
193
    (cond ((stringp at) (set-current)(terpri *error-output*)
 
194
           (setq *no-prompt* nil)
 
195
           )
 
196
          (t (set-back at env)))
 
197
      (loop 
 
198
       (setq +++ ++ ++ + + -)
 
199
       (cond (*no-prompt* (setq *no-prompt* nil))
 
200
             (t
 
201
              (format *debug-io* "~&~a~a>~{~*>~}"
 
202
                      (if (stringp at) "" "dbl:")
 
203
                      (if (eq *package* (find-package 'user)) ""
 
204
                        (package-name *package*))
 
205
                      *break-level*)))
 
206
       (force-output *error-output*)
 
207
       (when
 
208
        (catch 'step-continue
 
209
        (catch *quit-tag*
 
210
          (setq - (locally (declare (notinline read))
 
211
                           (dbl-read *debug-io* nil *top-eof*)))
 
212
          (when (eq - *top-eof*) (bye -1))
 
213
          (let* ( break-command
 
214
                 (values
 
215
                  (multiple-value-list
 
216
                  (LOCALLY (declare (notinline break-call evalhook))
 
217
                           (if (keywordp -)(setq - (cons - nil)))
 
218
                           (cond ((and (consp -) (keywordp (car -)))
 
219
                                  (setq break-command t)
 
220
                                  (break-call (car -) (cdr -) 'si::break-command))
 
221
                                 (t (evalhook - nil nil *break-env*)))))))
 
222
            (and break-command (eq (car values) :resume )(return))
 
223
            (setq /// // // / / values *** ** ** * * (car /))
 
224
            (fresh-line *debug-io*)
 
225
            (dolist (val /)
 
226
                    (locally (declare (notinline prin1)) (prin1 val *debug-io*))
 
227
                    (terpri *debug-io*)))
 
228
          nil))
 
229
        (terpri *debug-io*)
 
230
        (break-current))))))
 
231
 
 
232
(defvar *debug-print-level* 3)
 
233
 
 
234
(defun warn (format-string &rest args)
 
235
  (let ((*print-level* 4)
 
236
        (*print-length* 4)
 
237
        (*print-case* :upcase))
 
238
    (cond (*break-on-warnings*
 
239
           (apply #'break format-string args))
 
240
          (t (format *error-output* "~&Warning: ")
 
241
             (let ((*indent-formatted-output* t))
 
242
               (apply #'format *error-output* format-string args))
 
243
             nil))))
 
244
 
 
245
(defun universal-error-handler
 
246
  (error-name correctable function-name
 
247
   continue-format-string error-format-string
 
248
   &rest args &aux message)
 
249
  (declare (ignore error-name))
 
250
  (let ((*print-pretty* nil)
 
251
        (*print-level* *debug-print-level*)
 
252
        (*print-length* *debug-print-level*)
 
253
        (*print-case* :upcase))
 
254
       (terpri *error-output*)
 
255
       (cond ((and correctable *break-enable*)
 
256
              (format *error-output* "~&Correctable error: ")
 
257
              (let ((*indent-formatted-output* t))
 
258
                (apply 'format *error-output* error-format-string args))
 
259
              (terpri *error-output*)
 
260
              (setq message (apply 'format nil error-format-string args))
 
261
              (if function-name
 
262
                  (format *error-output*
 
263
                          "Signalled by ~:@(~S~).~%" function-name)
 
264
                  (format *error-output*
 
265
                          "Signalled by an anonymous function.~%"))
 
266
              (format *error-output* "~&If continued: ")
 
267
              (let ((*indent-formatted-output* t))
 
268
                (format *error-output* "~?~&" continue-format-string args))
 
269
              )
 
270
             (t
 
271
              (format *error-output* "~&Error: ")
 
272
              (let ((*indent-formatted-output* t))
 
273
                (apply 'format *error-output* error-format-string args))
 
274
              (terpri *error-output*)
 
275
              (if (> (length *link-array*) 0)
 
276
                  (format *error-output* "Fast links are on: do (si::use-fast-links nil) for debugging~%"))
 
277
              (setq message (apply 'format nil error-format-string args))
 
278
              (if function-name
 
279
                  (format *error-output*
 
280
                          "Error signalled by ~:@(~S~).~%" function-name)
 
281
                  (format *error-output*
 
282
                          "Error signalled by an anonymous function.~%")))))
 
283
  (force-output *error-output*)
 
284
  (break-level message)
 
285
  (unless correctable (throw *quit-tag* *quit-tag*)))
 
286
 
 
287
(defun break (&optional format-string &rest args &aux message)
 
288
  (let ((*print-pretty* nil)
 
289
        (*print-level* 4)
 
290
        (*print-length* 4)
 
291
        (*print-case* :upcase))
 
292
       (terpri *error-output*)
 
293
    (cond (format-string
 
294
           (format *error-output* "~&Break: ")
 
295
           (let ((*indent-formatted-output* t))
 
296
             (apply 'format *error-output* format-string args))
 
297
           (terpri *error-output*)
 
298
           (setq message (apply 'format nil format-string args)))
 
299
          (t (format *error-output* "~&Break.~%")
 
300
             (setq message ""))))
 
301
  (let ((*break-enable* t)) (break-level message))
 
302
  nil)
 
303
 
 
304
(defun terminal-interrupt (correctablep)
 
305
  (let ((*break-enable* t))
 
306
    (if correctablep
 
307
        (cerror "Type :r to resume execution, or :q to quit to top level."
 
308
                "Console interrupt.")
 
309
        (error "Console interrupt -- cannot continue."))))
 
310
 
 
311
 
 
312
(defun break-call (key args &optional (prop 'si::break-command) &aux fun)
 
313
  (setq fun (complete-prop key 'keyword prop))
 
314
  (or fun (return-from break-call nil))
 
315
  (setq fun (get fun prop))
 
316
  (cond (fun
 
317
         (setq args (cons fun args))
 
318
         (or (symbolp fun) (setq args (cons 'funcall args)))
 
319
         (evalhook args nil nil *break-env*)
 
320
         )
 
321
        (t (format *debug-io* "~&~S is undefined break command.~%" key))))
 
322
 
 
323
(defun break-quit (&optional (level 0)
 
324
                   &aux (current-level (length *break-level*)))
 
325
  (when (and (>= level 0) (< level current-level))
 
326
    (let ((x (nth (- current-level level 1) *quit-tags*)))
 
327
      (throw (cdr x) (cdr x))))
 
328
  (break-current))
 
329
 
 
330
(defun break-previous (&optional (offset 1))
 
331
  (do ((i (1- *current-ihs*) (1- i)))
 
332
      ((or (< i *ihs-base*) (<= offset 0))
 
333
       (set-env)
 
334
       (break-current))
 
335
    (when (ihs-visible i)
 
336
      (setq *current-ihs* i)
 
337
      (setq offset (1- offset)))))
 
338
 
 
339
(defun set-current ()
 
340
  (do ((i *current-ihs* (1- i)))
 
341
      ((or (ihs-visible i) (<= i *ihs-base*))
 
342
       (setq *current-ihs* i)
 
343
       (set-env)
 
344
       (format *debug-io* "Broken at ~:@(~S~).~:[  Type :H for Help.~;~]"
 
345
               (ihs-fname *current-ihs*)
 
346
               (cdr *break-level*)))))
 
347
 
 
348
(defun break-next (&optional (offset 1))
 
349
  (do ((i *current-ihs* (1+ i)))
 
350
      ((or (> i *ihs-top*) (< offset 0))
 
351
       (set-env)
 
352
       (break-current))
 
353
    (when (ihs-visible i)
 
354
      (setq *current-ihs* i)
 
355
      (setq offset (1- offset)))))
 
356
 
 
357
(defun break-go (ihs-index)
 
358
  (setq *current-ihs* (min (max ihs-index *ihs-base*) *ihs-top*))
 
359
  (if (ihs-visible *current-ihs*)
 
360
      (progn (set-env) (break-current))
 
361
      (break-previous)))
 
362
 
 
363
(defun break-message ()
 
364
  (princ *break-message* *debug-io*)
 
365
  (terpri *debug-io*)
 
366
  (values))
 
367
 
 
368
(defun describe-environment (&optional (env *break-env*) (str *debug-io*))
 
369
  (or (eql (length env) 3) (error "bad env"))
 
370
    (let ((fmt "~a~#[none~;~S~;~S and ~S~
 
371
         ~:;~@{~#[~;and ~]~S~^, ~}~].~%"))
 
372
      (apply 'format str fmt "Local variables: "
 
373
             (mapcar #'car (car *break-env*)))
 
374
      (apply 'format str fmt "Local functions: "
 
375
             (mapcar #'car (cadr *break-env*)))
 
376
      (apply 'format str fmt "Local blocks: "
 
377
             (mapcan #'(lambda (x) (when (eq (cadr x) 'block) (list (car x))))
 
378
                 (caddr *break-env*)))
 
379
      (apply 'format str fmt "Local tags: "
 
380
             (mapcan #'(lambda (x) (when (eq (cadr x) 'tag) (list (car x))))
 
381
                 (caddr *break-env*)))))
 
382
 
 
383
(defun break-vs (&optional (x (ihs-vs *ihs-base*)) (y (ihs-vs *ihs-top*)))
 
384
  (setq x (max x (ihs-vs *ihs-base*)))
 
385
  (setq y (min y (1- (ihs-vs (1+ *ihs-top*)))))
 
386
  (do ((ii *ihs-base* (1+ ii)))
 
387
      ((or (>= ii *ihs-top*) (>= (ihs-vs ii) x))
 
388
       (do ((vi x (1+ vi)))
 
389
           ((> vi y) (values))
 
390
         (do ()
 
391
             ((> (ihs-vs ii) vi))
 
392
           (when (ihs-visible ii) (print-ihs ii))
 
393
           (incf ii))
 
394
         (format *debug-io* "~&VS[~d]: ~s" vi (vs vi))))))
 
395
 
 
396
(defun break-local (&optional (n 0) &aux (x (+ (ihs-vs *current-ihs*) n)))
 
397
  (break-vs x x))
 
398
 
 
399
(defun break-bds (&rest vars &aux (fi *frs-base*))
 
400
  (do ((bi (1+ (frs-bds (1- *frs-base*))) (1+ bi))
 
401
       (last (frs-bds (1+ *frs-top*))))
 
402
      ((> bi last) (values))
 
403
    (when (or (null vars) (member (bds-var bi) vars))
 
404
      (do ()
 
405
          ((or (> fi *frs-top*) (> (frs-bds fi) bi)))
 
406
        (print-frs fi)
 
407
        (incf fi))
 
408
      (format *debug-io* "~&BDS[~d]: ~s = ~s"
 
409
              bi (bds-var bi) (bds-val bi)))))
 
410
 
 
411
(defun simple-backtrace ()
 
412
  (princ "Backtrace: " *debug-io*)
 
413
  (do* ((i *ihs-base* (1+ i))
 
414
        (b nil t))
 
415
       ((> i *ihs-top*) (terpri *debug-io*) (values))
 
416
    (when (ihs-visible i)
 
417
      (when b (princ " > " *debug-io*))
 
418
      (write (ihs-fname i) :stream *debug-io* :escape t
 
419
             :case (if (= i *current-ihs*) :upcase :downcase)))))
 
420
 
 
421
(defun ihs-backtrace (&optional (from *ihs-base*) (to *ihs-top*))
 
422
  (setq from (max from *ihs-base*))
 
423
  (setq to (min to *ihs-top*))
 
424
  (do* ((i from (1+ i))
 
425
        (j (or (sch-frs-base *frs-base* from) (1+ *frs-top*))))
 
426
       ((> i to) (values))
 
427
    (when (ihs-visible i) (print-ihs i))
 
428
    (do () ((or (> j *frs-top*) (> (frs-ihs j) i)))
 
429
      (print-frs j)
 
430
      (incf j))))
 
431
 
 
432
(defun print-ihs (i &aux (*print-level* 2) (*print-length* 4))
 
433
  (format t "~&~:[  ~;@ ~]IHS[~d]: ~s ---> VS[~d]"
 
434
          (= i *current-ihs*)
 
435
          i
 
436
          (let ((fun (ihs-fun i)))
 
437
            (cond ((or (symbolp fun) (compiled-function-p fun)) fun)
 
438
                  ((consp fun)
 
439
                   (case (car fun)
 
440
                     (lambda fun)
 
441
                     ((lambda-block lambda-block-expanded) (cdr fun))
 
442
                     (lambda-closure (cons 'lambda (cddddr fun)))
 
443
                     (lambda-block-closure (cddddr fun))
 
444
                     (t (cond
 
445
                         ((and (symbolp (car fun))
 
446
                               (or (special-form-p(car fun))
 
447
                                   (fboundp (car fun))))
 
448
                          (car fun))
 
449
                         (t '(:zombi))))))
 
450
                  (t (print fun)
 
451
                   :zombi)))
 
452
          (ihs-vs i)))
 
453
 
 
454
(defun print-frs (i)
 
455
  (format *debug-io* "~&    FRS[~d]: ~s ---> IHS[~d],VS[~d],BDS[~d]"
 
456
          i (frs-kind i) (frs-ihs i) (frs-vs i) (frs-bds i)))
 
457
 
 
458
(defun frs-kind (i &aux x)
 
459
  (case (frs-class i)
 
460
    (:catch
 
461
     (if (spicep (frs-tag i))
 
462
         (or (and (setq x (member (frs-tag i) (vs (+ (frs-vs i) 2))
 
463
                                  :key #'caddr :test #'eq))
 
464
                  (if (eq (cadar x) 'block)
 
465
                      `(block ,(caar x) ***)
 
466
                      `(tagbody ,@(reverse (mapcar #'car
 
467
                                             (remove (frs-tag i) x
 
468
                                                     :test-not #'eq
 
469
                                                     :key #'caddr)))
 
470
                                ***)))
 
471
             `(block/tagbody ,(frs-tag i)))
 
472
         `(catch ',(frs-tag i) ***)))
 
473
    (:protect '(unwind-protect ***))
 
474
    (t `(system-internal-catcher ,(frs-tag i)))))
 
475
 
 
476
(defun break-current ()
 
477
  (if *break-level*
 
478
      (format *debug-io* "Broken at ~:@(~S~)." (ihs-fname *current-ihs*))
 
479
      (format *debug-io* "~&Top level."))
 
480
  (values))
 
481
 
 
482
 
 
483
 
 
484
(defvar *break-hidden-packages* nil)
 
485
 
 
486
(defun ihs-visible (i &aux (tem (ihs-fname i)))
 
487
  (and tem (not (member tem *break-hidden-packages*))))
 
488
 
 
489
 
 
490
(defun ihs-fname (ihs-index)
 
491
  (let ((fun (ihs-fun ihs-index)))
 
492
    (cond ((symbolp fun) fun)
 
493
          ((consp fun)
 
494
           (case (car fun)
 
495
             (lambda 'lambda)
 
496
             ((lambda-block lambda-block-expanded) (cadr fun))
 
497
             (lambda-block-closure (nth 4 fun))
 
498
             (lambda-closure 'lambda-closure)
 
499
             (t (if (and (symbolp (car fun))
 
500
                         (or (special-form-p (car fun))
 
501
                             (fboundp (car fun))))
 
502
                    (car fun) :zombi)
 
503
                    )))
 
504
          ((compiled-function-p fun)
 
505
           (compiled-function-name fun))
 
506
          (t :zombi))))
 
507
 
 
508
(defun ihs-not-interpreted-env (ihs-index)
 
509
  (let ((fun (ihs-fun ihs-index)))
 
510
    (cond ((and (consp fun)
 
511
                (> ihs-index 3)
 
512
                ;(<= (ihs-vs ihs-index) (ihs-vs (- ihs-index 1)))
 
513
                )
 
514
           nil)
 
515
          (t t))))
 
516
 
 
517
(defun set-env ()
 
518
  (setq *break-env*
 
519
        (if (ihs-not-interpreted-env *current-ihs*)
 
520
            nil
 
521
            (let ((i (ihs-vs *current-ihs*)))
 
522
              (list (vs i) (vs (1+ i)) (vs (+ i 2)))))))
 
523
 
 
524
(defun list-delq (x l)
 
525
  (cond ((null l) nil)
 
526
        ((eq x (car l)) (cdr l))
 
527
        (t (rplacd l (list-delq x (cdr l))))))
 
528
 
 
529
(defun super-go (i tag &aux x)
 
530
  (when (and (>= i *frs-base*) (<= i *frs-top*) (spicep (frs-tag i)))
 
531
    (if (setq x (member (frs-tag i) (vs (+ (frs-vs i) 2))
 
532
                        :key #'caddr :test #'eq))
 
533
        ; Interpreted TAGBODY.
 
534
        (when (and (eq (cadar x) 'tag)
 
535
                   (member tag (mapcar #'car (remove (frs-tag i) x
 
536
                                                     :test-not #'eq
 
537
                                                     :key #'caddr))))
 
538
          (internal-super-go (frs-tag i) tag t))
 
539
        ; Maybe, compiled cross-closure TAGBODY.
 
540
        ; But, it may also be compiled cross-closure BLOCK, in which case
 
541
        ; SUPER-GO just RETURN-FROMs with zero values.
 
542
        (internal-super-go (frs-tag i) tag nil)))
 
543
  (format *debug-io* "~s is invalid tagbody identification for ~s." i tag))
 
544
 
 
545
(defun break-backward-search-stack (sym &aux string)
 
546
  (setq string (string sym))
 
547
  (do* ((ihs (1- *current-ihs*) (1- ihs))
 
548
        (fname (ihs-fname ihs) (ihs-fname ihs)))
 
549
      ((< ihs *ihs-base*)
 
550
       (format *debug-io* "Search for ~a failed.~%" string))
 
551
    (when (and (ihs-visible ihs)
 
552
               (search string (symbol-name fname) :test #'char-equal))
 
553
      (break-go ihs)
 
554
      (return))))
 
555
 
 
556
(defun break-forward-search-stack (sym &aux string)
 
557
  (setq string (string sym))
 
558
  (do* ((ihs (1+ *current-ihs*) (1+ ihs))
 
559
        (fname (ihs-fname ihs) (ihs-fname ihs)))
 
560
      ((> ihs *ihs-top*)
 
561
       (format *debug-io* "Search for ~a failed.~%" string))
 
562
    (when (and (ihs-visible ihs)
 
563
               (search string (symbol-name fname) :test #'char-equal))
 
564
      (break-go ihs)
 
565
      (return))))
 
566
 
 
567
 
 
568
(putprop :b 'simple-backtrace 'break-command)
 
569
(putprop :r '(lambda () :resume) 'break-command)
 
570
(putprop :resume (get :r 'break-command) 'break-command)
 
571
(putprop :bds 'break-bds 'break-command)
 
572
(putprop :blocks 'break-blocks 'break-command)
 
573
(putprop :bs 'break-backward-search-stack 'break-command)
 
574
(putprop :c 'break-current 'break-command)
 
575
(putprop :fs 'break-forward-search-stack 'break-command)
 
576
(putprop :functions 'break-functions 'break-command)
 
577
(putprop :go 'break-go 'break-command)
 
578
(putprop :h 'break-help 'break-command)
 
579
(putprop :help 'break-help 'break-command)
 
580
(putprop :ihs 'ihs-backtrace 'break-command)
 
581
(putprop :env '(lambda () (describe-environment *break-env*)) 'break-command)
 
582
(putprop :m 'break-message 'break-command)
 
583
(putprop :n 'break-next 'break-command)
 
584
(putprop :p 'break-previous 'break-command)
 
585
(putprop :q 'break-quit 'break-command)
 
586
(putprop :s 'break-backward-search-stack 'break-command)
 
587
(putprop :vs 'break-vs 'break-command)
 
588
 
 
589
(defun break-help ()
 
590
  (dolist (v '( "
 
591
Break-loop Command Summary ([] indicates optional arg)
 
592
--------------------------
 
593
 
 
594
:bl [j]     show local variables and their values, or segment of vs if compiled
 
595
              in j stack frames starting at the current one.
 
596
:bt [n]     BACKTRACE [n steps]
 
597
:down [i]   DOWN i frames (one if no i)
 
598
:env        describe ENVIRONMENT of this stack frame (for interpreted).
 
599
:fr [n]     show frame n
 
600
:loc [i]    return i'th local of this frame if its function is compiled (si::loc i)
 
601
"
 
602
":r          RESUME (return from the current break loop).
 
603
:up [i]     UP i frames (one if no i)
 
604
 
 
605
Example: print a bactrace of the last 4 frames
 
606
 
 
607
>>:bt 4
 
608
 
 
609
Note:  (use-fast-links nil) makes all non system function calls
 
610
be recorded in the stack.   (use-fast-links t) is the default
 
611
 
 
612
Low level commands:
 
613
------------------
 
614
:p [i]           make current the i'th PREVIOUS frame (in list show by :b)
 
615
:n [i]           make current the i'th NEXT frame (in list show by :b)
 
616
:go [ihs-index]  make current the frame corresponding ihs-index
 
617
"
 
618
":m               print the last break message.
 
619
:c               show function of the current ihs frame.
 
620
:q [i]           quit to top level
 
621
:r               resume from this break loop.
 
622
:b               full backtrace of all functions and special forms.
 
623
:bs [name]       backward search for frame named 'name'
 
624
:fs  [name]      search for frame named 'name'
 
625
:vs [from] [to]  Show value stack between FROM and TO
 
626
:ihs [from] [to] Show Invocation History Stack
 
627
"
 
628
"
 
629
:bds ['v1 'v2 ..]Show previous special bindings of v1, v2,.. or all if no v1
 
630
 
 
631
")) (format  *debug-io* v))
 
632
  (format *debug-io* "~%Here is a COMPLETE list of bindings.   Too
 
633
add a new one, add a 'si::break-command property:")
 
634
  (do-symbols (v (find-package "KEYWORD"))
 
635
              (cond ((get v 'si::break-command)
 
636
                     (format  *debug-io*
 
637
                              "~%~(~a -- ~a~)" v (get v 'si::break-command)))))
 
638
          (values)
 
639
          )
 
640
 
 
641
 
 
642
;;make sure '/' terminated
 
643
 
 
644
(defun coerce-slash-terminated (v )
 
645
  (declare (string v))
 
646
  (or (stringp v) (error "not a string ~a" v))
 
647
  (let ((n (length v)))
 
648
    (declare (fixnum n))
 
649
    (unless (and (> n 0) (eql
 
650
                          (the character(aref v (the fixnum (- n 1)))) #\/))
 
651
            (setf v (format nil "~a/" v))))
 
652
  v)
 
653
(defun fix-load-path (l)
 
654
  (when (not (equal l *fixed-load-path*))
 
655
      (do ((x l (cdr x)) )
 
656
          ((atom x))
 
657
          (setf (car x) (coerce-slash-terminated (car x))))
 
658
      (do ((v l (cdr v)))
 
659
          ((atom v))
 
660
          (do ((w v (cdr w)))
 
661
              ((atom (cdr w)))
 
662
              (cond ((equal (cadr w) (car v))
 
663
                     (setf (cdr w)(cddr w)))))))
 
664
  (setq *fixed-load-path* l))
 
665
 
 
666
(defun file-search (NAME &optional (dirs *load-path*)
 
667
                          (extensions *load-types*) (fail-p t) &aux  tem)
 
668
  "Search for NAMME in DIRS with EXTENSIONS.
 
669
First directory is checked for first name and all extensions etc."
 
670
  (fix-load-path dirs)
 
671
  (dolist (v dirs)
 
672
      (dolist (e extensions)
 
673
          (if (probe-file (setq tem (si::string-concatenate v name e)))
 
674
            (return-from file-search tem))))
 
675
  (if fail-p
 
676
      (let ((*path* nil))
 
677
        (declare (special *path*))
 
678
        (cerror
 
679
         "Do (setq si::*path* \"pathname\") for path to use then :r to continue"
 
680
         "Lookup failed in directories:~s for name ~s with extensions ~s"
 
681
         dirs name extensions)
 
682
        *path*)))
 
683
 
 
684
(defun aload (path)
 
685
  (load (file-search path *load-path* *load-types*)))
 
686
 
 
687
(defun autoload (sym path &aux (si::*ALLOW-GZIPPED-FILE* t))
 
688
  (or (fboundp sym)
 
689
      (setf (symbol-function sym)
 
690
            #'(lambda (&rest l)
 
691
                (aload path)
 
692
                (apply sym l)))))
 
693
 
 
694
(defun autoload-macro (sym path &aux (si::*ALLOW-GZIPPED-FILE* t))
 
695
  (or (fboundp sym)
 
696
      (setf (macro-function sym)
 
697
            #'(lambda (form env)
 
698
                (aload path)
 
699
                (funcall sym form env)))))
 
700
 
 
701
(eval-when (compile) (proclaim '(optimize (safety 0))) )
 
702
(defvar si::*command-args* nil)
 
703
(defun si::get-command-arg (a &optional val-if-there &aux (v *command-args*))
 
704
  (declare (string a))
 
705
  ;; return non nil if annnnxu is in si::*command-args* and return
 
706
  ;; the string which is after it if there is one"
 
707
  (loop
 
708
    (setq v (cdr v))
 
709
    (or v (return nil))
 
710
    (let ((str (car v)))
 
711
      (declare (string str))
 
712
      (if (and (eql  (aref str 0) (aref a 0))
 
713
               (eql  (aref str 1) (aref a 1))
 
714
               (equal str a))
 
715
          (return
 
716
          (cond (val-if-there)
 
717
                ((cadr v)(values (cadr v) (cdr v)))
 
718
                (t t)))))))
 
719
 
 
720
; (let ((tem (member a si::*command-args* :test 'equal)))
 
721
;    (if tem (or  val-if-there (cadr tem) t))))
 
722
 
 
723
(defun set-dir (sym flag)
 
724
   (let ((tem (or (si::get-command-arg flag) (and (boundp sym) (symbol-value sym)))))
 
725
      (if tem (set sym (si::coerce-slash-terminated tem)))))
 
726
 
 
727
(defun set-up-top-level ( &aux (i (si::argc)) tem)
 
728
  (declare (fixnum i))
 
729
  (loop (setq i (- i 1))
 
730
        (cond ((< i 0)(return nil))
 
731
              (t (setq tem (cons (argv i) tem)))))
 
732
  (setq *command-args* tem)
 
733
  (setq tem *lib-directory*)
 
734
  (let ((dir (si::getenv "GCL_LIBDIR")))
 
735
    (or (set-dir  'si::*lib-directory* "-libdir")
 
736
        (if dir (setq *lib-directory* (coerce-slash-terminated dir))))
 
737
    (unless
 
738
     (and *load-path* (equal tem *lib-directory*))
 
739
     (setq *load-path* (cons (si::string-concatenate *lib-directory*
 
740
                                                     "lsp/") *load-path*))
 
741
     (setq *load-path* (cons (si::string-concatenate *lib-directory*
 
742
                                                     "mod/") *load-path*))
 
743
     (setq *load-path* (cons (si::string-concatenate *lib-directory*
 
744
                                                     "gcl-tk/") *load-path*))
 
745
            )
 
746
    (when (not (boundp 'si::*system-directory*)) 
 
747
      (setq si::*system-directory* (namestring
 
748
        (truename (make-pathname :name nil :type nil :defaults (si::argv 0))))))
 
749
    (set-dir  'si::*system-directory* "-dir")
 
750
    (if (multiple-value-setq (tem tem) (get-command-arg "-f"))
 
751
        (let (*load-verbose*)
 
752
          (si::process-some-args si::*command-args*)
 
753
          (setq si::*command-args* tem)
 
754
          (si::do-f (car si::*command-args*))))
 
755
    ))
 
756
 
 
757
(defun do-f (file )
 
758
  (let ((eof '(nil)) tem
 
759
        *break-enable*)
 
760
    (catch *quit-tag*
 
761
      (with-open-file (st file)
 
762
                      (READ-LINE ST)
 
763
                      (LOOP
 
764
                       (SETQ TEM (READ ST NIL EOF))
 
765
                       (COND ((EQ EOF TEM) (return nil)))
 
766
                       (EVAL TEM)))
 
767
      (bye))
 
768
      (bye 1)
 
769
      ))