-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathschum.lisp
317 lines (268 loc) · 9.27 KB
/
schum.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
(FILEHEADER SCHUM)
(PRINT '(SCHUM PROGRAMMING SYSTEM))
(PRINT '(VERSION 2))
(DEFINEQ
(ASN
(LAMBDA NIL
(SPUSH 'ASN1)
(SETQ **EXP** (CADDR **EXP**))
(SETQ **PC** 'SEVAL)))
(ASN1
(LAMBDA NIL
(PROG ((B (VARBDG (CADR **EXP**) **ENV**)))
(COND (B (VAL:BDG:SET B **VAL**))
((SET (CADR **EXP**) **VAL**)))
(SPOP))))
(BDG
(LAMBDA (VAR VAL) (LIST VAR VAL)))
(BDGS:ENV
(LAMBDA (E) E))
(BLOCK
(LAMBDA NIL
(PROG ((BVARS (CADR **EXP**)) VARS VALS)
LOOP (COND (BVARS (PUSH (POP BVARS) VARS)
(PUSH (POP BVARS) VALS)
(GO LOOP)))
(SETQ VARS (REVERSE VARS))
(SETQ VALS (REVERSE VALS))
(SETQ **ENV**
(VARSBIND VARS
(MAPCAR VALS '(LAMBDA (X) NIL))
**ENV**))
(SETQ **ARGS** VALS)
(SETQ **ARGVALS** (BDGS:ENV **ENV**))
(SETQ **PC** 'REC-EVLIS))))
(BODY:LAMBDA-EXP
(LAMBDA (X) (CADDR X)))
(CLOSURE
(LAMBDA (FUN ENV) (LIST 'CLOSURE FUN ENV)))
(DEF
(NLAMBDA L
(SET (CAR L)
(CLOSURE
(LAMBDA-EXP (CADR L) (CDDR L))
(EMPTY-ENV)))
(CAR L)))
(EMPTY-ENV
(LAMBDA NIL NIL))
(ENV
(LAMBDA (BDGS) BDGS))
(ENV:CLOSURE
(LAMBDA (X) (CADDR X)))
(ERROR
(LAMBDA (X) (PRINT X) NIL))
(EVLIS0
[LAMBDA NIL
(COND (**ARGS**
(SPUSH 'EVLIS1)
(SETQ **EXP** (CAR **ARGS**))
(SETQ **PC** 'SEVAL))
(T (SETQ **ARGVALS** (REVERSE **ARGVALS**))
(SETQ **ARGS** (POP **ARGVALS**))
(SETQ **PC** 'SCHAPPLY])
(EVLIS1
(LAMBDA NIL
(SETQ **ARGVALS** (CONS **VAL** **ARGVALS**))
(SETQ **ARGS** (CDR **ARGS**))
(SETQ **PC** 'EVLIS0)))
(EVSEQ
[LAMBDA NIL
(COND (**ARGS**
(COND ((CDR **ARGS**) (SPUSH 'EVSEQ1)))
(SETQ **EXP** (CAR **ARGS**))
(SETQ **PC** 'SEVAL))
((SPOP])
(EVSEQ1
(LAMBDA NIL (SETQ **ARGS** (CDR **ARGS**)) (SETQ **PC** 'EVSEQ)))
(FRAME
(LAMBDA (EXP ENV PC ARGS ARGVALS SUPER)
(NCONC (LIST EXP ENV PC ARGS ARGVALS) SUPER)))
(FRAME:LABEL-FUNCTION
(LAMBDA (X) (CADR X)))
(FUN:APPL
(LAMBDA (X) (CAR X)))
(FUN:CLOSURE
(LAMBDA (X) (CADR X)))
(GETL
[LAMBDA (F)
(OR (GETPROP F 'SCHUMRES)
(AND (LISTP (SETQ F (GETD F)))
(SELECTQ (CAR F) (NLAMBDA F) (FSUBR F) NIL])
(IF0
(LAMBDA NIL (SETQ **ARGS** (CDR **EXP**)) (SETQ **PC** 'IF1)))
(IF1
[LAMBDA NIL
(COND (**ARGS**
(COND ((OR (CDR **ARGS**) (CDAR **ARGS**))
(SPUSH 'IF2)))
(SETQ **EXP** (CAAR **ARGS**))
(SETQ **PC** 'SEVAL))
(T (SETQ **VAL** NIL) (SPOP])
(IF2
[LAMBDA NIL
(COND (**VAL**
(SETQ **ARGS** (CDAR **ARGS**))
(SETQ **PC** 'EVSEQ))
(T (SETQ **ARGS** (CDR **ARGS**))
(SETQ **PC** 'IF1])
(IS-CLOSURE
(LAMBDA (X) (EQ 'CLOSURE (CAR X))))
(IS-LABEL-FUNCTION
(LAMBDA (X) (EQ 'LABEL-FUNCTION (CAR X))))
(IS-PRIMOP
(LAMBDA (F)
(AND (LISTP (SETQ F (GETD F)))
(SELECTQ (CAR F) (SUBR F) (LAMBDA F) NIL))))
(LABEL-FUNCTION
(LAMBDA (FRAME) (LIST 'LABEL-FUNCTION FRAME)))
(LAMBDA-EXP
(LAMBDA (VARS BODY) (LIST '\ VARS BODY)))
(MAPCAR2
[LAMBDA (F L1 L2)
(COND ((NULL L1) NIL)
(T (CONS (APPLY F (LIST (CAR L1) (CAR L2)))
(MAPCAR2 F (CDR L1) (CDR L2])
(MLOOP
[LAMBDA NIL
(PROG NIL
LOOP (COND (**PC** (APPLY **PC** NIL) (GO LOOP))
((RETURN **VAL**])
(POP
[NLAMBDA ($POP$)
(PROG (($POP (EVAL $POP$)))
(SET $POP$ (CDR $POP))
(RETURN (CAR $POP])
(PUSH
[NLAMBDA ($PUSH$ $PUSH)
(CAR (SET $PUSH (CONS (EVAL $PUSH$) (EVAL $PUSH])
(REC-EVLIS
[LAMBDA NIL
(COND (**ARGS**
(SPUSH 'REC-EVLIS1)
(SETQ **EXP** (CAR **ARGS**))
(SETQ **PC** 'SEVAL))
(T (SETQ **ARGS** (CDDR **EXP**))
(SETQ **PC** 'EVSEQ])
(REC-EVLIS1
(LAMBDA NIL
(VAL:BDG:SET (POP **ARGVALS**) **VAL**)
(SETQ **ARGS** (CDR **ARGS**))
(SETQ **PC** 'REC-EVLIS)))
(SCHAPPLY
[LAMBDA NIL
(COND ((ATOM **ARGS**)
(SETQ **VAL** (APPLY **ARGS** **ARGVALS**))
(SPOP))
((IS-CLOSURE **ARGS**)
(SETQ **ENV**
(VARSBIND
(VARS:LAMBDA-EXP (FUN:CLOSURE **ARGS**))
**ARGVALS**
(ENV:CLOSURE **ARGS**)))
(SETQ **ARGS**
(BODY:LAMBDA-EXP (FUN:CLOSURE **ARGS**)))
(SETQ **PC** 'EVSEQ))
((IS-LABEL-FUNCTION **ARGS**)
(SETQ **VAL** (CAR **ARGVALS**))
(SETQ **STACK** (FRAME:LABEL-FUNCTION **ARGS**))
(SPOP))
((ERROR "BAD FUNCTION"])
(SCHUM
[LAMBDA NIL
(PROG (R)
LOOP (PRINT 'SCHUM)
[SETQ R (PRINT (SCHUMVAL (READ]
(AND (NEQ R 'LISP) (GO LOOP])
(SCHUMVAL
[LAMBDA (**EXP**)
(PROG ((**ENV** **ENV**)
(**PC** 'SEVAL)
**ARGS** **ARGVALS**
(**STACK** (FRAME NIL NIL NIL NIL NIL NIL)))
(RETURN (MLOOP])
(SEVAL
[LAMBDA NIL
(PROG (TEMP)
(COND ((ATOM **EXP**)
(COND ((OR (NUMBERP **EXP**)
(IS-PRIMOP **EXP**))
(SETQ **VAL** **EXP**))
((SETQ TEMP (VARBDG **EXP** **ENV**))
(SETQ **VAL** (VAL:BDG TEMP)))
((ERRORSET
'(SETQ **VAL** (EVAL **EXP**))
NIL))
((ERROR "UNBOUND VARIABLE")))
(SPOP))
[(AND (ATOM (FUN:APPL **EXP**))
(GETL (FUN:APPL **EXP**)))
(COND ((SETQ TEMP
(GETPROP
(FUN:APPL **EXP**)
'SCHUMRES))
(SETQ **PC** TEMP))
((GETD (FUN:APPL **EXP**))
(SETQ **VAL** (EVAL **EXP**))
(SPOP]
(T (SETQ **ARGVALS** NIL)
(SETQ **ARGS** **EXP**)
(SETQ **PC** 'EVLIS0])
(SLABEL
(LAMBDA NIL
(SETQ **ENV**
(VARSBIND
(LIST (CADR **EXP**))
(LIST (LABEL-FUNCTION **STACK**))
**ENV**))
(SETQ **ARGS** (CDDR **EXP**))
(SETQ **PC** 'EVSEQ)))
(SPOP
[LAMBDA NIL
(COND (**STACK**
(SETQ **EXP** (POP **STACK**))
(SETQ **ENV** (POP **STACK**))
(SETQ **PC** (POP **STACK**))
(SETQ **ARGS** (POP **STACK**))
(SETQ **ARGVALS** (POP **STACK**)))
(T (ERROR "BLEW STACK"])
(SPUSH
(LAMBDA (TAG)
(SETQ **STACK**
(FRAME **EXP** **ENV** TAG **ARGS** **ARGVALS** **STACK**))))
(VAL:BDG
(LAMBDA (X) (CADR X)))
(VAL:BDG:SET
(LAMBDA (X V) (RPLACA (CDR X) V)))
(VARBDG
(LAMBDA (V E) (ASSOC V E)))
(VARS:ENV
(LAMBDA (E) (MAPCAR E 'CAR)))
(VARS:LAMBDA-EXP
(LAMBDA (X) (CADR X)))
(VARSBIND
[LAMBDA (VARS VALS ENV)
(COND ((EQUAL (LENGTH VARS) (LENGTH VALS))
(NCONC (MAPCAR2 'BDG VARS VALS) ENV))
(T (ERROR "WRONG NUMBER OF ARGUMENTS"])
(\
(NLAMBDA L (CLOSURE (LAMBDA-EXP (CAR L) (CDR L)) **ENV**)))
)
(PRINT 'SCHUMFNS)
(RPAQQ SCHUMFNS
(ASN ASN1 BDG BDGS:ENV BLOCK BODY:LAMBDA-EXP CLOSURE DEF EMPTY-ENV ENV
ENV:CLOSURE ERROR EVLIS0 EVLIS1 EVSEQ EVSEQ1 FRAME
FRAME:LABEL-FUNCTION FUN:APPL FUN:CLOSURE GETL IF0 IF1 IF2
IS-CLOSURE IS-LABEL-FUNCTION IS-PRIMOP LABEL-FUNCTION LAMBDA-EXP
MAPCAR2 MLOOP POP PUSH REC-EVLIS REC-EVLIS1 SCHAPPLY SCHUM
SCHUMVAL SEVAL SLABEL SPOP SPUSH VAL:BDG VAL:BDG:SET VARBDG
VARS:ENV VARS:LAMBDA-EXP VARSBIND \))
(RPAQQ SCHUMCOMS (SCHUM PROGRAMMING SYSTEM))
(RPAQ SCHUMGENNR 2)
(PRINT 'SCHUMVARS)
(RPAQQ SCHUMVARS
((P (SETQ **ENV** (EMPTY-ENV)))
(PROP SCHUMRES ASN IF0 BLOCK LABEL)))
(SETQ **ENV** (EMPTY-ENV))
(DEFLIST '((ASN ASN) (IF0 IF0) (BLOCK BLOCK) (LABEL SLABEL))
'SCHUMRES)
STOP