-
Notifications
You must be signed in to change notification settings - Fork 2
/
run-lisp
executable file
·341 lines (324 loc) · 10.2 KB
/
run-lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
#! /bin/sh
# -----------------------------------------------------------------------------
# Title: A script to invoke the various CL implementations in a uniform way
# Created: 1999-01-16 16:41
# Author: Gilbert Baumann <[email protected]>
# License: LGPL (See file GNU-LGPL for details)
# -----------------------------------------------------------------------------
# (c) copyright 1999 by Gilbert Baumann, Sam Steingold, Bruno Haible
# $CLOCC-Id: run-lisp,v 1.15 2001/12/14 19:06:01 sds Exp $
# $CLOCC-Source: /cvsroot/clocc/clocc/bin/run-lisp,v $
# Prior to invocation the LISPTYPE environment variable must been set to
# one of these:
#
# clisp uses ${CLISP} if set, else "clisp"
# cmucl uses ${CMUCL} if set, else "lisp"
# acl43 uses ${ACL43} if set, else "cl"
# acl5 uses ${ACL5} if set, else "cl"
# gcl uses ${GCL} if set, else "gcl"
# sbcl uses ${SBCL} if set, else "sbcl"
usage(){
cat <<\EOF
Usage:
run-lisp [clause ...] [argument ...]
clause ::= -i file ; load file `file'
| -c file ; compile file `file'
| -x form ; execute form `form'
| -I image ; use image file `image'
| -d image ; dump to image `image'
| --safety n ; set safety level for compilation
| --speed n ; set speed level for compilation
Note: Lisp specific extensions (e.g. .dxl on ACL or .mem for CLISP)
are not to be included into the image argument
Anything else is stuffed into the Lisp variable 'argv', which is
available in the lexical environment forms given to -x are
evaluated in.
run-lisp -run image
interactively run `image'
(user:run) will be called upon start up.
Makefile support
run-lisp -faslext
echo the fasload file extension to stdout.
This is useful for Makefile; you could then say e.g.
FAS:=$(shell $(TOP)/bin/run-lisp -faslext)
run-lisp -dumpext
echo the memory image extension _with_ dot.
usage: (like above)
DUMP:=$(shell $(TOP)/bin/run-lisp -dumpext)
run-lisp -cat [fasl-file ...]
Cat all the given fasl files together.
EXAMPLE
$ run-lisp -x "(print argv)" foo bar baz "Hallo Welt" foo\"bar
("foo" "bar" "baz" "Hallo Welt" "foo\"bar")
$
EOF
exit 0;
}
fail(){
echo "$0: $*" 1>&2
exit 1
}
case "$1" in
"--help" | "-h" | "-?" )
usage
;;
"-cat" )
shift
case "$LISPTYPE" in
clisp | cmucl | acl43 | acl5 | sbcl)
cat "$@"
;;
* )
fail "Sorry, option -cat not supported for LISPTYPE=${LISPTYPE}."
;;
esac
;;
"-faslext" )
# (pathname-type (compile-file-pathname "foo.lisp"))
shift
case "$LISPTYPE" in
clisp )
# This is (pathname-type (car (system::*compiled-file-types*))).
echo 'fas'
;;
cmucl )
# This can be found via
# (c:backend-fasl-file-type c:*target-backend*),
# but for speed we look at the uname first.
case `uname -m 2>/dev/null` in
i[3-6]86 )
echo 'x86f'
;;
* )
# Call .
${CMUCL-lisp} -noinit \
-eval "(progn \
(write-string (c:backend-fasl-file-type c:*target-backend*))
(terpri)
(ext:quit 0))"
;;
esac
;;
acl43 | acl5 )
echo 'fasl'
;;
gcl )
echo 'o' # but also 'data' on same platforms
;;
sbcl )
echo 'fasl'
;;
* )
# Since make does not stop when the exit status is 1, we simply
# echo LISPTYPE_NOT_SET here.
echo LISPTYPE_NOT_SET
fail "Sorry, option -faslext not supported for LISPTYPE=${LISPTYPE}."
;;
esac
;;
"-dumpext" )
shift 1
case "$LISPTYPE" in
clisp)
echo .mem
;;
acl43)
echo ""
;;
acl5)
echo .dxl
;;
cmucl)
echo .core
;;
sbcl)
echo .core
;;
*)
# Since make does not stop when the exit status is 1, we simply
# echo LISPTYPE_NOT_SET here.
echo LISPTYPE_NOT_SET
fail "Sorry, option -dumpext not supported for LISPTYPE=${LISPTYPE}."
;;
esac
;;
"-run" )
# we special case on '-run' for now
shift 1
case "$LISPTYPE" in
clisp)
${CLISP-clisp} -M "$1".mem
;;
cmucl )
${CMUCL-lisp} -core "$1".core
;;
acl43 )
# Why "$1"? ACL4.3 dumps executables
"$1" -e '(unwind-protect (run) (excl:exit))'
;;
acl5 )
${ACL5-cl} -I "$1".dxl -e '(unwind-protect (run) (excl:exit))'
;;
gcl )
"$1" -eval '(run)'
;;
sbcl )
${SBCL:-sbcl} -core "$1".core
;;
*)
fail "Sorry, option -run not supported for LISPTYPE=${LISPTYPE}."
;;
esac
;;
* )
# Multiple arguments.
unset image
todo="" # list of forms to execute
args="" # list of arguments (strings) to pass
while [ $# != 0 ]; do
case "$1" in
-i)
if [ $# = 1 ]; then
fail "missing argument for $1"
fi
shift
backslashify='s,\(["\\]\),\\\1,g'
arg=`echo "$1" | sed -e "$backslashify"`
todo=$todo" (load \"${arg}\")"
shift
;;
-x)
if [ $# = 1 ]; then
fail "missing argument for $1"
fi
shift
todo=$todo" $1"
shift
;;
-c)
if [ $# = 1 ]; then
fail "missing argument for $1"
fi
shift
backslashify='s,\(["\\]\),\\\1,g'
arg=`echo "$1" | sed -e "$backslashify"`
# todo=$todo" (compile-file \"${arg}\" :print nil)"
# truename helps, when using Franz' emacs interface
todo=$todo" (compile-file (truename \"${arg}\") :print nil)"
shift
;;
-I)
if [ $# = 1 ]; then
fail "missing argument for $1"
fi
shift
image="$1"
shift
;;
-d)
if [ $# = 1 ]; then
fail "missing argument for $1"
fi
shift
backslashify='s,\(["\\]\),\\\1,g'
arg=`echo "$1" | sed -e "$backslashify"`
case "$LISPTYPE" in
clisp )
todo=$todo" (#+lisp=cl ext:saveinitmem #-lisp=cl lisp:saveinitmem \"${arg}.mem\")"
;;
cmucl )
todo=$todo" (ext:save-lisp \"${arg}.core\")"
;;
acl43 )
todo=$todo" (excl:dumplisp :name \"${arg}\")"
;;
acl5 )
todo=$todo" (excl:dumplisp :name \"${arg}.dxl\")"
;;
gcl )
todo=$todo" (si:save-system \"${arg}\")"
;;
sbcl )
todo=$todo" (sb-ext:save-lisp-and-die \"${arg}.core\")"
;;
* )
fail "Sorry, option -d not supported for LISPTYPE=${LISPTYPE}."
;;
esac
shift
;;
--safety)
if [ $# = 1 ]; then
fail "missing argument for $1"
fi
shift 1
todo=$todo" (proclaim (quote (optimize (safety "$1"))))"
shift 1
;;
--speed)
if [ $# = 1 ]; then
fail "missing argument for $1"
fi
shift 1
todo=$todo" (proclaim (quote (optimize (speed "$1"))))"
shift 1
;;
*)
backslashify='s,\(["\\]\),\\\1,g'
arg=`echo "$1" | sed -e "$backslashify"`
args=$args" \"${arg}\""
shift
;;
esac
done
# done with collecting the arguments
todo="(progn${todo})"
args="(${args})"
todo="(let ((argv '$args)) (declare (ignorable argv)) $todo (values))"
case "$LISPTYPE" in
clisp )
todo="(progn (setq #+lisp=cl ext:*load-paths* #-lisp=cl lisp:*load-paths* '(#P\"\")) ${todo})"
test -z "$image" || image="-M ${image}.mem";
exec ${CLISP-clisp} -norc -q ${image} -x "$todo"
;;
cmucl )
# we have to convince CMUCL to return a proper exit status.
todo="(let (.res (.cond t))
(unwind-protect
(multiple-value-setq (.res .cond)
(ignore-errors (progn $todo
(fresh-line) (finish-output))))
(unix:unix-exit (if .cond 1 0))))"
test -z "$image" || image="-core ${image}.core";
exec ${CMUCL-lisp} -noinit ${image} -eval "$todo"
;;
acl43 )
exec echo "$todo" | ${image-${ACL43-cl}} -batch
;;
acl5 )
test -z "$image" || image="-I ${image}.dxl";
exec echo "$todo" | ${ACL5-cl} ${image+"-I ${image}.dxl"} -batch
;;
gcl )
exec echo "$todo" | ${image-${GCL-gcl}} -batch
;;
sbcl )
# see comment for CMUCL
todo="(let (.res (.cond t))
(unwind-protect
(multiple-value-setq (.res .cond)
(ignore-errors (progn $todo
(fresh-line) (finish-output))))
(sb-ext:quit :unix-status (if .cond 1 0))))"
test -z "$image" || image="-core ${image}.core";
exec ${SBCL:-sbcl} --userinit /dev/null ${image} --eval "$todo"
;;
* )
if [ -n "$LISPTYPE" ] ; then
fail "Sorry, LISPTYPE=${LISPTYPE} is not supported"
else
fail "LISPTYPE environment variable is not set"
fi
;;
esac
esac