source: trunk/abcl/src/org/armedbear/lisp/boot.lisp @ 12192

Last change on this file since 12192 was 12105, checked in by Mark Evenson, 16 years ago

Split StackFrame? abstraction into Java and Lisp stack frames.

From the original patch/idea from Tobias Rittweiler this introduces
more information of primary interest to ABCL implemnters such as when
a form like (make-thread #'(lambda ())) is evaluated

All users of EXT:BACKTRACE-AS-LIST should now use SYS:BACKTRACE, the
results of which is a list of the new builtin classes JAVA_STACK_FRAME
or LISP_STACK_FRAME. The methods SYS:FRAME-TO-STRING and
SYS:FRAME-TO-LIST are defined to break these new objects into
inspectable parts. As a convenience, there is a SYS:BACKTRACE-AS-LIST
which calls SYS:FRAME-TO-LIST to each element of the computed
backtrace.

Refactorings have occurred on the Java side: the misnamed
LispThread?.backtrace() is now LispThread?.printBacktrace().
LispThread?.backtraceAsList() is now LispThread?.backtrace() as it is
a shorter name, and more to the point.

Java stack frames only appear after a call through Lisp.error(), which
has only the top level as a restart as an option.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 12.2 KB
Line 
1;;; boot.lisp
2;;;
3;;; Copyright (C) 2003-2007 Peter Graves <peter@armedbear.org>
4;;; $Id: boot.lisp 12105 2009-08-19 14:51:56Z mevenson $
5;;;
6;;; This program is free software; you can redistribute it and/or
7;;; modify it under the terms of the GNU General Public License
8;;; as published by the Free Software Foundation; either version 2
9;;; of the License, or (at your option) any later version.
10;;;
11;;; This program is distributed in the hope that it will be useful,
12;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14;;; GNU General Public License for more details.
15;;;
16;;; You should have received a copy of the GNU General Public License
17;;; along with this program; if not, write to the Free Software
18;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19;;;
20;;; As a special exception, the copyright holders of this library give you
21;;; permission to link this library with independent modules to produce an
22;;; executable, regardless of the license terms of these independent
23;;; modules, and to copy and distribute the resulting executable under
24;;; terms of your choice, provided that you also meet, for each linked
25;;; independent module, the terms and conditions of the license of that
26;;; module.  An independent module is a module which is not derived from
27;;; or based on this library.  If you modify this library, you may extend
28;;; this exception to your version of the library, but you are not
29;;; obligated to do so.  If you do not wish to do so, delete this
30;;; exception statement from your version.
31
32(sys:%in-package "SYSTEM")
33
34(setq *load-verbose*     nil)
35(setq *autoload-verbose* nil)
36
37;; Redefined in macros.lisp.
38(defmacro in-package (name)
39  (list '%in-package (string name)))
40
41(defmacro lambda (lambda-list &rest body)
42  (list 'function (list* 'lambda lambda-list body)))
43
44(defmacro named-lambda (name lambda-list &rest body)
45  (list 'function (list* 'named-lambda name lambda-list body)))
46
47;; Redefined in macros.lisp.
48(defmacro return (&optional result)
49  (list 'return-from nil result))
50
51;; Redefined in precompiler.lisp.
52(defmacro defun (name lambda-list &rest body)
53  (let ((block-name (fdefinition-block-name name)))
54    (list '%defun
55          (list 'quote name)
56          (list 'lambda lambda-list (list* 'block block-name body)))))
57
58;; Redefined in macros.lisp.
59(defmacro defconstant (name initial-value &optional docstring)
60  (list '%defconstant (list 'quote name) initial-value docstring))
61
62;; Redefined in macros.lisp.
63(defmacro defparameter (name initial-value &optional docstring)
64  (list '%defparameter (list 'quote name) initial-value docstring))
65
66(defmacro declare (&rest ignored) nil)
67
68(in-package #:extensions)
69
70(export '(%car %cdr %cadr %caddr))
71
72(defmacro %car (x)
73  (list 'car (list 'truly-the 'cons x)))
74
75(defmacro %cdr (x)
76  (list 'cdr (list 'truly-the 'cons x)))
77
78(defmacro %cadr (x)
79  (list '%car (list '%cdr x)))
80
81(defmacro %caddr (x)
82  (list '%car (list '%cdr (list '%cdr x))))
83
84(in-package #:system)
85
86;; Redefined in precompiler.lisp.
87(defun eval (form)
88  (%eval form))
89
90;; Redefined in pprint.lisp.
91(defun terpri (&optional output-stream)
92  (%terpri output-stream))
93
94;; Redefined in pprint.lisp.
95(defun fresh-line (&optional output-stream)
96  (%fresh-line output-stream))
97
98;; Redefined in pprint.lisp.
99(defun write-char (character &optional output-stream)
100  (%write-char character output-stream))
101
102(in-package #:extensions)
103
104;; Redefined in pprint.lisp.
105(defun charpos (stream)
106  (sys::stream-charpos stream))
107
108;; Redefined in pprint.lisp.
109(defun (setf charpos) (new-value stream)
110  (sys::stream-%set-charpos stream new-value))
111
112(export 'charpos '#:extensions)
113
114;; Redefined in precompiler.lisp.
115(defun precompile (name &optional definition)
116  (declare (ignore name definition))
117  nil)
118
119(export 'precompile '#:extensions)
120
121(in-package #:system)
122
123(defun simple-format (destination control-string &rest args)
124  (apply *simple-format-function* destination control-string args))
125
126(export 'simple-format '#:system)
127
128;; INVOKE-DEBUGGER is redefined in debug.lisp.
129(defun invoke-debugger (condition)
130  (sys::%format t "~A~%" condition)
131  (ext:quit))
132
133(load-system-file "autoloads")
134(load-system-file "early-defuns")
135(load-system-file "backquote")
136(load-system-file "destructuring-bind")
137(load-system-file "defmacro")
138(load-system-file "setf")
139(load-system-file "fdefinition")
140(load-system-file "featurep")
141(load-system-file "read-conditional")
142(load-system-file "macros")
143
144;; Redefined in package.lisp
145(defun make-package (package-name &key nicknames use)
146  (%make-package package-name nicknames use))
147
148;;; Reading circular data: the #= and ## reader macros (from SBCL)
149
150;;; Objects already seen by CIRCLE-SUBST.
151(defvar *sharp-equal-circle-table*)
152
153;; This function is kind of like NSUBLIS, but checks for circularities and
154;; substitutes in arrays and structures as well as lists. The first arg is an
155;; alist of the things to be replaced assoc'd with the things to replace them.
156(defun circle-subst (old-new-alist tree)
157  (macrolet ((recursable-element-p (subtree)
158                `(typep ,subtree
159                       '(or cons (array t) structure-object standard-object)))
160             (element-replacement (subtree)
161               `(let ((entry (find ,subtree old-new-alist :key #'second)))
162                  (if entry (third entry) ,subtree))))
163  (cond ((not (recursable-element-p tree))
164         (element-replacement tree))
165        ((null (gethash tree *sharp-equal-circle-table*))
166         (cond
167          ((typep tree 'structure-object)
168           (setf (gethash tree *sharp-equal-circle-table*) t)
169           (do ((i 0 (1+ i))
170                (end (structure-length tree)))
171               ((= i end))
172             (let* ((old (structure-ref tree i))
173                    (new (circle-subst old-new-alist old)))
174               (unless (eq old new)
175                 (structure-set tree i new)))))
176;;           ((typep tree 'standard-object)
177;;            (setf (gethash tree *sharp-equal-circle-table*) t)
178;;            (do ((i 1 (1+ i))
179;;                 (end (%instance-length tree)))
180;;                ((= i end))
181;;              (let* ((old (%instance-ref tree i))
182;;                     (new (circle-subst old-new-alist old)))
183;;                (unless (eq old new)
184;;                  (setf (%instance-ref tree i) new)))))
185          ((arrayp tree)
186           (setf (gethash tree *sharp-equal-circle-table*) t)
187           (do ((i 0 (1+ i))
188                (end (array-total-size tree)))
189               ((>= i end))
190             (let* ((old (row-major-aref tree i))
191                    (new (circle-subst old-new-alist old)))
192               (unless (eq old new)
193                 (setf (row-major-aref tree i) new)))))
194         (t ;; being CONSP as all the other cases have been handled
195            (do ((subtree tree (cdr subtree)))
196                ((or (not (consp subtree))
197                     (gethash subtree *sharp-equal-circle-table*)))
198                ;; CDR no longer a CONS; no need to recurse any further:
199                ;; the case where the CDR is a symbol to be replaced
200                ;; has been handled in the last iteration
201              (setf (gethash subtree *sharp-equal-circle-table*) t)
202              (let* ((c (car subtree))
203                     (d (cdr subtree))
204                     (a (if (recursable-element-p c)
205                            (circle-subst old-new-alist c)
206                            (element-replacement c)))
207                     (b (cond
208                         ((consp d) d) ;; CONSes handled in the loop
209                         ((recursable-element-p d)
210                          ;; ARRAY, STRUCTURE-OBJECT and STANDARD-OBJECT
211                          ;; handled in recursive calls
212                          (circle-subst old-new-alist d))
213                         (t
214                          (element-replacement d)))))
215                (unless (eq a c)
216                  (rplaca subtree a))
217                (unless (eq d b)
218                  (rplacd subtree b))))))
219        tree)
220  (t tree))))
221
222;;; Sharp-equal works as follows. When a label is assigned (i.e. when
223;;; #= is called) we GENSYM a symbol is which is used as an
224;;; unforgeable tag. *SHARP-SHARP-ALIST* maps the integer tag to this
225;;; gensym.
226;;;
227;;; When SHARP-SHARP encounters a reference to a label, it returns the
228;;; symbol assoc'd with the label. Resolution of the reference is
229;;; deferred until the read done by #= finishes. Any already resolved
230;;; tags (in *SHARP-EQUAL-ALIST*) are simply returned.
231;;;
232;;; After reading of the #= form is completed, we add an entry to
233;;; *SHARP-EQUAL-ALIST* that maps the gensym tag to the resolved
234;;; object. Then for each entry in the *SHARP-SHARP-ALIST, the current
235;;; object is searched and any uses of the gensysm token are replaced
236;;; with the actual value.
237
238(defvar *sharp-sharp-alist* ())
239
240(defun sharp-equal (stream ignore label)
241  (declare (ignore ignore))
242  (when *read-suppress* (return-from sharp-equal (values)))
243  (unless label
244    (error 'reader-error
245           :stream stream
246           :format-control "Missing label for #="))
247  (when (or (assoc label *sharp-sharp-alist*)
248            (assoc label *sharp-equal-alist*))
249    (error 'reader-error
250           :stream stream
251           :format-control "Multiply defined label: #~D="
252           :format-arguments (list label)))
253  (let* ((tag (gensym))
254         (*sharp-sharp-alist* (cons (list label tag nil) *sharp-sharp-alist*))
255         (obj (read stream t nil t)))
256    (when (eq obj tag)
257      (error 'reader-error
258             :stream stream
259             :format-control "Must tag something more than just #~D#"
260             :format-arguments (list label)))
261    (push (list label tag obj) *sharp-equal-alist*)
262    (when (third (car *sharp-sharp-alist*)) ;; set to T on circularity
263      (let ((*sharp-equal-circle-table* (make-hash-table :test 'eq :size 20)))
264        (circle-subst *sharp-equal-alist* obj)))
265    obj))
266
267(defun sharp-sharp (stream ignore label)
268  (declare (ignore ignore))
269  (when *read-suppress* (return-from sharp-sharp nil))
270  (unless label
271    (error 'reader-error :stream stream :format-control "Missing label for ##"))
272  (let ((entry (assoc label *sharp-equal-alist*)))
273    (if entry
274        (third entry)
275        (let ((pair (assoc label *sharp-sharp-alist*)))
276          (unless pair
277            (error 'reader-error
278                   :stream stream
279                   :format-control "Object is not labelled #~S#"
280                   :format-arguments (list label)))
281          (setf (third pair) t)
282          (second pair)))))
283
284(set-dispatch-macro-character #\# #\= #'sharp-equal +standard-readtable+)
285(set-dispatch-macro-character #\# #\# #'sharp-sharp +standard-readtable+)
286
287(copy-readtable +standard-readtable+ *readtable*)
288
289;; SYS::%COMPILE is redefined in precompiler.lisp.
290(defun sys::%compile (name definition)
291  (values (if name name definition) nil nil))
292
293(load-system-file "inline")
294(load-system-file "proclaim")
295(load-system-file "arrays")
296(load-system-file "compiler-macro")
297(load-system-file "subtypep")
298(load-system-file "typep")
299(load-system-file "compiler-error")
300(load-system-file "source-transform")
301(load-system-file "precompiler")
302
303(precompile-package "PRECOMPILER")
304(precompile-package "EXTENSIONS")
305(precompile-package "SYSTEM")
306(precompile-package "COMMON-LISP")
307
308(load-system-file "signal")
309(load-system-file "list")
310(load-system-file "sequences")
311(load-system-file "error")
312(load-system-file "defpackage")
313(load-system-file "define-modify-macro")
314
315;;; Package definitions.
316(defpackage "FORMAT" (:use "CL" "EXT"))
317
318(defpackage "XP"
319  (:use "CL")
320  (:export
321   #:output-pretty-object))
322
323(defconstant lambda-list-keywords
324  '(&optional &rest &key &aux &body &whole &allow-other-keys &environment))
325
326(load-system-file "require")
327(load-system-file "defstruct")
328(load-system-file "restart")
329(load-system-file "late-setf")
330(load-system-file "debug")
331(load-system-file "print")
332(load-system-file "pprint-dispatch")
333(load-system-file "pprint")
334(load-system-file "defsetf")
335(load-system-file "package")
336
337(defun preload-package (pkg)
338  (%format t "Preloading ~S~%" (find-package pkg))
339  (dolist (sym (package-symbols pkg))
340    (when (autoloadp sym)
341      (resolve sym))))
342
343(unless (featurep :j)
344  (load-system-file "top-level")
345  (unless *noinform*
346    (%format t "Startup completed in ~A seconds.~%"
347             (float (/ (ext:uptime) 1000)))))
Note: See TracBrowser for help on using the repository browser.