3 ;; This file contains essential definitions for `runlisp'. You are
4 ;; encouraged to put your local changes in the main `runlisp.conf', or in
5 ;; other files alongside this one in `runlisp.d/', rather then editing this
10 ;; Sections are started with a line `[NAME]', starting in the leftmost
11 ;; column. Empty lines and lines starting with `;' -- /without/ preceding
12 ;; whitespace -- are ignored. Assignments have the form `VAR = VALUE'; the
13 ;; VALUE may be continued across multiple lines, if they begin with
14 ;; whitespace. All of the lines are stripped of initial and final whitespace
15 ;; and concatenated with spaces.
17 ;; Values may contain substitutions:
19 ;; * ${[SECTION:]VAR[?ALT]} -- replace with the value of VAR in SECTION; if
20 ;; not found, use ALT instead. (If ALT isn't provided, it's an error.)
22 ;; * $?[SECTION:]VAR{YES[|NO]} -- look up VAR in SECTION (or in the
23 ;; (original) current section, and `@COMMON'); if found, use YES,
26 ;; Variables are looked up starting in the home (or explicitly specified)
27 ;; section, then proceeding to the parents assigned to `@PARENTS'.
28 ;; (`@PARENTS' usually defaults to `@COMMON'; the parent of `@COMMON' is
29 ;; `@BUILTIN'; `@BUILTIN' and `@CONFIG' have no parents.)
31 ;; At top-level, the text is split into words at whitespace, unless prevented
32 ;; by double- and single-quote, or escaped by `\'. Within single quotes, all
33 ;; characters are treated literally. Within double quotes, `\' and `$' still
34 ;; works. A variable reference within quotes, or within a word, suppresses
35 ;; word-splitting and quoting, within the variable value -- but `$'
36 ;; expansions still work.
38 ;;;--------------------------------------------------------------------------
41 ;; Turn `#!' into a comment-to-end-of-line. This is used in all Lisp
42 ;; invocations, even though some of them don't apparently need it. For
43 ;; example, SBCL ignores an initial line beginning `#!' as a special feature
44 ;; of its `--script' option. Other Lisps won't do this, so a countermeasure
45 ;; like the following is necessary in their case. For the sake of a
46 ;; consistent environment, we ignore `#!' lines everywhere, even in Lisps
47 ;; which have their own, more specific, solution to this problem.
49 (set-dispatch-macro-character
51 (lambda (#1=#:stream #2=#:char #3=#:arg)
52 (declare (ignore #2# #3#))
53 (values (read-line #1#))))
55 ;; Clear all present symbols from the `COMMON-LISP-USER' package. Some Lisps
56 ;; leave débris in `COMMON-LISP-USER' -- for example, ECL leaves some
57 ;; allegedly useful symbols lying around, while ABCL has a straight-up bug in
58 ;; its `adjoin.lisp' file.
60 (let ((#4=#:pkg (find-package "COMMON-LISP-USER")))
61 (with-package-iterator (#5=#:next #4# :internal)
62 (loop (multiple-value-bind (#6=#:anyp #7=#:sym #8=#:how)
64 (declare (ignore #8#))
66 (unintern #7# #4#)))))
68 ;; Add `:runlisp-script' to `*features*' so that scripts can tell whether
69 ;; they're supposed to sit quietly and be debugged in a Lisp session or run
72 (pushnew :runlisp-script *features*)
74 ;; Load the system's ASDF.
78 ;; Prevent ASDF from upgrading itself. Otherwise it will do this
79 ;; automatically if a script invokes `asdf:load-system', but that will have a
80 ;; bad effect on startup time, and risks spamming the output streams with
82 inhibit-asdf-upgrade =
83 (funcall (intern "REGISTER-IMMUTABLE-SYSTEM"
84 (find-package "ASDF"))
87 ;; Upgrade ASDF from the source registry.
89 (funcall (intern "UPGRADE-ASDF" (find-package "ASDF")))
91 ;; Common actions when resuming a custom image.
93 (uiop:call-image-restore-hook)
95 ;; Common prelude for script startup in vanilla images. Most of this is
96 ;; already done in custom images.
99 (setf *load-verbose* nil *compile-verbose* nil)
101 ${inhibit-asdf-upgrade}
103 ${set-script-feature})
105 ;; Common prelude for dumping images.
110 ${inhibit-asdf-upgrade}
112 ${set-script-feature})
114 image-path = ${@image-dir}/${image-file}
116 ;;;--------------------------------------------------------------------------
119 command = ${@ENV:SBCL?sbcl}
120 image-file = ${@name}+asdf.core
123 ${command} --noinform
124 $?@image{--core "${image-path}" --eval "${image-restore}" |
125 --eval "${run-script-prelude}"}
126 --script "${@script}"
129 ${command} --noinform --no-userinit --no-sysinit --disable-debugger
130 --eval "${dump-image-prelude}"
131 --eval "(sb-ext:save-lisp-and-die \"${@image-new|q}\")"
133 ;;;--------------------------------------------------------------------------
136 command = ${@ENV:CCL?ccl}
137 image-file = ${@name}+asdf.image
141 $?@image{-I "${image-path}" -e "${image-restore}" |
142 -e "${run-script-prelude}"}
143 -l "${@script}" -e "(ccl:quit)" --
145 ;; A snaglet occurs here. CCL wants to use the image name as a clue to where
146 ;; the rest of its installation is; but in fact the image is nowhere near its
147 ;; installation. So we must hack...
150 -e "${dump-image-prelude}"
151 -e "(ccl::in-development-mode
152 (let ((#1=#:real-ccl-dir (ccl::ccl-directory)))
153 (defun ccl::ccl-directory ()
155 (ccl:getenv \"CCL_DEFAULT_DIRECTORY\")))
156 (if (and #2# (plusp (length (namestring #2#))))
157 (ccl::native-to-directory-pathname #2#)
159 (compile 'ccl::ccl-directory))"
160 -e "(ccl:save-application \"${@image-new|q}\"
162 :error-handler :quit)"
164 ;;;--------------------------------------------------------------------------
167 ;; CLisp causes much sadness. Superficially, it's the most sensible of all
168 ;; of the systems supported here: you just run `clisp SCRIPT -- ARGS ...' and
171 ;; The problems come when you want to do some preparatory work (e.g., load
172 ;; `asdf') and then run the script. There's a `-x' option to evaluate some
173 ;; Lisp code, but it has three major deficiencies.
175 ;; * It insists on printing the values of the forms it evaluates. It
176 ;; prints a blank line even if the form goes out of its way to produce no
177 ;; values at all. So the whole thing has to be a single top-level form
178 ;; which quits the Lisp rather than returning.
180 ;; * For some idiotic reason, you can have /either/ `-x' forms /or/ a
181 ;; script, but not both. So we have to include the `load' here
182 ;; explicitly. I suppose that was inevitable because we have to inhibit
183 ;; printing of the result forms, but it's still a separate source of
186 ;; * The icing on the cake: the `-x' forms are collectively concatenated --
187 ;; without spaces! -- and used to build a string stream, which is then
188 ;; assigned over the top of `*standard-input*', making the original stdin
189 ;; somewhat fiddly to track down.
191 ;; There's a `-i' option which will load a file without any of this
192 ;; stupidity, but nothing analogous for immediate expressions.
194 clisp-common-startup =
195 (setf *standard-input* (ext:make-stream :input))
196 (load "${@script|q}" :verbose nil :print nil)
199 command = ${@ENV:CLISP?clisp}
200 image-file = ${@name}+asdf.mem
204 $?@image{-M "${image-path}" -q
207 ${clisp-common-startup})" |
210 ${run-script-prelude}
211 ${clisp-common-startup})"}
215 ${command} -norc -q -q
216 -x "${dump-image-prelude}"
217 -x "(ext:saveinitmem \"${@image-new|q}\" :norc t :script t)"
219 ;;;--------------------------------------------------------------------------
222 command = ${@ENV:ECL?ecl}
223 image-file = ${@name}+asdf
226 $?@image{"${image-path}" -s "${@script}" |
227 ${@ENV:ECL?ecl} "${@ecl-opt}norc"
228 "${@ecl-opt}eval" "(progn
229 ${run-script-prelude}
231 "${@ecl-opt}shell" "${@script}"}
235 "${@data-dir}/dump-ecl"
236 "${@image-new}" "${command}" "${@ecl-opt}" "${@tmp-dir}"
238 ;;;--------------------------------------------------------------------------
241 command = ${@ENV:CMUCL?cmucl}
242 image-file = ${@name}+asdf.core
246 $?@image{-core "${image-path}" -eval "${image-restore}" |
247 -batch -noinit -nositeinit -quiet
249 (setf ext:*require-verbose* nil)
250 ${run-script-prelude})"}
251 -load "${@script}" -eval "(ext:quit)" --
254 ${command} -batch -noinit -nositeinit -quiet
255 -eval "${dump-image-prelude}"
256 -eval "(ext:save-lisp \"${@image-new|q}\"
257 :batch-mode t :print-herald nil
258 :site-init nil :load-init-file nil)"
260 ;;;--------------------------------------------------------------------------
263 ;; CLisp made a worthy effort, but ABCL still manages to take the prize.
265 ;; * ABCL manages to avoid touching the `stderr' stream at all, ever. Its
266 ;; startup machinery finds `stdout' (as `java.lang.System.out'), wraps it
267 ;; up in a Lisp stream, and uses the result as `*standard-output*' and
268 ;; `*error-output*' (and a goodly number of other things too). So we
269 ;; must manufacture a working `stderr' the hard way.
271 ;; * There doesn't appear to be any easy way to prevent toplevel errors
272 ;; from invoking the interactive debugger. For extra fun, the debugger
273 ;; reads from `stdin' by default, so an input file which somehow manages
274 ;; to break the script can then take over its brain by providing Lisp
275 ;; forms for the debugger to evaluate.
277 ;; * And, just to really top everything off, ABCL's `adjoin.lisp' is
278 ;; missing an `(in-package ...)' form at the top, so it leaks symbols
279 ;; into the `COMMON-LISP-USER' package.
281 command = ${@ENV:ABCL?abcl}
284 (let ((#9=#:script "${@script|q}"))
285 ${run-script-prelude}
288 (java:jnew "org.armedbear.lisp.Stream"
290 (java:jfield "java.lang.System" "err")
293 (handler-case (load #9# :verbose nil :print nil)
295 (format *error-output* "~A (unhandled error): ~A~%" #9# error)
296 (ext:quit :status 255))))
299 ${command} --batch --noinform --noinit --nosystem
300 --eval "${abcl-startup}"
303 ;;;----- That's all, folks --------------------------------------------------