/[cmucl]/src/code/save.lisp
ViewVC logotype

Contents of /src/code/save.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.31 - (hide annotations)
Sat Mar 15 16:58:59 1997 UTC (17 years, 1 month ago) by dtc
Branch: MAIN
CVS Tags: RELEASE_18a
Branch point for: RELENG_18
Changes since 1.30: +3 -1 lines
Patch to save-lisp to cancel the finalizer for the *tty* stream before
the save. To fix a problem where the stream is erroneously closed in
the re-started lisp.
1 ram 1.1 ;;; -*- Mode: Lisp; Package: Lisp; Log: code.log -*-
2     ;;;
3     ;;; **********************************************************************
4 ram 1.5 ;;; This code was written as part of the CMU Common Lisp project at
5     ;;; Carnegie Mellon University, and has been placed in the public domain.
6     ;;;
7     (ext:file-comment
8 dtc 1.31 "$Header: /tiger/var/lib/cvsroots/cmucl/src/code/save.lisp,v 1.31 1997/03/15 16:58:59 dtc Exp $")
9 ram 1.5 ;;;
10 ram 1.1 ;;; **********************************************************************
11     ;;;
12 wlott 1.2 ;;; Dump the current lisp image into a core file. All the real work is done
13 ram 1.8 ;;; be C. Also contains various high-level initialization stuff: loading init
14     ;;; files and parsing environment variables.
15 wlott 1.2 ;;;
16     ;;; Written by William Lott.
17 ram 1.1 ;;;
18     ;;;
19     (in-package "LISP")
20    
21     (in-package "EXTENSIONS")
22 ram 1.15 (export '(print-herald *herald-items* save-lisp *before-save-initializations*
23 wlott 1.2 *after-save-initializations* *environment-list* *editor-lisp-p*))
24 ram 1.1 (in-package "LISP")
25    
26 wlott 1.2 (defvar *before-save-initializations* nil
27     "This is a list of functions which are called before creating a saved core
28     image. These functions are executed in the child process which has no ports,
29     so they cannot do anything that tries to talk to the outside world.")
30 ram 1.1
31 wlott 1.2 (defvar *after-save-initializations* nil
32     "This is a list of functions which are called when a saved core image starts
33     up. The system itself should be initialized at this point, but applications
34     might not be.")
35 ram 1.1
36 wlott 1.2 (defvar *environment-list* nil
37     "An alist mapping environment variables (as keywords) to either values")
38 ram 1.1
39 wlott 1.2 (defvar *editor-lisp-p* nil
40     "This is true if and only if the lisp was started with the -edit switch.")
41    
42    
43    
44     ;;; Filled in by the startup code.
45 ram 1.1 (defvar lisp-environment-list)
46    
47    
48 ram 1.8 ;;; PARSE-UNIX-SEARCH-LIST -- Internal
49     ;;;
50     ;;; Returns a list of the directories that are in the specified Unix
51     ;;; environment variable. Return NIL if the variable is undefined.
52     ;;;
53     (defun parse-unix-search-list (var)
54     (let ((path (cdr (assoc var ext::*environment-list*))))
55     (when path
56     (do* ((i 0 (1+ p))
57     (p (position #\: path :start i)
58     (position #\: path :start i))
59     (pl ()))
60     ((null p)
61     (let ((s (subseq path i)))
62     (if (string= s "")
63     (push "default:" pl)
64     (push (concatenate 'simple-string s "/") pl)))
65     (nreverse pl))
66     (let ((s (subseq path i p)))
67     (if (string= s "")
68     (push "default:" pl)
69     (push (concatenate 'simple-string s "/") pl)))))))
70    
71    
72     ;;; ENVIRONMENT-INIT -- Internal
73     ;;;
74     ;;; Parse the LISP-ENVIRONMENT-LIST into a keyword alist. Set up default
75     ;;; search lists.
76     ;;;
77     (defun environment-init ()
78 ram 1.16 (setq *environment-list* ())
79 ram 1.8 (dolist (ele lisp-environment-list)
80     (let ((=pos (position #\= (the simple-string ele))))
81     (when =pos
82     (push (cons (intern (string-upcase (subseq ele 0 =pos))
83     *keyword-package*)
84     (subseq ele (1+ =pos)))
85     *environment-list*))))
86     (setf (search-list "default:") (list (default-directory)))
87     (setf (search-list "path:") (parse-unix-search-list :path))
88 ram 1.10 (setf (search-list "home:")
89     (or (parse-unix-search-list :home)
90     (list (default-directory))))
91    
92 ram 1.9 (setf (search-list "library:")
93     (or (parse-unix-search-list :cmucllib)
94 ram 1.29 '(#+mach "/usr/misc/.cmucl/lib/"
95     #+linux "/usr/lib/cmucl/"
96     #-(or mach linux) "/usr/local/lib/cmucl/lib/"))))
97 ram 1.8
98 wlott 1.17
99    
100     ;;;; SAVE-LISP itself.
101    
102     (alien:def-alien-routine "save" (alien:boolean)
103     (file c-call:c-string)
104     (initial-function (alien:unsigned #.vm:word-bits)))
105    
106 wlott 1.2 (defun save-lisp (core-file-name &key
107     (purify t)
108     (root-structures ())
109 ram 1.21 (environment-name "Auxiliary")
110 ram 1.28 (init-function #'%top-level)
111 wlott 1.2 (load-init-file t)
112 ram 1.8 (site-init "library:site-init")
113 wlott 1.2 (print-herald t)
114     (process-command-line t))
115     "Saves a CMU Common Lisp core image in the file of the specified name. The
116     following keywords are defined:
117    
118     :purify
119 ram 1.18 If true (the default), do a purifying GC which moves all dynamically
120     allocated objects into static space so that they stay pure. This takes
121     somewhat longer than the normal GC which is otherwise done, but GC's will
122 ram 1.21 done less often and take less time in the resulting core file. See
123     EXT:PURIFY.
124 wlott 1.2
125     :root-structures
126 ram 1.21 This should be a list of the main entry points in any newly loaded
127     systems. This need not be supplied, but locality and/or GC performance
128     will be better if they are. Meaningless if :purify is NIL. See EXT:PURIFY.
129    
130     :environment-name
131     Also passed to EXT:PURIFY when :PURIFY is T. Rarely used.
132 wlott 1.2
133     :init-function
134 ram 1.18 This is the function that starts running when the created core file is
135 wlott 1.17 resumed. The default function simply invokes the top level
136     read-eval-print loop. If the function returns the lisp will exit.
137 wlott 1.2
138     :load-init-file
139     If true, then look for an init.lisp or init.fasl file when the core
140     file is resumed.
141 ram 1.8
142     :site-init
143     If true, then the name of the site init file to load. The default is
144     library:site-init. No error if this does not exist.
145    
146 wlott 1.2 :print-herald
147 ram 1.18 If true (the default), print out the lisp system herald when starting."
148 ram 1.4
149 ram 1.8 (when (fboundp 'eval:flush-interpreted-function-cache)
150     (eval:flush-interpreted-function-cache))
151 dtc 1.31 (when (fboundp 'cancel-finalization)
152     (cancel-finalization sys:*tty*))
153 wlott 1.2 (if purify
154 ram 1.21 (purify :root-structures root-structures
155     :environment-name environment-name)
156 wlott 1.2 (gc))
157 ram 1.23 (dolist (f *before-save-initializations*) (funcall f))
158 wlott 1.17 (flet
159     ((restart-lisp ()
160 ram 1.28 (unix:unix-exit
161     (catch '%end-of-the-world
162     (with-simple-restart (abort "Skip remaining initializations.")
163     (catch 'top-level-catcher
164     (reinit)
165     (dolist (f *after-save-initializations*) (funcall f))
166     (environment-init)
167     (when process-command-line
168     (ext::process-command-strings))
169     (setf *editor-lisp-p* nil)
170     (macrolet ((find-switch (name)
171     `(find ,name *command-line-switches*
172     :key #'cmd-switch-name
173     :test #'(lambda (x y)
174     (declare (simple-string x y))
175     (string-equal x y)))))
176 pw 1.30 (when site-init
177     (load site-init :if-does-not-exist nil :verbose nil))
178 ram 1.28 (when (and process-command-line (find-switch "edit"))
179     (setf *editor-lisp-p* t))
180     (when (and load-init-file
181     (not (and process-command-line
182     (find-switch "noinit"))))
183     (let* ((cl-switch (find-switch "init"))
184     (name (and cl-switch
185     (or (cmd-switch-value cl-switch)
186     (car (cmd-switch-words
187     cl-switch))))))
188     (if name
189     (load (merge-pathnames name #p"home:")
190     :if-does-not-exist nil)
191     (or (load "home:init" :if-does-not-exist nil)
192     (load "home:.cmucl-init"
193     :if-does-not-exist nil))))))
194     (when process-command-line
195     (ext::invoke-switch-demons *command-line-switches*
196     *command-switch-demons*))
197     (when print-herald
198     (print-herald))))
199     (funcall (if (and *batch-mode* (eq init-function #'%top-level))
200     #'%handled-top-level
201     init-function))))))
202    
203 wlott 1.17 (let ((initial-function (get-lisp-obj-address #'restart-lisp)))
204     (without-gcing
205     (save (unix-namestring core-file-name nil) initial-function))))
206     nil)
207 wlott 1.2
208 wlott 1.17
209    
210     ;;;; PRINT-HERALD support.
211 wlott 1.2
212 ram 1.15 (defvar *herald-items* ()
213     "Determines what PRINT-HERALD prints (the system startup banner.) This is a
214     database which can be augmented by each loaded system. The format is a
215     property list which maps from subsystem names to the banner information for
216     that system. This list can be manipulated with GETF -- entries are printed
217     in, reverse order, so the newest entry is printed last. Usually the system
218     feature keyword is used as the system name. A given banner is a list of
219     strings and functions (or function names). Strings are printed, and
220     functions are called with an output stream argument.")
221    
222     (setf (getf *herald-items* :common-lisp)
223     `("CMU Common Lisp "
224     ,#'(lambda (stream)
225     (write-string (lisp-implementation-version) stream))
226     ", running on "
227     ,#'(lambda (stream) (write-string (machine-instance) stream))))
228    
229     (setf (getf *herald-items* :bugs)
230     '("Send bug reports and questions to cmucl-bugs@cs.cmu.edu."
231     terpri
232     "Loaded subsystems:"))
233    
234     ;;; PRINT-HERALD -- Public
235     ;;;
236     (defun print-herald (&optional (stream *standard-output*))
237     "Print some descriptive information about the Lisp system version and
238     configuration."
239     (let ((res ()))
240     (do ((item *herald-items* (cddr item)))
241     ((null item))
242     (push (second item) res))
243    
244     (fresh-line stream)
245     (dolist (item res)
246     (dolist (thing item)
247     (typecase thing
248     (string
249     (write-string thing stream))
250     (function (funcall thing stream))
251     ((or symbol cons)
252     (funcall (fdefinition thing) stream))
253     (t
254     (error "Unrecognized *HERALD-ITEMS* entry: ~S." thing))))
255     (fresh-line stream)))
256    
257 wlott 1.2 (values))
258    
259    
260     ;;;; Random functions used by worldload.
261    
262     (defun assert-user-package ()
263     (unless (eq *package* (find-package "USER"))
264     (error "Change *PACKAGE* to the USER package and try again.")))
265 ram 1.20
266     ;;; MAYBE-BYTE-LOAD -- Interface
267     ;;;
268     ;;; If Name has been byte-compiled, and :runtime is a feature, then load the
269     ;;; byte-compiled version, otherwise just do normal load.
270     ;;;
271     (defun maybe-byte-load (name &optional (load-native t))
272     (let ((bname (make-pathname
273     :defaults name
274     :type #.(c:backend-byte-fasl-file-type c:*target-backend*))))
275     (cond ((and (featurep :runtime)
276     (probe-file bname))
277     (load bname))
278     (load-native
279     (load name)))))
280    
281    
282     ;;; BYTE-LOAD-OVER -- Interface
283     ;;;
284     ;;; Replace a cold-loaded native object file with a byte-compiled one, if it
285     ;;; exists.
286     ;;;
287     (defun byte-load-over (name)
288     (load (make-pathname
289     :defaults name
290     :type #.(c:backend-byte-fasl-file-type c:*target-backend*))
291     :if-does-not-exist nil))

  ViewVC Help
Powered by ViewVC 1.1.5