forked from historicalsource/zork
-
Notifications
You must be signed in to change notification settings - Fork 0
/
impl.mud
977 lines (848 loc) · 25.7 KB
/
impl.mud
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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
"(c) Copyright 1979, Massachusetts Institute of Technology. All rights reserved."
<OR <TYPE? ,REP SUBR>
<SETG SAVEREP ,REP>>
<DEFINE ZGO ()
<SETG REP ,ZREP>
<ON "BLOCKED"
<FUNCTION (FOO)
<PRINC !\:>>
5>
<ERRET>>
<DEFINE ZREP ZTOP ("AUX" RD)
#DECL ((ZTOP) <SPECIAL ACTIVATION> (RD) ANY)
<REPEAT ()
<CRLF>
<SET RD <READ>>
<CRLF>
<SET RD <ZEVAL .RD>>
<ZPRINT .RD>
.RD>>
<DEFINE ZPRINT (ITEM)
#DECL ((ITEM) ANY)
<COND (<TYPE? .ITEM OBJECT>
<ZOBJ-PRINT .ITEM>)
(<TYPE? .ITEM ROOM>
<ZRM-PRINT .ITEM>)
(<TYPE? .ITEM VERB>
<PRINC "Verb = ">
<PRINC <STRINGP <1 .ITEM>>>)
(<TYPE? .ITEM CEVENT>
<ZEV-PRINT .ITEM>)
(<TYPE? .ITEM LIST>
<ZLST-PRINT .ITEM>)
(<==? .ITEM T>
<PRINC "True">)
(<==? .ITEM <>>
<PRINC "False">)
(<PRIN1 .ITEM>)>>
<DEFINE ZEV-PRINT (CEV)
#DECL ((CEV) CEVENT)
<PRINC "Running ">
<PRINC <SPNAME <2 .CEV>>>
<PRINC " in ">
<PRIN1 <1 .CEV>>
<PRINC " moves">
<COND (<NOT <3 .CEV>>
<PRINC " (disabled)">)>>
<DEFINE ZLST-PRINT (LST)
#DECL ((LST) LIST)
<PRINC "List containing:">
<ZPC .LST>>
<DEFINE ZOBJ-PRINT (OBJ)
#DECL ((OBJ) OBJECT)
<PRINC "Object = ">
<PRINC <ODESC2 .OBJ>>
<COND (<OCAN .OBJ>
<PRINC " (in ">
<PRINC <ODESC2 <OCAN .OBJ>>>
<PRINC ")">)>
<COND (<NOT <EMPTY? <OCONTENTS .OBJ>>>
<PRINC " /Contains:">
<ZPC <OCONTENTS .OBJ>>)>>
<DEFINE ZPC (LST)
#DECL ((LST) LIST)
<PRINC !\ >
<MAPR <>
<FUNCTION (LST2 "AUX" (ITEM <1 .LST2>))
#DECL ((LST2) LIST (ITEM) ANY)
<COND (<TYPE? .ITEM OBJECT>
<PRINC <ODESC2 .ITEM>>)
(<PRIN1 .ITEM>)>
<OR <LENGTH? .LST2 1>
<PRINC " & ">>>
.LST>>
<DEFINE ZRM-PRINT (RM "AUX" (OBJS <ROBJS .RM>))
#DECL ((RM) ROOM (OBJS) <LIST [REST OBJECT]>)
<PRINC "Room = ">
<PRINC <RDESC2 .RM>>
<COND (<NOT <EMPTY? .OBJS>>
<PRINC "
Contains:">
<ZPC .OBJS>)>
<PRINC "
Exits to: ">
<MAPF <>
<FUNCTION (ITM)
#DECL ((ITM) ANY)
<COND (<TYPE? .ITM DIRECTION>
<PRINC <STRINGP .ITM>>
<PRINC !\ >)>>
<REXITS .RM>>>
<SET ZFLUSH
<ON "CHAR"
<FUNCTION (CHR CHN)
#DECL ((CHR) CHARACTER (CHN) CHANNEL)
<COND (<==? .CHR <ASCII 7>>
<INT-LEVEL 0>
<AND <GET BLOCKED!-INTERRUPTS INTERRUPT>
<OFF "BLOCKED">>
<SETG REP ,SAVEREP>
<LISTEN>)>>
8 0 ,INCHAN>>
<DEFINE ZEVAL (ITEM "OPTIONAL" (FLAG <>) "AUX" OPER TEMP)
#DECL ((ITEM TEMP) ANY (OPER) STRING (FLAG) <OR ATOM FALSE>)
<COND (<TYPE? .ITEM FIX FLOAT STRING> .ITEM)
(<TYPE? .ITEM FORM> <EVAL .ITEM>)
(<TYPE? .ITEM ATOM>
<SET OPER <SPNAME .ITEM>>
<COND (<SET TEMP <ZLOOKUP .OPER ,ZERO-POBL>>
<APPLY .TEMP>)
(<ZLOOKUP .OPER ,ZVARS-POBL>)
(<PLOOKUP .OPER ,OBJECT-POBL>)
(<PLOOKUP .OPER ,ROOM-POBL>)
(<PLOOKUP .OPER ,WORDS-POBL>)
(<ZLOOKUP .OPER ,ZOBITS-POBL>)
(<ZLOOKUP .OPER ,ZRBITS-POBL>)
(.FLAG #LOSE 0)
(ELSE <ILLEGAL "Unknown word: " .OPER>)>)
(<TYPE? .ITEM LIST>
<REPEAT (R I S)
#DECL ((R I) ANY (S) STRING)
<COND (<EMPTY? .ITEM> <RETURN <AND <ASSIGNED? R> .R>>)>
<SET I <1 .ITEM>>
<COND (<TYPE? .I ATOM>
<SET S <SPNAME .I>>
<COND (<SET TEMP <ZLOOKUP .S ,ZERO-POBL>>
<SET R <APPLY .TEMP>>)
(<SET TEMP <ZLOOKUP .S ,ONE-POBL>>
<COND (<EMPTY? <SET ITEM <REST .ITEM>>>
<TOOFEW .S>)
(ELSE
<SET R
<APPLY .TEMP
<ZEVAL <1 .ITEM>>>>)>)
(<SET TEMP <ZLOOKUP .S ,TWO-POBL>>
<COND (<EMPTY? <SET ITEM <REST .ITEM>>>
<TOOFEW .S>)
(<ASSIGNED? R>
<SET R
<APPLY .TEMP
.R
<ZEVAL <1 .ITEM>>>>)
(ELSE
<TOOFEW .S>)>)
(<SET TEMP <ZLOOKUP .S ,ANY-POBL>>
<COND (<EMPTY? <SET ITEM <REST .ITEM>>>
<TOOFEW .S>)
(ELSE
<SET R
<APPLY .TEMP
<OR <NOT <ASSIGNED? R>>
.R>
.ITEM>>
<RETURN .R>)>)
(ELSE <SET R <ZEVAL .I>>)>)
(ELSE <SET R <ZEVAL .I>>)>
<SET ITEM <REST .ITEM>>>)
(<ILLEGAL "ZEVAL of non list, form or atom.">)>>
<DEFINE ZIN (ITM1 ITM2)
#DECL ((ITM1 ITM2) ANY)
<COND (<TYPE? .ITM2 LIST>
<AND <MEMQ .ITM1 .ITM2> T>)
(<TYPE? .ITM1 OBJECT>
<COND (<TYPE? .ITM2 OBJECT>
<==? <OCAN .ITM1> .ITM2>)
(<TYPE? .ITM2 ROOM>
<AND <MEMQ .ITM1 <ROBJS .ITM2>> T>)
(<TYPE? .ITM2 ADV>
<AND <MEMQ .ITM1 <AOBJS ,WINNER>> T>)
(<ILLEGAL "Illegal container - " .OBJ2>)>)
(<ILLEGAL "Illegal object?">)>>
<DEFINE ZEQUALS (ITM1 ITM2)
#DECL ((ITM1 ITM2) ANY)
<COND (<==? <TYPE .ITM1> <TYPE .ITM2>>
<==? .ITM1 .ITM2>)
(<TYPE? .ITM2 FIX>
<COND (<TYPE? .ITM1 OBJECT> <TRNN .ITM1 .ITM2>)
(<TYPE? .ITM1 ROOM> <RTRNN .ITM1 .ITM2>)
(<ILLEGAL "Unknown type?">)>)>>
"ZIF -- fsubr"
<DEFINE ZIF (DUMMY LST "AUX" P (TOKEN then) (R <>))
<COND (<SET P <ZEVAL <1 .LST>>>)
(ELSE <SET TOKEN else>)>
<COND (<SET LST <MEMQ .TOKEN .LST>>
<MAPF <>
<FUNCTION (I)
<AND <==? .I else> <MAPLEAVE .R>>
<SET R <ZEVAL .I>>>
<REST .LST>>)
(ELSE <ILLEGAL "If lacks then/else">)>>
"ZCASE -- fsubr"
<SETG EXPR <ILIST 3>>
<DEFINE ZCASE (DUMMY LST "AUX" OBJ (E ,EXPR))
<SET OBJ <1 .LST>>
<COND (<TYPE? .OBJ ATOM>)(ELSE <SET OBJ <ZEVAL .OBJ>>)>
<SET LST <REST .LST>>
<COND (<EMPTY? .LST> <TOOFEW "case">)
(<TYPE? <SET OPR <1 .LST>> ATOM>
<SET LST <REST .LST>>)>
<MAPF <>
<FUNCTION (I)
<PUT .E 1 .OBJ>
<PUT .E 2 .OPR>
<PUT .E 3 <1 .I>>
<COND (<OR <==? <1 .I> else> <ZEVAL .E>>
<MAPLEAVE <ZEVAL <REST .I>>>)>>
.LST>>
"ZFOR-EACH -- fsubr"
<DEFINE ZFOR-EACH (DUMMY ARGL)
#DECL ((ARGL) LIST)
<COND (<LENGTH? .ARGL 1>
<TOOFEW>)
(<TYPE? <SET LST <ZEVAL <1 .ARGL>>> LIST>
<MAPF <>
<FUNCTION (ZITS)
#DECL ((ZITS) <SPECIAL ANY>)
<ZEVAL <REST .ARGL>>>
.LST>)
(<ILLEGAL "Argument-not-list/FOR-EACH">)>>
"ZPLUS -- two args"
<DEFINE ZPLUS (A B)
<COND (<ASSIGNED? B> <+ .A .B>)
(ELSE .A)>>
"ZMINUS -- two args"
<DEFINE ZMINUS (A B)
<COND (<ASSIGNED? B> <- .A .B>)
(ELSE .A)>>
"ZTIMES -- two args"
<DEFINE ZTIMES (A B)
<COND (<ASSIGNED? B> <* .A .B>)
(ELSE .A)>>
"ZDIVIDED -- two args"
<DEFINE ZDIVIDED (A B)
<COND (<ASSIGNED? B> </ .A .B>)
(ELSE .A)>>
"ZLESS -- two args"
<DEFINE ZLESS (A B)
<COND (<ASSIGNED? B> <L? .A .B>)
(ELSE .A)>>
"ZGREATER -- two args"
<DEFINE ZGREATER (A B)
<COND (<ASSIGNED? B> <G? .A .B>)
(ELSE .A)>>
"ZEQUAL -- two args"
<DEFINE ZEQUAL (A B)
<COND (<ASSIGNED? B> <==? .A .B>)
(ELSE .A)>>
"ZAND -- two args"
<DEFINE ZAND (A B)
<COND (<ASSIGNED? B> <AND .A .B>)
(ELSE .A)>>
"ZOR -- two args"
<DEFINE ZOR (A B)
<COND (<ASSIGNED? B> <OR .A .B>)
(ELSE .A)>>
"ZIS -- fsubr"
<DEFINE ZIS (OBJ LIST)
<ZPRED .OBJ .LIST>>
"ZISNT -- fsubr"
<DEFINE ZISNT (OBJ LIST)
<NOT <ZPRED .OBJ .LIST>>>
"ZPRED -- general predicates"
<DEFINE ZPRED (OBJ EXPR "OPTIONAL" (TTYPE <>)
"AUX" (NTTYPE <>) (VAL <>) (NOT? <>) (BOOL? <>))
#DECL ((OBJ) ANY (EXPR) <OR ATOM LIST>)
<COND (<TYPE? .EXPR ATOM>
<COND (<NOT .TTYPE>
<ZEQUALS .OBJ <ZEVAL .EXPR>>)
(<=? .TTYPE in>
<ZIN .OBJ <ZEVAL .EXPR>>)
(ELSE <ERROR UNKNOWN-TTYPE .TTYPE>)>)
(ELSE
<MAPF <>
<FUNCTION (E)
#DECL ((E) <OR ATOM LIST>)
<COND (<AND <TYPE? .E ATOM> <MEMQ .E ,BUZZ>>)
(<==? .E or> <SET BOOL? <>>)
(<==? .E and> <SET BOOL? T>)
(<==? .E not> <SET NOT? <NOT .NOT?>>)
(<MEMQ .E ,TEST-TYPES> <SET NTTYPE .E>)
(ELSE
<SET NVAL <ZPRED .OBJ .E <OR .NTTYPE .TTYPE>>>
<SET NTTYPE <>>
<COND (.NOT?
<SET NVAL <NOT .NVAL>>
<SET NOT? <>>)>
<COND (.BOOL?
<SET VAL <AND .VAL .NVAL>>)
(ELSE
<SET VAL <OR .VAL .NVAL>>)>)>>
.EXPR>
.VAL)>>
"ZLOOKUP -- fsubr"
<DEFINE ZLKUP (DUMMY ARGL "AUX" M LST)
#DECL ((ARGL) LIST (M) <OR FALSE LIST> (LST) ANY)
<COND (<LENGTH? .ARGL 1> <TOOFEW>)
(<TYPE? <SET LST <ZEVAL <2 .ARGL>>> LIST>
<AND <SET M <MEMQ <ZEVAL <1 .ARGL>> .LST>>
<NOT <LENGTH? .M 1>>>
<2 .M>)
(<ILLEGAL "Lookup in non-list?">)>>
"ZCONTENTS -- fsubr"
<DEFINE ZCONTENTS (DUMMY ARGL "AUX" (ARG .ARGL) ITEM)
#DECL ((ARGL ARG) LIST (ITEM) ANY)
<COND (<OR <EMPTY? .ARGL>
<AND <==? <1 .ARGL> of>
<SET ARG <REST .ARG>>
<LENGTH? .ARGL 1>>>
<TOOFEW>)>
<COND (<TYPE? <SET ITEM <ZEVAL <1 .ARG>>> OBJECT>
<OCONTENTS .ITEM>)
(<TYPE? .ITEM ROOM>
<ROBJS .ITEM>)
(<TYPE? .ITEM ADV>
<AOBJS .ITEM>)
(<ILLEGAL "Unknown/CONTENTS">)>>
"ZSET -- fsubr"
<DEFINE ZSET (DUMMY ARGL)
#DECL ((ARGL) LIST)
<COND (<LENGTH? .ARGL 1>
<TOOFEW>)
(<TYPE? <1 .ARGL> ATOM>
<ZINSERT <SPNAME <1 .ARGL>> ,ZVARS-POBL <ZEVAL <2 .ARGL>>>)
(<ILLEGAL "Non-atomic set?">)>>
"ZDEFINE -- fsubr"
<DEFINE ZDEFINE (DUMMY ARGL "AUX" STR)
#DECL ((ARGL) LIST (STR) STRING)
<COND (<N==? <LENGTH .ARGL> 2>
<WNA>)
(<ZINSERT <SET STR <SPNAME <1 .ARGL>>>
,ZVARS-POBL
<2 .ARGL>>
<ZFUNCTION .STR>
<1 .ARGL>)>>
<DEFINE ZFUNCTION (STR)
#DECL ((STR) STRING)
<ZINSERT .STR
<GET INITIAL OBLIST>
<CHTYPE <LIST () <FORM ZEVAL <FORM ZLOOKUP .STR ,ZVARS-POBL>>> FUNCTION>>>
"ZLOAD -- one arg"
<DEFINE ZLOAD (ARG "AUX" STR)
#DECL ((ARG) ANY (STR) ANY)
<COND (<AND <TYPE? .ARG STRING> <SET STR .ARG>>
<COND (<SET C <OPEN "READ" .STR>>
<SET <ZATOM <7 .C>>
<MAPF ,LIST
<FUNCTION ()
#DECL ((ITM) ANY)
<SET ITM <READ .C '<MAPSTOP>>>
<COND (<TYPE? .ITM LIST>
<ZEVAL .ITM>)>
.ITM>>>
<CLOSE .C>
"Done")
(<ILLEGAL "File not found.">)>)
(<ILLEGAL "Non-string file name?">)>>
"ZATOM -- ??"
<DEFINE ZATOM (STR)
#DECL ((STR) STRING)
<OR <LOOKUP .STR <GET INITIAL OBLIST>>
<INSERT .STR <GET INITIAL OBLIST>>>>
"ZDUMP -- one arg"
<DEFINE ZDUMP (ARG "AUX" STR ATM LST)
#DECL ((ARG) ANY (STR LST) ANY (ATM) ATOM)
<COND (<AND <TYPE? .ARG STRING> <SET STR .ARG>>
<COND (<SET C <OPEN "PRINT" .STR>>
<COND (<AND <ASSIGNED? <SET ATM <ZATOM <7 .C>>>>
<TYPE? <SET LST ..ATM> LIST>>
<MAPF <>
<FUNCTION (ITM)
#DECL ((ITM) ANY)
<COND (<AND <TYPE? .ITM LIST>
<==? <1 .ITM> define>>
<PPRINT (define
<2 .ITM>
<ZLOOKUP <SPNAME <2 .ITM>>
,ZVARS-POBL>)
.C>)
(<PPRINT .ITM .C>)>>
.LST>
<CLOSE .C>
<TELL "Done" 0>)
(<ILLEGAL "Not a group?">)>)
(<ILLEGAL "Can't open channel?">)>)
(<ILLEGAL "Non-string file name?">)>>
"ZPPRINT -- one arg"
<DEFINE ZPPRINT (DUMMY ARG)
#DECL ((ARG) ANY)
<ZEDIT <> .ARG T>>
"ZRUN -- fsubr"
<DEFINE ZRUN (DUMMY ARGL "AUX" STR ARG VAL (CEV <>))
#DECL ((ARGL) LIST (STR) STRING (VAL ARG) ANY (CEV) <OR FALSE CEVENT>)
<COND (<EMPTY? .ARGL> <TOOFEW>)
(<AND <TYPE? <SET ARG <1 .ARGL>> ATOM>
<TYPE? <SET VAL <ZLOOKUP <SET STR <SPNAME .ARG>> ,ZVARS-POBL>> LIST>>
<MAPF <>
<FUNCTION (ITEM)
<COND (<MEMQ .ITEM '[in moves]>)
(<TYPE? .ITEM FIX>
<SET CEV
<COND (<ZLOOKUP .STR ,ZINT-POBL>)
(<ZINSERT .STR
,ZINT-POBL
<CEVENT 0
<ZATOM .STR>
<>
"**::**">>)>>
<COND (<MEMQ .CEV ,ZINTS>)
(<SETG ZINTS (<LOOKUP .STR ,ZINT-POBL>
.CEV
!,ZINTS)>)>
<MAPLEAVE <CLOCK-ENABLE <CLOCK-INT .CEV .ITEM>>>)
(<ILLEGAL "Bad argument/RUN">)>>
<REST .ARGL>>
<OR .CEV <ZEVAL .VAL>>)
(<ILLEGAL "Not applicable?">)>>
"ZENABLE -- one arg"
<DEFINE ZENABLE (ARG "AUX")
#DECL ((ARG) ANY)
<CLOCK-ENABLE <ZINT-FIND .ARG>>>
"ZDISABLE -- one arg"
<DEFINE ZDISABLE (ARG "AUX")
#DECL ((ARG) ANY)
<CLOCK-DISABLE <ZINT-FIND .ARG>>>
<DEFINE ZINT-FIND (ITEM "AUX" (VARS ,ZVARS-POBL))
#DECL ((ITEM) ANY (VARS) OBLIST)
<COND (<AND <TYPE? .ITEM LIST>
<REPEAT ((L ,ZINTS))
#DECL ((L) <LIST [REST ATOM CEVENT]>)
<COND (<EMPTY? .L> <RETURN <>>)
(<==? <ZLOOKUP <SPNAME <1 .L>> .VARS> .ITEM>
<RETURN <2 .L>>)
(<SET L <REST .L 2>>)>>>)
(<ILLEGAL "Not an interrupt">)>>
"ZEDIT -- fsubr"
<DEFINE ZEDIT (DUMMY ARGL "OPTIONAL" (PRINT? <>) "AUX" L ARG STR)
#DECL ((ARGL) LIST (ARG) ANY (L) ANY (PRINT?) <OR FALSE ATOM> (STR) STRING)
<COND (<EMPTY? .ARGL> <TOOFEW>)
(<TYPE? <SET ARG <1 .ARGL>> ATOM>
<COND (<TYPE? <SET L <ZLOOKUP <SET STR <SPNAME .ARG>> ,ZVARS-POBL>> LIST>
<ZINSERT <SPNAME .ARG> ,ZVARS-POBL <ZEP .L .PRINT?>>
.ARG)
(<TYPE? .L ROOM OBJECT>
<SET VAL <ZEP <ZLOOKUP <SPNAME .ARG> ,ZDEFS-POBL> .PRINT?>>
<ZINSERT .STR ,ZDEFS-POBL .VAL>
<COND (<TYPE? .L ROOM>
<RM/OBJ-CREATE .VAL <>>)
(<RM/OBJ-CREATE .VAL>)>)
(<ILLEGAL "Value of atom not a list?">)>)
(<ILLEGAL "Must edit an atom.">)>>
<DEFINE ZEP (OBJ PRINT?)
#DECL ((OBJ) LIST (PRINT?) <OR ATOM FALSE>)
<COND (.PRINT?
<PPRINT .OBJ>
.OBJ)
(<TELL " Starting edit." 0>
<EDIT OBJ>
<TELL "
Return from edit.">
.OBJ)>>
"zero-arg goodies"
<DEFINE ZWINNER () ,WINNER>
<DEFINE ZTRUE () T>
<DEFINE ZFALSE () <>>
<DEFINE ZSCORE () <ASCORE ,WINNER>>
<DEFINE ZPRSO () <PRSO>>
<DEFINE ZROOM () ,HERE>
<DEFINE ZPRSI () <PRSI>>
<DEFINE ZVERB () <PRSA>>
<DEFINE ZIT () .ZITS>
<DEFINE ZZORK () <OFF "BLOCKED"> <DC>>
"ZTAKE -- one arg"
<DEFINE ZTAKE (ARG "AUX" OBJ)
#DECL ((ARG) ANY (OBJ) ANY)
<COND (<TYPE? .ARG OBJECT>
<REMOVE-OBJECT .OBJ>
<TAKE-OBJECT .OBJ>)>>
"ZREMOVE -- fsubr"
<DEFINE ZREMOVE (DUMMY LST "AUX" OBJ)
#DECL ((LST) LIST (OBJ) ANY)
<COND (<EMPTY? .LST>
<TOOFEW>)
(<MAPF <>
<FUNCTION (ITM)
#DECL ((ITM) ANY)
<COND (<==? .ITM and>)
(<TYPE? <SET OBJ <ZEVAL .ITM>> OBJECT>
<REMOVE-OBJECT .OBJ>)
(<ILLEGAL "Not an object/REMOVE">)>>
.LST>)
(<ILLEGAL "Not an object/REMOVE">)>>
"ZPUTIN -- fsubr"
<DEFINE ZPUTIN (DUMMY LST "AUX" OBJ)
#DECL ((LST) LIST (OBJ) ANY)
<COND (<LENGTH? .LST 1>
<TOOFEW>)
(ELSE
<SET OBJ2 <COND (<MEMQ <2 .LST> ![in into to]>
<COND (<LENGTH? .LST 2>
<TOOFEW>)
(<ZEVAL <3 .LST>>)>)
(<ZEVAL <2 .LST>>)>>
<COND (<TYPE? .OBJ2 LIST>
<CONS <ZEVAL <1 .LST>> .OBJ2>)
(<TYPE? <SET OBJ <ZEVAL <1 .LST>>> OBJECT>
<REMOVE-OBJECT .OBJ>
<COND (<TYPE? .OBJ2 ROOM>
<INSERT-OBJECT .OBJ .OBJ2>)
(<TYPE? .OBJ2 OBJECT>
<INSERT-INTO .OBJ2 .OBJ>)
(<TYPE? .OBJ2 ADV>
<TAKE-OBJECT .OBJ>)
(<ILLEGAL "Illegal operator/INSERT">)>)
(<ILLEGAL "Not an object/INSERT">)>)>>
"ZTELL -- fsubr"
<DEFINE ZTELL (DUMMY LST)
<MAPF <>
<FUNCTION (ITEM)
<COND (<TYPE? .ITEM STRING>
<TELL .ITEM 0>)
(<==? .ITEM crlf>
<TELL "">)
(<TYPE? <SET VAL <ZEVAL .ITEM>> OBJECT>
<TELL <ODESC2 .VAL> 0>)
(<ILLEGAL "Unknown print operator.">)>>
.LST>>
"ZGOTO -- one arg"
<DEFINE ZGOTO (ARG)
#DECL ((ARG) ANY)
<COND (<TYPE? .ARG ROOM> <GOTO .ARG>)
(<ILLEGAL "Not a room/GOTO">)>>
"ZMAKE -- fsubr"
<DEFINE ZMAKE (DUMMY LST "AUX" OBJ (NOT? <MEMQ not .LST>))
#DECL ((LST) LIST (OBJ) ANY (NOT?) <OR FALSE LIST>)
<COND (<OR <AND .NOT? <LENGTH? .LST 2>>
<LENGTH? .LST 1>>
<TOOFEW>)
(<TYPE? <SET OBJ <ZEVAL <1 .LST>>> OBJECT>
<COND (<SET M <ZLOOKUP <SPNAME <COND (.NOT? <3 .LST>) (<2 .LST>)>>
,ZOBITS-POBL>>
<COND (.NOT?
<TRZ .OBJ .M>)
(<TRO .OBJ .M>)>)
(<ILLEGAL "Not an object flag/MAKE">)>)
(<TYPE? .OBJ ROOM>
<COND (<SET M <ZLOOKUP <SPNAME <COND (.NOT? <3 .LST>) (<2 .LST>)>>
,ZRBITS-POBL>>
<COND (.NOT?
<RTRZ .OBJ .M>)
(<RTRO .OBJ .M>)>)
(<ILLEGAL "Not a room flag/MAKE">)>)
(<ILLEGAL "Not a room or object/MAKE">)>>
<DEFINE ZTOPLEVEL () <ERRET>>
<DEFINE ZSTACK& () <ZSTACK T>>
<DEFINE ZSTACK ("OPTIONAL" (FLG <>) "AUX" (F <FRAME>) (LEVEL -1) ARG)
#DECL ((FLG) <OR ATOM FALSE> (F) FRAME (LEVEL) FIX (ARG) ANY)
<REPEAT ()
<COND (<==? <FUNCT .F> TOPLEVEL>
<PRINC "toplevel">
<RETURN>)
(<AND <==? <FUNCT .F> EVAL>
<TYPE? <SET ARG <1 <ARGS .F>>> FORM>
<OR <==? <1 .ARG> ZEVAL>
<==? <1 .ARG> ZPRED>
<==? <1 .ARG> ILLEGAL>>>
<PRIN1 <SET LEVEL <+ .LEVEL 1>>>
<PRINC !\ >
<PRIN1 <1 .ARG>>
<INDENT-TO 10>
<COND (.FLG
<&1 <EVAL <2 .ARG> .F>>
<AND <==? <1 .ARG> ZPRED>
<CRLF>
<INDENT-TO 10>
<&1 <EVAL <3 .ARG> .F>>>)
(<EPRIN1 <EVAL <2 .ARG> .F>>
<AND <==? <1 .ARG> ZPRED>
<CRLF>
<INDENT-TO 10>
<EPRIN1 <EVAL <3 .ARG> .F>>>)>
<CRLF>)>
<SET F <FRAME .F>>>
,NULL>
<DEFINE ZRETURN (DUMMY ARGL)
#DECL ((ARGL) LIST)
<ZRETRY <ZEVAL <2 .ARGL>> <ZEVAL <1 .ARGL>>>>
<DEFINE ZRETRY (TARGET "OPTIONAL" (VAL #LOSE 0) "AUX" (LEVEL -1) (F <FRAME>) ARG)
#DECL ((TARGET LEVEL) FIX (ARG VAL) ANY (F) FRAME)
<COND (<TYPE? .TARGET FIX>
<REPEAT ()
<COND (<==? <FUNCT .F> TOPLEVEL>
<PRINC "Beyond toplevel?">
<RETURN>)
(<AND <==? <FUNCT .F> EVAL>
<TYPE? <SET ARG <1 <ARGS .F>>> FORM>
<OR <==? <1 .ARG> ZEVAL>
<==? <1 .ARG> ZPRED>
<==? <1 .ARG> ILLEGAL>>
<==? <SET LEVEL <+ .LEVEL 1>> .TARGET>>
<COND (<TYPE? .VAL LOSE>
<RETRY .F>)
(<ERRET .VAL .F>)>)>
<SET F <FRAME .F>>>)
(<ILLEGAL "Bad argument to RETRY/RETURN">)>>
<DEFINE ZCREATE (DUMMY ARGL "AUX" TYP)
#DECL ((ARGL) LIST (TYP) ANY)
<COND (<==? <SET TYP <1 .ARGL>> room>
<RM/OBJ-CREATE <REST .ARGL> <>>)
(<==? .TYP object>
<RM/OBJ-CREATE <REST .ARGL>>)
(<==? .TYP syntax>
<SYNTAX-CREATE <REST .ARGL>>)
(<==? .TYP list>
<MAPF ,LIST ,ZEVAL <REST .ARGL>>)
(<ILLEGAL "Unknown type/CREATE">)>>
<SETG HI-RM/OBJ 0>
<DEFINE NEXT-RM/OBJ ()
<STRING "Z" <UNPARSE <SETG HI-RM/OBJ <+ ,HI-RM/OBJ 1>>>>>
<DEFINE RM/OBJ-CREATE (ARGL "OPTIONAL" (OBJ? T)
"AUX" NAME (OBJS ()) RM OBJ SYN ADJ)
#DECL ((ARGL) LIST (NAME) ATOM (OBJS) <LIST [REST OBJECT]>
(RM) ROOM (OBJECT) OBJECT (OBJ?) <OR ATOM FALSE>
(SYN) <UVECTOR [REST PSTRING]> (ADJ) <UVECTOR [REST ADJECTIVE]>)
<MAPF <>
<FUNCTION (ITEM "AUX" OPER VAL VAL2)
#DECL ((ITEM OPER VAL VAL2) ANY)
<COND (<TYPE? .ITEM ATOM>
<SET NAME .ITEM>
<SET VAL <ZLOOKUP <SPNAME .NAME> ,ZVARS-POBL>>
<COND (.OBJ?
<SET OBJ
<COND (<TYPE? .VAL OBJECT> .VAL)
(<GET-OBJ <NEXT-RM/OBJ>>)>>)
(<SET RM
<COND (<TYPE? .VAL ROOM> .VAL)
(<GET-ROOM <NEXT-RM/OBJ>>)>>)>)
(<TYPE? .ITEM LIST>
<COND (<LENGTH? .ITEM 1>
<ILLEGAL "Bad format/CREATE">)
(<==? <SET OPER <1 .ITEM>> property>
<COND (.OBJ?
<PUT .OBJ
,OFLAGS
<BITS-GET ,ZOBITS-POBL <REST .ITEM>>>)
(<PUT .RM
,RBITS
<BITS-GET ,ZRBITS-POBL <REST .ITEM>>>
<RTRO .RM ,RLANDBIT>)>)
(<AND <SET VAL <2 .ITEM>> <>>)
(<==? .OPER name>
<COND (.OBJ?
<PUT .OBJ ,ODESC2 .VAL>)
(<PUT .RM ,RDESC2 .VAL>)>)
(<==? .OPER description>
<COND (.OBJ?
<OPUT .OBJ ODESC1 .VAL T>)
(<PUT .RM ,RDESC1 .VAL>)>)
(<==? .OPER run>
<COND (<TYPE? .VAL ATOM>
<COND (<GASSIGNED? .VAL>)
(<SETG .VAL ,ZFALSE>)>
<COND (.OBJ?
<PUT .OBJ ,OACTION .VAL>)
(<PUT .RM ,RACTION .VAL>)>)
(<ILLEGAL "Bad routine/CREATE">)>)
(<==? .OPER contents>
<MAPF <>
<FUNCTION (FOO)
#DECL ((FOO) ANY)
<COND (<TYPE? <SET VAL2 <ZEVAL .FOO T>>
OBJECT>
<REMOVE-OBJECT .VAL2>)
(<TYPE? .VAL2 LOSE>
<SET VAL2
<RM/OBJ-CREATE (.FOO)>>)
(<ILLEGAL "Bad object/CREATE">)>
<SET OBJS (.VAL2 !.OBJS)>>
<REST .ITEM>>)
(<AND <NOT .OBJ?> <==? .OPER exit>>
<ZEXIT .RM <REST .ITEM>>)
(<AND .OBJ? <==? .OPER synonym>>
<SET SYN
<MAPF ,UVECTOR
<FUNCTION (NAM)
#DECL ((NAM) ANY)
<COND (<TYPE? .NAM ATOM>
<ZSYN .NAM .OBJ>)
(<ILLEGAL "Bad synonym/CREATE">)>>
<REST .ITEM>>>)
(<AND .OBJ? <==? .OPER adjective>>
<SET ADJ
<MAPF ,UVECTOR
<FUNCTION (NAM)
#DECL ((NAM) ANY)
<COND (<TYPE? .NAM ATOM>
<ADD-ZORK ADJECTIVE <SPNAME .NAM>>)
(<ILLEGAL "Bad adjective/CREATE">)>>
<REST .ITEM>>>)
(<ILLEGAL "Bad identifier/CREATE">)>)>>
.ARGL>
<ZINSERT <SPNAME .NAME> ,ZDEFS-POBL .ARGL>
<COND (.OBJ?
<PUT .OBJ ,OCONTENTS ()>
<MAPF <>
<FUNCTION (NOBJ) #DECL ((NOBJ) OBJECT)
<INSERT-INTO .OBJ .NOBJ>>
.OBJS>
<AND <ASSIGNED? SYN> <PUT .OBJ ,ONAMES .SYN>>
<AND <ASSIGNED? ADJ> <PUT .OBJ ,OADJS .ADJ>>
<ZINSERT <SPNAME .NAME> ,ZVARS-POBL .OBJ>
.OBJ)
(<PUT .RM ,ROBJS ()>
<MAPF <>
<FUNCTION (NOBJ) #DECL ((NOBJ) OBJECT)
<INSERT-OBJECT .NOBJ .RM>>
.OBJS>
<ZINSERT <SPNAME .NAME> ,ZVARS-POBL .RM>
.RM)>>
<DEFINE ZSYN (NAM OBJ "AUX" (S <SPNAME .NAM>) STR)
#DECL ((NAM) ATOM (S STR) STRING (OBJ) OBJECT)
<SET STR <UPPERCASE <SUBSTRUC .S 0 <MIN <LENGTH .S> 5>>>>
<PINSERT .STR ,OBJECT-POBL .OBJ>
<PSTRING .STR>>
<DEFINE ZEXIT (THIS LST "AUX" DIR RM RM? (NEXIT <>) (CEXIT <>) (CFCN <>) M EXIT)
#DECL ((LST) LIST (DIR) <OR DIRECTION FALSE> (RM?) ANY (RM THIS) ROOM
(NEXIT) <OR STRING FALSE> (CEXIT CFCN) <OR FALSE ATOM> (EXIT) ANY
(M) <OR FALSE <VECTOR [REST DIRECTION ANY]>>)
<COND (<LENGTH? .LST 2>
<TOOFEW>)
(<SET DIR <PLOOKUP <UPPERCASE <PNAME <1 .LST>>> ,DIRECTIONS-POBL>>
<COND (<==? <2 .LST> to>
<COND (<TYPE? <SET RM? <ZEVAL <3 .LST> T>> ROOM>)
(<TYPE? .RM? LOSE>
<SET RM? <RM/OBJ-CREATE (<3 .LST>) <>>>)
(<TYPE? .RM? STRING>
<SET NEXIT .RM?>)
(<ILLEGAL "Not-a-room/EXIT">)>
<SET RM .RM?>
<SET LST <REST .LST 3>>
<COND (<EMPTY? .LST>)
(<AND <==? <1 .LST> if>
<NOT <LENGTH? .LST 1>>>
<COND (<==? <2 .LST> run>
<COND (<LENGTH? .LST 2>
<SET CFCN <3 .LST>>)
(<ILLEGAL "Bad format/EXIT">)>)
(<SET CEXIT <2 .LST>>)>)
(<ILLEGAL "Bad format/EXIT">)>
<SET EXIT
<COND (.NEXIT <CHTYPE .NEXIT STRING>)
(.CEXIT <CEXIT <SPNAME .CEXIT> <RID .RM> "" <> <>>)
(.CFCN <CEXIT "FROBOZZ" <RID .RM> "" <> .CFCN>)
(.RM)>>
<COND (<SET M <MEMQ .DIR <REXITS .THIS>>>
<PUT .M 2 .EXIT>)
(<PUT .THIS ,REXITS <VECTOR .DIR .EXIT !<REXITS .THIS>>>)>)
(<ILLEGAL "Bad format/EXIT">)>)
(<ILLEGAL "Unknown-direction: " <1 .LST>>)>>
<DEFINE BITS-GET (POBL ARGL "AUX" FX)
#DECL ((ARGL) LIST (POBL) OBLIST (FX) <OR FIX FALSE>)
<MAPF ,+
<FUNCTION (ITEM)
<COND (<AND <TYPE? .ITEM ATOM>
<SET FX <ZLOOKUP <SPNAME .ITEM> .POBL>>>)
(<ILLEGAL "Illegal property.">)>>
.ARGL>>
<DEFINE ZOBLIST (ATM NUM)
<SETG .ATM <MOBLIST .ATM .NUM>>>
<DEFINE ZLOOKUP (STR OBL "AUX" ATM)
#DECL ((STR) STRING (OBL) OBLIST (ATM) <OR FALSE ATOM>)
<AND <SET ATM <LOOKUP .STR .OBL>> ,.ATM>>
<DEFINE ZINSERT (STR OBL VAL)
#DECL ((STR) STRING (OBL) OBLIST (VAL) ANY)
<SETG <OR <LOOKUP .STR .OBL> <INSERT .STR .OBL>> .VAL>>
<DEFINE PINS (POBL VEC)
#DECL ((POBL) OBLIST (VEC) <VECTOR [REST <OR STRING ATOM> ANY]>)
<REPEAT ((V .VEC) ELEM)
#DECL ((V) <VECTOR [REST <OR STRING ATOM> ANY]> (ELEM) <OR STRING ATOM>)
<ZINSERT <COND (<TYPE? <SET ELEM <1 .V>> ATOM>
<PNAME .ELEM>)
(.ELEM)>
.POBL
<2 .V>>
<COND (<EMPTY? <SET V <REST .V 2>>>
<RETURN>)>>>
<ZOBLIST ZOBITS-POBL 17>
<ZOBLIST ZRBITS-POBL 17>
<ZOBLIST ZVARS-POBL 17>
<ZOBLIST ZDEFS-POBL 17>
<ZOBLIST ZINT-POBL 17>
<ZOBLIST ZERO-POBL 17>
<ZOBLIST ONE-POBL 17>
<ZOBLIST TWO-POBL 17>
<ZOBLIST ANY-POBL 17>
<SETG ZINTS ()>
<GDECL (ZINTS) <LIST [REST ATOM CEVENT]>>
<PINS ,ANY-POBL
["edit" ,ZEDIT "pprint" ,ZPPRINT
"if" ,ZIF "case" ,ZCASE "for-each" ,ZFOR-EACH "contents" ,ZCONTENTS
"is" ,ZIS "isnt" ,ZISNT
"define" ,ZDEFINE "set" ,ZSET "run" ,ZRUN "lookup" ,ZLKUP
"remove" ,ZREMOVE "insert" ,ZPUTIN "return" ,ZRETURN "put" ,ZPUTIN
"print" ,ZTELL "make" ,ZMAKE "create" ,ZCREATE]>
<PINS ,TWO-POBL
["and" ,ZAND "or" ,ZOR "plus" ,ZPLUS "minus" ,ZMINUS
"times" ,ZTIMES "divided-by" ,ZDIVIDED "is-greater-than" ,ZGREATER
"is-less-than" ,ZLESS "gt" ,ZGREATER "lt" ,ZLESS "eq" ,ZEQUAL
"equals" ,ZEQUAL]>
<PINS ,ONE-POBL
["retry" ,ZRETRY "goto" ,ZGOTO "take" ,ZTAKE
"load" ,ZLOAD "dump" ,ZDUMP "enable" ,ZENABLE "disable" ,ZDISABLE
]>
<PINS ,ZERO-POBL
["stack" ,ZSTACK "stack&" ,ZSTACK& "toplevel" ,ZTOPLEVEL
"me" ,ZWINNER "hand" ,ZWINNER "player" ,ZWINNER
"handled" ,ZTRUE
"not-handled" ,ZFALSE
"room" ,ZROOM "here" ,ZROOM
"verb" ,ZVERB "zork" ,ZZORK
"objo" ,ZPRSO "direct-object" ,ZPRSO "object" ,ZPRSO
"indirect-object" ,ZPRSI "obji" ,ZPRSI "it" ,ZIT
"score" ,ZSCORE]>
<PINS ,ZOBITS-POBL
["visible" ,OVISON "readable" ,READBIT "burnable" ,BURNBIT
"weapon" ,WEAPONBIT "takeable" ,TAKEBIT "villain" ,VILLAIN
"container" ,CONTBIT "edible" ,FOODBIT "transparent" ,TRANSBIT
"indescribable" ,NDESCBIT "drinkable" ,DRINKBIT "potable" ,DRINKBIT
"light" ,LIGHTBIT "victim" ,VICBIT "flaming" ,FLAMEBIT "tool" ,TOOLBIT
"turnable" ,TURNBIT "vehicle" ,VEHBIT "sacred" ,SACREDBIT "tieable"
,TIEBIT "climbable" ,CLIMBBIT "open" ,OPENBIT "touched" ,TOUCHBIT
"on" ,ONBIT]>
<PINS ,ZRBITS-POBL
["land" ,RLANDBIT "seen" ,RSEENBIT "illuminated" ,RLIGHTBIT
"sacred" ,RSACREDBIT "reservoir" ,RFILLBIT
"inaccessible" ,RMUNGBIT "wallless" ,RNWALLBIT]>
<SETG BUZZ ![a the is]>
<SETG NOTS [not isnt]>
<SETG TEST-TYPES [in]>
<DEFINE ILLEGAL ("OPTIONAL" (STR "Illegal operation.") (STR2 ""))
#DECL ((STR) STRING)
<TELL .STR 0 .STR2>
<LISTEN>>
<DEFINE TOOFEW ("OPTIONAL" WHAT)
<TELL "Too few arguments" 0>
<AND <ASSIGNED? WHAT> <TELL " to " 0 .WHAT>>
<LISTEN>>
<DEFINE WNA ()
<TELL "Wrong number of arguments." 0>
<LISTEN>>