-
Notifications
You must be signed in to change notification settings - Fork 3
/
makstr.25
312 lines (270 loc) · 10.2 KB
/
makstr.25
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
<SETG GLOHI 1>
<SETG STAR-BITS 0>
<DEFINE CEVENT (TICK APP FLG NAME "AUX" (OBL <GET INITIAL OBLIST>) ATM)
#DECL ((TICK) FIX (APP) <OR APPLICABLE OFFSET> (FLG) <OR ATOM FALSE>
(NAME) <OR ATOM STRING> (ATM) <OR ATOM FALSE>)
<COND (<TYPE? .NAME STRING>
<COND (<SET ATM <LOOKUP .NAME .OBL>>)
(T <SET ATM <INSERT .NAME .OBL>>)>)
(<SET ATM .NAME>)>
<SETG .ATM <CHTYPE [.TICK .APP .FLG .ATM] CEVENT>>>
<DEFINE CEXIT (FLID RMID "OPTIONAL" (STR <>) (FLAG <>) (FUNCT <>) "AUX" (FVAL <>) ATM)
#DECL ((STR) <OR FALSE STRING> (FLID RMID) <OR ATOM STRING>
(ATM FUNCT) <OR ATOM FALSE> (FVAL) <OR APPLICABLE FALSE>
(FLAG) <OR ATOM FALSE>)
<COND (<TYPE? .FLID ATOM> <SET FLID <SPNAME .FLID>>)>
<SET ATM <OR <LOOKUP .FLID <GET FLAG OBLIST>>
<INSERT .FLID <GET FLAG OBLIST>>>>
<SETG .ATM .FLAG>
<CHTYPE <VECTOR .ATM <FIND-ROOM .RMID> .STR .FUNCT> CEXIT>>
<DEFINE DOOR (OID RM1 RM2 "OPTIONAL" (STR <>) (FN <>) "AUX" (OBJ <FIND-OBJ .OID>))
#DECL ((OID) STRING (STR) <OR STRING FALSE> (FN) <OR ATOM FALSE>
(OBJ) OBJECT (RM1 RM2) <OR STRING ROOM>)
<COND (<FIND-DOOR <SET RM1 <FIND-ROOM .RM1>> .OBJ>)
(<FIND-DOOR <SET RM2 <FIND-ROOM .RM2>> .OBJ>)
(<CHTYPE [.OBJ .RM1 .RM2 .STR .FN] DOOR>)>>
<DEFINE EXIT ("TUPLE" PAIRS "AUX" (DOBL ,DIRECTIONS)
(FROB <IVECTOR <LENGTH .PAIRS>>))
#DECL ((PAIRS) <TUPLE [REST STRING <OR DOOR NEXIT CEXIT STRING ATOM>]>
(DIR) <LIST [REST ATOM]> (FROB) VECTOR (DOBL) OBLIST)
<REPEAT (ATM RM (F .FROB))
#DECL ((ATM) <OR ATOM FALSE> (RM) <OR ROOM FALSE> (F) VECTOR)
<COND (<OR
<AND <SET ATM <LOOKUP <1 .PAIRS> .DOBL>>
<GASSIGNED? .ATM>
<TYPE? ,.ATM DIRECTION>>>
<PUT .F 1 .ATM>
<COND (<TYPE? <2 .PAIRS> STRING>
<PUT .F 2 <FIND-ROOM <2 .PAIRS>>>)
(<PUT .F 2 <2 .PAIRS>>)>
<SET F <REST .F 2>>)
(T
<PUT .PAIRS 1 <ERROR ILLEGAL-DIRECTION <1 .PAIRS>>>)>
<COND (<EMPTY? <SET PAIRS <REST .PAIRS 2>>>
<RETURN>)>>
<CHTYPE .FROB EXIT>>
<DEFINE ROOM (ID D1 D2 LIT? EX "OPTIONAL" (OBJS ()) (APP <>) (VAL 0) (BIT ,RLANDBIT)
(GLOB 0) "AUX" (RM <FIND-ROOM .ID>))
#DECL ((ID) <OR STRING ATOM> (D1 D2) STRING (LIT?) <OR ATOM FORM FALSE>
(EX) EXIT (APP) <OR FORM FALSE ATOM> (VAL BIT GLOB) FIX (RM) ROOM)
<SETG SCORE-MAX <+ ,SCORE-MAX .VAL>>
<PUT .RM ,RGLOBAL <+ .GLOB ,STAR-BITS>>
<PUT .RM ,RVAL .VAL>
<PUT .RM ,ROBJS .OBJS>
<PUT .RM ,RDESC1 .D1>
<PUT .RM ,RDESC2 .D2>
<PUT .RM ,REXITS .EX>
<PUT .RM ,RACTION <COND (<TYPE? .APP FALSE FORM> <>) (.APP)>>
<COND (<TYPE? .LIT? FALSE FORM>) (ELSE <SET BIT <+ .BIT ,RLIGHTBIT>>)>
<MAPF <>
<FUNCTION (X) #DECL ((X) OBJECT)
<PUT .X ,OROOM .RM>>
<ROBJS .RM>>
<PUT .RM ,RBITS .BIT>
.RM>
<DEFINE SOBJECT (ID STR "TUPLE" TUP)
#DECL ((ID) STRING (TUP) TUPLE)
<OBJECT .ID "" .STR %<> <> () <> <+ !.TUP>>>
<DEFINE AOBJECT (ID STR APP "TUPLE" TUP)
#DECL ((ID) STRING (TUP) TUPLE (APP) ATOM)
<OBJECT .ID "" .STR %<> .APP () <> <+ !.TUP>>>
<DEFINE GOBJECT (IDS STR APP NAM "TUPLE" TUP "AUX" (OBJOB ,OBJECT-OBL) OBJ)
#DECL ((IDS) <VECTOR [REST STRING]> (STR) STRING (APP) <OR ATOM FALSE>
(TUP) TUPLE (OBJ) OBJECT (OBJOB) OBLIST (NAM) <OR FALSE ATOM>)
<SET OBJ <OBJECT <1 .IDS> "" .STR %<> .APP () <> <+ !.TUP>>>
<PUT .OBJ ,OGLOBAL <SETG GLOHI <* ,GLOHI 2>>>
<AND .NAM <SETG .NAM ,GLOHI>>
<MAPF <>
<FUNCTION (X)
#DECL ((X) STRING)
<SETG <OR <LOOKUP .X .OBJOB>
<INSERT .X .OBJOB>> .OBJ>>
<REST .IDS>>
.OBJ>
<DEFINE OBJECT (ID DESC1 DESC2 DESCO APP CONTS CAN FLAGS
"OPTIONAL" (S1 0) (S2 0) (SIZE 5) (CAPAC 0)
"AUX" (OBJ <FIND-OBJ .ID>))
#DECL ((ID) <OR ATOM STRING> (DESC1 DESC2) STRING (APP) <OR FALSE FORM ATOM>
(CONTS) <LIST [REST OBJECT]> (CAN) <OR FALSE OBJECT>
(FLAGS) <PRIMTYPE WORD> (SIZE CAPAC) FIX (OBJ) OBJECT
(S1 S2) FIX (DESCO) <OR STRING FALSE>)
<SETG SCORE-MAX <+ ,SCORE-MAX .S1 .S2>>
<PUT .OBJ ,ODESC1 .DESC1>
<PUT .OBJ ,ODESC2 .DESC2>
<PUT .OBJ ,ODESCO .DESCO>
<PUT .OBJ ,OACTION <COND (<TYPE? .APP FALSE FORM> <>) (.APP)>>
<PUT .OBJ ,OCONTENTS .CONTS>
<PUT .OBJ ,OCAN .CAN>
<PUT .OBJ ,OFLAGS .FLAGS>
<PUT .OBJ ,OFVAL .S1>
<PUT .OBJ ,OTVAL .S2>
<PUT .OBJ ,OSIZE .SIZE>
<PUT .OBJ ,OCAPAC .CAPAC>>
<DEFINE FIND-PREP (STR "AUX" (ATM <ADD-WORD .STR>))
#DECL ((STR) STRING (ATM) <OR FALSE ATOM>)
<COND (<GASSIGNED? .ATM>
<COND (<TYPE? ,.ATM PREP> ,.ATM)
(<ERROR NO-PREP!-ERRORS>)>)
(<SETG .ATM <CHTYPE .ATM PREP>>)>>
<DEFINE ADD-ACTION (NAM STR "TUPLE" DECL
"AUX" (ATM <OR <LOOKUP .NAM ,ACTIONS>
<INSERT .NAM ,ACTIONS>>))
#DECL ((NAM STR) STRING (DECL) <TUPLE [REST VECTOR]> (ATM) ATOM)
<SETG .ATM <CHTYPE [.ATM <MAKE-ACTION !.DECL> .STR] ACTION>>
.ATM>
<DEFINE ADD-DIRECTIONS ("TUPLE" NMS "AUX" (DIR ,DIRECTIONS) ATM)
#DECL ((NMS) <TUPLE [REST STRING]> (DIR) OBLIST (ATM) ATOM)
<MAPF <> <FUNCTION (X) <SETG <SET ATM <OR <LOOKUP .X .DIR> <INSERT .X .DIR>>>
<CHTYPE .ATM DIRECTION>>>
.NMS>>
<DEFINE DSYNONYM (STR "TUPLE" NMS "AUX" VAL (DIR ,DIRECTIONS) ATM)
#DECL ((ATM) ATOM (STR) STRING (NMS) <TUPLE [REST STRING]>
(VAL) DIRECTION (DIR) OBLIST)
<SET VAL <ADD-DIRECTIONS .STR>>
<MAPF <> <FUNCTION (X) <SETG <SET ATM <OR <LOOKUP .X .DIR> <INSERT .X .DIR>>>
.VAL>>
.NMS>>
<DEFINE VSYNONYM (N1 "TUPLE" N2 "AUX" ATM VAL)
#DECL ((N1) STRING (N2) <TUPLE [REST STRING]> (ATM) <OR FALSE ATOM>
(VAL) ANY)
<COND (<SET ATM <LOOKUP .N1 ,WORDS>>
<SET VAL ,.ATM>
<MAPF <> <FUNCTION (X) <SETG <ADD-WORD .X> .VAL>> .N2>)>
<COND (<SET ATM <LOOKUP .N1 ,ACTIONS>>
<SET VAL ,.ATM>
<MAPF <> <FUNCTION (X) <SETG <OR <LOOKUP .X ,ACTIONS>
<INSERT .X ,ACTIONS>>
.VAL>> .N2>)>>
"STUFF FOR ADDING TO VOCABULARY, ADDING TO LISTS (OF DEMONS, FOR EXAMPLE)."
<DEFINE ADD-WORD (W)
#DECL ((W) STRING)
<OR <LOOKUP .W ,WORDS> <INSERT .W ,WORDS>>>
<DEFINE ADD-BUZZ ("TUPLE" W)
#DECL ((W) <TUPLE [REST STRING]>)
<MAPF <>
<FUNCTION (X)
#DECL ((X) STRING)
<SETG <ADD-WORD .X> <CHTYPE .X BUZZ>>>
.W>>
<DEFINE ADD-ZORK (NM "TUPLE" W)
#DECL ((NM) ATOM (W) <TUPLE [REST STRING]>)
<MAPF <>
<FUNCTION (X "AUX" ATM)
#DECL ((X) STRING (ATM) ATOM)
<SETG <SET ATM <ADD-WORD .X>> <CHTYPE .ATM .NM>>>
.W>>
<DEFINE ADD-OBJECT (OBJ NAMES "OPTIONAL" (ADJ '[]) "AUX" (OBJS ,OBJECT-OBL))
#DECL ((OBJ) OBJECT (NAMES ADJ) <VECTOR [REST STRING]> (OBJS) OBLIST)
<PUT .OBJ
,ONAMES
<MAPF ,UVECTOR
<FUNCTION (X)
#DECL ((X) STRING)
<OR <LOOKUP .X .OBJS> <INSERT .X .OBJS>>>
.NAMES>>
<PUT .OBJ ,OADJS <MAPF ,UVECTOR <FUNCTION (W) <ADD-ZORK ADJECTIVE .W>> .ADJ>>
<CHUTYPE <OADJS .OBJ> ADJECTIVE>
.OBJ>
<DEFINE SYNONYM (N1 "TUPLE" N2 "AUX" ATM VAL)
#DECL ((N1) STRING (N2) <TUPLE [REST STRING]> (ATM) <OR FALSE ATOM>
(VAL) ANY)
<COND (<SET ATM <LOOKUP .N1 ,WORDS>>
<SET VAL ,.ATM>
<MAPF <> <FUNCTION (X) <SETG <ADD-WORD .X> .VAL>> .N2>)>>
<DEFINE ADD-ABBREV (X Y "AUX")
#DECL ((X Y) STRING)
<SETG <ADD-WORD .X> <OR <LOOKUP .Y ,WORDS> <INSERT .Y ,WORDS>>>>
<DEFINE ADD-DEMON (X) #DECL ((X) HACK)
<COND (<MAPR <>
<FUNCTION (Y) #DECL ((Y) <LIST [REST HACK]>)
<COND (<==? <HACTION <1 .Y>> <HACTION .X>>
<PUT .Y 1 .X>
<MAPLEAVE T>)>>
,DEMONS>)
(<SETG DEMONS (.X !,DEMONS)>)>>
<DEFINE ADD-STAR (OBJ)
<SETG STAR-BITS <+ ,STAR-BITS <OGLOBAL .OBJ>>>>
<DEFINE ADD-ACTOR (ADV "AUX" (ACTORS ,ACTORS))
#DECL ((ADV) ADV (ACTORS) <LIST [REST ADV]>)
<COND (<MAPF <>
<FUNCTION (X) #DECL ((X) ADV)
<COND (<==? <AOBJ .X> <AOBJ .ADV>>
<MAPLEAVE T>)>>
.ACTORS>)
(<SETG ACTORS (.ADV !.ACTORS)>)>
.ADV>
<DEFINE ADD-DESC (OBJ STR)
#DECL ((OBJ) OBJECT (STR) STRING)
<PUT .OBJ ,OREAD .STR>>
<DEFINE SADD-ACTION (STR1 ATM)
<ADD-ACTION .STR1 "" [[.STR1 .ATM]]>>
<DEFINE 1ADD-ACTION (STR1 STR2 ATM)
<ADD-ACTION .STR1 .STR2 [OBJ [.STR1 .ATM]]>>
"MAKE-ACTION: Function for creating a verb. Takes;
vspec => [objspec {\"prep\"} {objspec} [atom!-WORDS fcn] extras]
objspec => OBJ | objlist
objlist => ( objbits {fwimbits} {NO-TAKE} {MUST-HAVE} {TRY-TAKE} {=} )
extras => DRIVER FLIP
Creates a VSPEC.
"
<DEFINE MAKE-ACTION ("TUPLE" SPECS "AUX" VV SUM (PREP <>) ATM)
#DECL ((SPECS) TUPLE (VV) <PRIMTYPE VECTOR> (SUM) FIX (PREP ATM) ANY)
<CHTYPE
<MAPF ,UVECTOR
<FUNCTION (SP "AUX" (SYN <VECTOR <> <> <> 0>) (WHR 1))
#DECL ((SP) VECTOR (SYN) VECTOR (WHR) FIX)
<MAPF <>
<FUNCTION (ITM)
#DECL ((ITM) ANY)
<COND (<TYPE? .ITM STRING> <SET PREP <FIND-PREP .ITM>>)
(<AND <==? .ITM OBJ> <SET ITM '(-1 ROBJS AOBJS)> <>>)
(<TYPE? .ITM LIST>
<SET VV <IVECTOR 4>>
<PUT .VV ,VBIT <1 .ITM>>
<COND (<AND <NOT <LENGTH? .ITM 1>> <TYPE? <2 .ITM> FIX>>
<PUT .VV ,VFWIM <2 .ITM>>)
(ELSE
<PUT .VV ,VBIT -1>
<PUT .VV ,VFWIM <1 .ITM>>)>
<AND <MEMQ = .ITM> <PUT .VV ,VBIT <VFWIM .VV>>>
<PUT .VV ,VPREP .PREP>
<SET SUM 0>
<SET PREP <>>
<AND <MEMQ AOBJS .ITM> <SET SUM <+ .SUM ,VABIT>>>
<AND <MEMQ ROBJS .ITM> <SET SUM <+ .SUM ,VRBIT>>>
<AND <MEMQ NO-TAKE .ITM> <SET SUM .SUM>>
<AND <MEMQ HAVE .ITM> <SET SUM <+ .SUM ,VCBIT>>>
<AND <MEMQ TRY .ITM> <SET SUM <+ .SUM ,VTBIT>>>
<AND <MEMQ TAKE .ITM> <SET SUM <+ .SUM ,VTBIT ,VCBIT>>>
<PUT .VV ,VWORD .SUM>
<PUT .SYN .WHR <CHTYPE .VV VARG>>
<SET WHR <+ .WHR 1>>)
(<TYPE? .ITM VECTOR>
<COND (<GASSIGNED? <SET ATM <ADD-WORD <1 .ITM>>>>
<PUT .SYN ,SFCN ,.ATM>)
(<PUT .SYN
,SFCN
<SETG <SET ATM <ADD-WORD <1 .ITM>>>
<CHTYPE [.ATM <2 .ITM>] VERB>>>)>)
(<==? .ITM DRIVER>
<PUT .SYN ,SFLAGS <CHTYPE <ORB <SFLAGS .SYN> ,SDRIVER> FIX>>)
(<==? .ITM FLIP>
<PUT .SYN ,SFLAGS <CHTYPE <ORB <SFLAGS .SYN> ,SFLIP> FIX>>)>>
.SP>
<OR <SYN1 .SYN> <PUT .SYN ,SYN1 ,EVARG>>
<OR <SYN2 .SYN> <PUT .SYN ,SYN2 ,EVARG>>
<CHTYPE .SYN SYNTAX>>
.SPECS>
VSPEC>>
"Default value for syntax slots not specified"
<SETG EVARG <CHTYPE [0 0 <> 0] VARG>>
<GDECL (EVARG) VARG>
; "To add VERBs to the BUNCHERS list"
<DEFINE ADD-BUNCHER ("TUPLE" STRS)
#DECL ((STRS) <TUPLE [REST STRING]>)
<MAPF <>
<FUNCTION (STR)
#DECL ((STR) STRING)
<SETG BUNCHERS
(,<LOOKUP .STR <GET WORDS OBLIST>> !,BUNCHERS)>>
.STRS>>