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

Contents of /src/code/save.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.26 - (show annotations)
Sun Nov 6 19:48:24 1994 UTC (19 years, 5 months ago) by ram
Branch: MAIN
Changes since 1.25: +3 -3 lines
Got conditional backwards in setting up Library:.
1 ;;; -*- Mode: Lisp; Package: Lisp; Log: code.log -*-
2 ;;;
3 ;;; **********************************************************************
4 ;;; 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 "$Header: /tiger/var/lib/cvsroots/cmucl/src/code/save.lisp,v 1.26 1994/11/06 19:48:24 ram Exp $")
9 ;;;
10 ;;; **********************************************************************
11 ;;;
12 ;;; Dump the current lisp image into a core file. All the real work is done
13 ;;; be C. Also contains various high-level initialization stuff: loading init
14 ;;; files and parsing environment variables.
15 ;;;
16 ;;; Written by William Lott.
17 ;;;
18 ;;;
19 (in-package "LISP")
20
21 (in-package "EXTENSIONS")
22 (export '(print-herald *herald-items* save-lisp *before-save-initializations*
23 *after-save-initializations* *environment-list* *editor-lisp-p*))
24 (in-package "LISP")
25
26 (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
31 (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
36 (defvar *environment-list* nil
37 "An alist mapping environment variables (as keywords) to either values")
38
39 (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 (defvar lisp-environment-list)
46
47
48 ;;; 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 (setq *environment-list* ())
79 (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 (setf (search-list "home:")
89 (or (parse-unix-search-list :home)
90 (list (default-directory))))
91
92 (setf (search-list "library:")
93 (or (parse-unix-search-list :cmucllib)
94 '(#+mach "/usr/misc/.cmucl/lib/"
95 #-mach "/usr/local/lib/cmucl/lib/"))))
96
97
98
99 ;;;; SAVE-LISP itself.
100
101 (alien:def-alien-routine "save" (alien:boolean)
102 (file c-call:c-string)
103 (initial-function (alien:unsigned #.vm:word-bits)))
104
105 (defun save-lisp (core-file-name &key
106 (purify t)
107 (root-structures ())
108 (environment-name "Auxiliary")
109 (init-function #'%top-level)
110 (load-init-file t)
111 (site-init "library:site-init")
112 (print-herald t)
113 (process-command-line t))
114 "Saves a CMU Common Lisp core image in the file of the specified name. The
115 following keywords are defined:
116
117 :purify
118 If true (the default), do a purifying GC which moves all dynamically
119 allocated objects into static space so that they stay pure. This takes
120 somewhat longer than the normal GC which is otherwise done, but GC's will
121 done less often and take less time in the resulting core file. See
122 EXT:PURIFY.
123
124 :root-structures
125 This should be a list of the main entry points in any newly loaded
126 systems. This need not be supplied, but locality and/or GC performance
127 will be better if they are. Meaningless if :purify is NIL. See EXT:PURIFY.
128
129 :environment-name
130 Also passed to EXT:PURIFY when :PURIFY is T. Rarely used.
131
132 :init-function
133 This is the function that starts running when the created core file is
134 resumed. The default function simply invokes the top level
135 read-eval-print loop. If the function returns the lisp will exit.
136
137 :load-init-file
138 If true, then look for an init.lisp or init.fasl file when the core
139 file is resumed.
140
141 :site-init
142 If true, then the name of the site init file to load. The default is
143 library:site-init. No error if this does not exist.
144
145 :print-herald
146 If true (the default), print out the lisp system herald when starting."
147
148 (when (fboundp 'eval:flush-interpreted-function-cache)
149 (eval:flush-interpreted-function-cache))
150 (if purify
151 (purify :root-structures root-structures
152 :environment-name environment-name)
153 (gc))
154 (dolist (f *before-save-initializations*) (funcall f))
155 (flet
156 ((restart-lisp ()
157 (catch '%end-of-the-world
158 (with-simple-restart (abort "Skip remaining initializations.")
159 (catch 'top-level-catcher
160 (reinit)
161 (dolist (f *after-save-initializations*) (funcall f))
162 (environment-init)
163 (when site-init
164 (load site-init :if-does-not-exist nil :verbose nil))
165 (when process-command-line
166 (ext::process-command-strings))
167 (setf *editor-lisp-p* nil)
168 (macrolet ((find-switch (name)
169 `(find ,name *command-line-switches*
170 :key #'cmd-switch-name
171 :test #'(lambda (x y)
172 (declare (simple-string x y))
173 (string-equal x y)))))
174 (when (and process-command-line (find-switch "edit"))
175 (setf *editor-lisp-p* t))
176 (when (and load-init-file
177 (not (and process-command-line
178 (find-switch "noinit"))))
179 (let* ((cl-switch (find-switch "init"))
180 (name (and cl-switch
181 (or (cmd-switch-value cl-switch)
182 (car (cmd-switch-words
183 cl-switch))))))
184 (if name
185 (load (merge-pathnames name #p"home:")
186 :if-does-not-exist nil)
187 (or (load "home:init" :if-does-not-exist nil)
188 (load "home:.cmucl-init"
189 :if-does-not-exist nil))))))
190 (when process-command-line
191 (ext::invoke-switch-demons *command-line-switches*
192 *command-switch-demons*))
193 (when print-herald
194 (print-herald))))
195 (funcall init-function))
196 (unix:unix-exit 0)))
197 (let ((initial-function (get-lisp-obj-address #'restart-lisp)))
198 (without-gcing
199 (save (unix-namestring core-file-name nil) initial-function))))
200 nil)
201
202
203
204 ;;;; PRINT-HERALD support.
205
206 (defvar *herald-items* ()
207 "Determines what PRINT-HERALD prints (the system startup banner.) This is a
208 database which can be augmented by each loaded system. The format is a
209 property list which maps from subsystem names to the banner information for
210 that system. This list can be manipulated with GETF -- entries are printed
211 in, reverse order, so the newest entry is printed last. Usually the system
212 feature keyword is used as the system name. A given banner is a list of
213 strings and functions (or function names). Strings are printed, and
214 functions are called with an output stream argument.")
215
216 (setf (getf *herald-items* :common-lisp)
217 `("CMU Common Lisp "
218 ,#'(lambda (stream)
219 (write-string (lisp-implementation-version) stream))
220 ", running on "
221 ,#'(lambda (stream) (write-string (machine-instance) stream))))
222
223 (setf (getf *herald-items* :bugs)
224 '("Send bug reports and questions to cmucl-bugs@cs.cmu.edu."
225 terpri
226 "Loaded subsystems:"))
227
228 ;;; PRINT-HERALD -- Public
229 ;;;
230 (defun print-herald (&optional (stream *standard-output*))
231 "Print some descriptive information about the Lisp system version and
232 configuration."
233 (let ((res ()))
234 (do ((item *herald-items* (cddr item)))
235 ((null item))
236 (push (second item) res))
237
238 (fresh-line stream)
239 (dolist (item res)
240 (dolist (thing item)
241 (typecase thing
242 (string
243 (write-string thing stream))
244 (function (funcall thing stream))
245 ((or symbol cons)
246 (funcall (fdefinition thing) stream))
247 (t
248 (error "Unrecognized *HERALD-ITEMS* entry: ~S." thing))))
249 (fresh-line stream)))
250
251 (values))
252
253
254 ;;;; Random functions used by worldload.
255
256 (defun assert-user-package ()
257 (unless (eq *package* (find-package "USER"))
258 (error "Change *PACKAGE* to the USER package and try again.")))
259
260 ;;; MAYBE-BYTE-LOAD -- Interface
261 ;;;
262 ;;; If Name has been byte-compiled, and :runtime is a feature, then load the
263 ;;; byte-compiled version, otherwise just do normal load.
264 ;;;
265 (defun maybe-byte-load (name &optional (load-native t))
266 (let ((bname (make-pathname
267 :defaults name
268 :type #.(c:backend-byte-fasl-file-type c:*target-backend*))))
269 (cond ((and (featurep :runtime)
270 (probe-file bname))
271 (load bname))
272 (load-native
273 (load name)))))
274
275
276 ;;; BYTE-LOAD-OVER -- Interface
277 ;;;
278 ;;; Replace a cold-loaded native object file with a byte-compiled one, if it
279 ;;; exists.
280 ;;;
281 (defun byte-load-over (name)
282 (load (make-pathname
283 :defaults name
284 :type #.(c:backend-byte-fasl-file-type c:*target-backend*))
285 :if-does-not-exist nil))

  ViewVC Help
Powered by ViewVC 1.1.5