chiark / gitweb /
Makefile.am: Rearrange the `dump-runlisp-image' options.
[runlisp] / toy-runlisp
1 #! /bin/sh -e
2
3 case $# in
4   0 | 1) echo >&2 "usage: $0 LISP SCRIPT [ARGS ...]"; exit 127 ;;
5 esac
6 lisp=$1 script=$2; shift 2
7
8 __CL_ARGV0=$script; export __CL_ARGV0 # this is stupid
9
10 lispscript=$(printf "%s" "$script" | sed 's/[\"]/\\&/g')
11
12 load_asdf_rune="\
13 (let ((*load-verbose* nil)
14       #+cmu (ext:*require-verbose* nil))
15   (require \"asdf\"))"
16
17 ignore_shebang_rune="\
18 (set-dispatch-macro-character
19  #\# #\!
20  (lambda (stream char arg)
21    (declare (ignore char arg))
22    (values (read-line stream))))"
23
24 clisp_startup_rune="\
25 (progn
26   $ignore_shebang_rune
27   $load_asdf_rune
28   (setf *standard-input* (ext:make-stream :input))
29   (load \"$lispscript\" :verbose nil :print nil)
30   (ext:quit))"
31
32 abcl_startup_rune="\
33 (let ((script \"$lispscript\"))
34   $load_asdf_rune
35   $ignore_shebang_rune
36   (setf *error-output*
37           (java:jnew \"org.armedbear.lisp.Stream\"
38                      'sys::system-stream
39                      (java:jfield \"java.lang.System\" \"err\")
40                      'character
41                      java:+true+))
42   (handler-case (load script :verbose nil :print nil)
43     (error (error)
44       (format *error-output* \"~A (unhandled error): ~A~%\" script error)
45     (ext:quit :status 255))))"
46
47 #set -x
48 case $lisp in
49
50   sbcl)
51     exec sbcl --noinform --eval "$load_asdf_rune" --script "$script" "$@"
52     ;;
53
54   ecl)
55     exec ecl --norc --eval "$load_asdf_rune" --shell "$script" -- "$@"
56     ;;
57
58   clisp)
59     exec clisp -norc -q -x "$clisp_startup_rune" -- "$@"
60     ;;
61
62   cmucl)
63     exec cmucl -batch -noinit -nositeinit -quiet \
64          -eval "$load_asdf_rune" \
65          -eval "$ignore_shebang_rune" \
66          -load "$script" -eval "(ext:quit)" -- "$@"
67     ;;
68
69   ccl)
70     exec ccl -b -n -Q \
71          -e "$load_asdf_rune" \
72          -e "$ignore_shebang_rune" \
73          -l "$script" -e "(ccl:quit)" -- "$@"
74     ;;
75
76   abcl)
77     exec abcl --batch --noinform --noinit --nosystem \
78          --eval "$abcl_startup_rune" -- "$@"
79     ;;
80
81   *)
82     echo >&2 "$0: unsupported Lisp \`$lisp'"
83     exit 127
84     ;;
85 esac