Simpler. But also broken! I can feel the abyss peering back...
Cat's Eye Technologies
11 years ago
0 | 0 | #!/bin/sh |
1 | 1 | |
2 | # A wrapper script around miniscm (my fork) to get it to behave more or less | |
3 | # how we want. | |
2 | # Support the miniscm-0.85p1 Scheme implementation as if it behaved like | |
3 | # plt-r5rs behaves, i.e.: | |
4 | ||
5 | # % echo '(+ 1 2)' > program.scm | |
6 | # % miniscm.sh program.scm | |
7 | # 3 | |
8 | # % | |
9 | ||
10 | # Some caveats apply (Protip: some caveats *always* apply.) | |
4 | 11 | |
5 | 12 | cat >init.scm <<EOF |
6 | 13 | (define (equal? x y) |
13 | 20 | (define (list? x) (or (eq? x '()) (and (pair? x) (list? (cdr x))))) |
14 | 21 | EOF |
15 | 22 | |
16 | miniscm -q -e <$1 | |
23 | echo "(display" >tmpprog.scm | |
24 | cat $1 >>tmpprog.scm | |
25 | echo ") (newline)" >>tmpprog.scm | |
26 | ||
27 | miniscm -q -e <tmpprog.scm | |
28 | ||
29 | rm -f tmpprog.scm |
0 | 0 | #!/bin/sh |
1 | 1 | |
2 | # A wrapper script around tinyscheme to get it to behave more or less | |
3 | # how we want. | |
2 | # Support the tinyscheme Scheme implementation as if it behaved like | |
3 | # plt-r5rs behaves, i.e.: | |
4 | 4 | |
5 | cat >init.scm <<EOF | |
6 | (define (equal? x y) | |
7 | (if (pair? x) | |
8 | (and (pair? y) | |
9 | (equal? (car x) (car y)) | |
10 | (equal? (cdr x) (cdr y))) | |
11 | (and (not (pair? y)) | |
12 | (eqv? x y)))) | |
13 | (define (list? x) (or (eq? x '()) (and (pair? x) (list? (cdr x))))) | |
14 | EOF | |
5 | # % echo '(+ 1 2)' > program.scm | |
6 | # % tinyscheme.sh program.scm | |
7 | # 3 | |
8 | # % | |
15 | 9 | |
16 | tinyscheme $1 | |
10 | # Note: if tinyscheme is installed from source, the executable's name | |
11 | # will be 'scheme' and it will require 'init.scm' in the current | |
12 | # directory. However, if it is installed from a package (using apt-get,) the | |
13 | # executable's name will be 'tinyscheme' and it will not require 'init.scm' | |
14 | # in the current directory. Just one of those cases where the package | |
15 | # managers decide to try to make your life easier by making things obstensibly | |
16 | # saner while at the same time introducing an incompatibility. | |
17 | # | |
18 | # This wrapper assumes you have installed it from a package. | |
19 | ||
20 | echo "(display" >tmpprog.scm | |
21 | cat $1 >>tmpprog.scm | |
22 | echo ") (newline)" >>tmpprog.scm | |
23 | ||
24 | tinyscheme tmpprog.scm | |
25 | ||
26 | rm -f tmpprog.scm |
35 | 35 | ### Initialization ### |
36 | 36 | |
37 | 37 | SCHEME_CMD=$SCHEME_IMPL # command to run for impl |
38 | CAN_EVAL=yes # impl can eval s-exprs as Scheme progs? | |
39 | EXPLICIT_QUIT=no # impl needs explicit (quit) to stop? | |
40 | NEED_EQUAL_P=no # impl lacks `equal?` | |
41 | NEED_LIST_P=no # impl lacks `list?` | |
42 | 38 | NEED_DUMP_SEXP=no # impl needs extra support to write s-exp? |
43 | 39 | |
44 | 40 | if [ "${SCHEME_IMPL}x" = "plt-r5rsx" ]; then |
51 | 47 | # don't expect. To work around this, this script prepends a |
52 | 48 | # definition of a function "dump-sexp" which explicitly formats |
53 | 49 | # the resulting S-expression in the way the tests do expect. |
54 | SCHEME_CMD='script/tinyscheme.sh' | |
50 | # | |
55 | 51 | NEED_DUMP_SEXP=yes |
56 | 52 | elif [ "${SCHEME_IMPL}x" = "miniscmx" ]; then |
57 | 53 | # Mini-Scheme is supported, but version 0.85p1 (a fork available |
61 | 57 | # miniscm's core lacks "equal?" and "list?", so definitions for |
62 | 58 | # those are also prepended to the source we want to run. |
63 | 59 | SCHEME_CMD='script/miniscm.sh' |
64 | NEED_DUMP_SEXP=yes | |
65 | 60 | else |
66 | 61 | echo "Please set SCHEME_IMPL to one of the following:" |
67 | 62 | echo "plt-r5rs, tinyscheme, miniscm" |
76 | 71 | ### Generate prelude ### |
77 | 72 | |
78 | 73 | echo -n '' >prelude.scm |
79 | ||
80 | if [ "$NEED_EQUAL_P" = "yes" ]; then | |
81 | # define `equal?` in Scheme. written by a.k. | |
82 | cat >>prelude.scm <<EOF | |
83 | (define (equal? x y) | |
84 | (if (pair? x) | |
85 | (and (pair? y) | |
86 | (equal? (car x) (car y)) | |
87 | (equal? (cdr x) (cdr y))) | |
88 | (and (not (pair? y)) | |
89 | (eqv? x y)))) | |
90 | EOF | |
91 | fi | |
92 | ||
93 | if [ "$NEED_LIST_P" = "yes" ]; then | |
94 | # define `list?` in Scheme. written by c.p. | |
95 | cat >>prelude.scm <<EOF | |
96 | (define (list? x) (or (eq? x '()) (and (pair? x) (list? (cdr x))))) | |
97 | EOF | |
98 | fi | |
99 | 74 | |
100 | 75 | if [ "$NEED_DUMP_SEXP" = "yes" ]; then |
101 | 76 | # extra support to dump a sexp (without abbreviating stuff) |
143 | 118 | cat >>program.scm <<EOF |
144 | 119 | (display tower) |
145 | 120 | EOF |
146 | if [ "${EXPLICIT_QUIT}" = "yes" ]; then | |
147 | echo '(quit)' >>program.scm | |
148 | fi | |
149 | 121 | |
150 | 122 | if [ ! "${DEBUG}x" = "x" ]; then |
151 | 123 | less program.scm |
162 | 134 | ${SCHEME_CMD} program.scm >>next.scm |
163 | 135 | echo ') (newline)' >>next.scm |
164 | 136 | fi |
165 | if [ "${EXPLICIT_QUIT}" = "yes" ]; then | |
166 | echo '(quit)' >>next.scm | |
167 | fi | |
168 | 137 | |
169 | 138 | mv next.scm program.scm |
170 | 139 | ${SCHEME_CMD} program.scm |