-
Notifications
You must be signed in to change notification settings - Fork 2
/
eval.mcr349
3935 lines (3336 loc) · 81.1 KB
/
eval.mcr349
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
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
TITLE EVAL -- MUDDLE EVALUATOR
RELOCATABLE
; GERALD JAY SUSSMAN, 1971. REWRITTEN MANY TIMES SINCE C. REEVE (1972--1974)
.GLOBAL BINDID,LPROG,GLOBSP,GLOBASE,SPBASE,TPBASE,PTIME,SWAP,CHFRAM
.GLOBAL IGVAL,CHKARG,NXTDCL,TPOVFL,CHFRM,PROCHK,CHFSWP,VECBOT,TYPSGR
.GLOBAL ILVAL,ER1ARG,SPECBIND,MAKACT,SPECSTORE,MAKTUP,TPALOC,IBIND,SSPECS
.GLOBAL IDVAL,EVECTO,EUVECT,CHARGS,BCKTRK,CELL,ILOC,IGLOC,CHKDCL,SSPEC1
.GLOBAL PDLBUF,MESS,FACTI,CHKARG,MAKENV,PSTAT,BNDV,UNBOU,UNAS,IGDECL
.GLOBAL 1STEPR,SEGMNT,SEGLST,NAPT,EVTYPE,EVATYP,APTYPE,APLTYP,APLQ,IDVAL1
.GLOBAL TESTR,VALG,TYPG,INCR1,TMATCH,TYPMIS,SAT,MAKACT,NTPALO,SPECBND
.GLOBAL TPGROW,CHKAB,TYPSEG,NXTLM,MONCH0,CHFINI,RMONC0,IMPURIFY,ICONS,INCONS
.GLOBAL CILVAL,CISET,CIGVAL,CSETG,MAPPLY,CLLOC,CGLOC,CASSQ,CGASSQ,CBOUND
.GLOBAL IIGLOC,CHUNW,IUNWIN,UNWIN2,SPCCHK,CURFCN,TMPLNT,TD.LNT,TBINIT
.GLOBAL SPECBE
.GLOBAL AGC,GVLINC,LVLINC,CGBOUN,IEVECT,MAKTU2
.INSRT MUDDLE >
MONITOR
; ENTRY TO EXPAND A MACRO
MFUNCTION EXPAND,SUBR
ENTRY 1
MOVEI A,PVLNT*2+1(PVP)
HRLI A,TFRAME
MOVE B,TBINIT+1(PVP)
HLL B,OTBSAV(B)
PUSH TP,A
PUSH TP,B
MOVEI B,-1(TP)
JRST AEVAL2
; MAIN EVAL ENTRANCE
MFUNCTION EVAL,SUBR
ENTRY
SKIPE C,1STEPR+1(PVP) ; BEING 1 STEPPED?
JRST 1STEPI ; YES HANDLE
EVALON: HLRZ A,AB ;GET NUMBER OF ARGS
CAIE A,-2 ;EXACTLY 1?
JRST AEVAL ;EVAL WITH AN ALIST
SEVAL: GETYP A,(AB) ;GET TYPE OF ARG
SKIPE C,EVATYP+1(TVP) ; USER TYPE TABLE?
JRST EVDISP
SEVAL1: CAIG A,NUMPRI ;PRIMITIVE?
JRST @EVTYPE(A) ;YES-DISPATCH
SELF: MOVE A,(AB) ;TYPES WHICH EVALUATE
MOVE B,1(AB)
JRST EFINIS ;TO SELF-EG NUMBERS
; HERE FOR USER EVAL DISPATCH
EVDISP: ADDI C,(A) ; POINT TO SLOT
ADDI C,(A)
SKIPE (C) ; SKIP EITHER A LOSER OR JRST DISP
JRST EVDIS1 ; APPLY EVALUATOR
SKIPN C,1(C) ; GET ADDR OR GO TO PURE DISP
JRST SEVAL1
JRST (C)
EVDIS1: PUSH TP,(C)
PUSH TP,1(C)
PUSH TP,(AB)
PUSH TP,1(AB)
MCALL 2,APPLY ; APPLY HACKER TO OBJECT
JRST EFINIS
; EVAL DISPATCH TABLE
DISTBL EVTYPE,SELF,[[TFORM,EVFORM],[TLIST,EVLIST],[TVEC,EVECT],[TUVEC,EUVEC]
[TSEG,ILLSEG]]
;WATCH FOR SUBTLE BUG 43 LERR,LPROG OR BINDID
AEVAL:
CAIE A,-4 ;EXACTLY 2 ARGS?
JRST WNA ;NO-ERROR
GETYP A,2(AB) ;CHECK THAT WE HAVE A FRAME
CAIE A,TACT
CAIN A,TFRAME
JRST .+3
CAIE A,TENV
JRST TRYPRO ; COULD BE PROCESS
MOVEI B,2(AB) ; POINT TO FRAME
AEVAL2: PUSHJ P,CHENV ; HACK ENVIRONMENT CHANGE
AEVAL1: PUSH TP,(AB)
PUSH TP,1(AB)
MCALL 1,EVAL
AEVAL3: HRRZ 0,FSAV(TB)
CAIN 0,EVAL
JRST EFINIS
JRST FINIS
TRYPRO: CAIE A,TPVP ; SKIP IF IT IS A PROCESS
JRST WTYP2
MOVE C,3(AB) ; GET PROCESS
CAMN C,PVP ; DIFFERENT FROM ME?
JRST SEVAL ; NO, NORMAL EVAL WINS
MOVE B,SPSTO+1(C) ; GET SP FOR PROCESS
MOVE D,TBSTO+1(C) ; GET TOP FRAME
HLL D,OTBSAV(D) ; TIME IT
MOVEI C,PVLNT*2+1(C) ; CONS UP POINTER TO PROC DOPE WORD
HRLI C,TFRAME ; LOOK LIK E A FRAME
PUSHJ P,SWITSP ; SPLICE ENVIRONMENT
JRST AEVAL1
; ROUTINE TO CHANGE LOOK UP PATH FOR BINDINGS
CHENV: PUSHJ P,CHFRM ; CHECK OUT FRAME
MOVE C,(B) ; POINT TO PROCESS
MOVE D,1(B) ; GET TB POINTER FROM FRAME
CAMN SP,SPSAV(D) ; CHANGE?
POPJ P, ; NO, JUST RET
MOVE B,SPSAV(D) ; GET SP OF INTEREST
SWITSP: MOVSI 0,TSKIP ; SET UP SKIP
HRRI 0,1(TP) ; POINT TO UNBIND PATH
MOVE A,PVP
ADD A,[BINDID,,BINDID] ; BIND THE BINDING ID
PUSH TP,BNDV
PUSH TP,A
PUSH TP,$TFIX
AOS A,PTIME ; NEW ID
PUSH TP,A
MOVE E,TP ; FOR SPECBIND
PUSH TP,0
PUSH TP,B
PUSH TP,C ; SAVE PROCESS
PUSH TP,D
PUSHJ P,SPECBE ; BIND BINDID
MOVE SP,TP ; GET NEW SP
SUB SP,[3,,3] ; SET UP SP FORK
POPJ P,
; HERE TO EVALUATE A FORM (99% OF EVAL'S WORK)
EVFORM: SKIPN C,1(AB) ; EMPTY FORM, RETURN FALSE
JRST EFALSE
GETYP A,(C) ; 1ST ELEMENT OF FORM
CAIE A,TATOM ; ATOM?
JRST EV0 ; NO, EVALUATE IT
MOVE B,1(C) ; GET ATOM
PUSHJ P,IGVAL ; GET ITS GLOBAL VALUE
; SPECIAL HACK TO SPEED UP LVAL AND GVAL CALLS
CAIE B,LVAL
CAIN B,GVAL
JRST ATMVAL ; FAST ATOM VALUE
GETYP 0,A
CAIE 0,TUNBOU ; BOUND?
JRST IAPPLY ; YES APPLY IT
MOVE C,1(AB) ; LOOK FOR LOCAL
MOVE B,1(C)
PUSHJ P,ILVAL
GETYP 0,A
CAIE 0,TUNBOU
JRST IAPPLY ; WIN, GO APPLY IT
PUSH TP,$TATOM
PUSH TP,EQUOTE UNBOUND-VARIABLE
PUSH TP,$TATOM
MOVE C,1(AB) ; FORM BACK
PUSH TP,1(C)
PUSH TP,$TATOM
PUSH TP,MQUOTE VALUE
MCALL 3,ERROR ; REPORT THE ERROR
JRST IAPPLY
EFALSE: MOVSI A,TFALSE ; SPECIAL FALSE FOR EVAL OF EMPTY FORM
MOVEI B,0
JRST EFINIS
ATMVAL: HRRZ D,(C) ; CDR THE FORM
HRRZ 0,(D) ; AND AGAIN
JUMPN 0,IAPPLY
GETYP 0,(D) ; MAKE SURE APPLYING TO ATOM
CAIE 0,TATOM
JRST IAPPLY
MOVEI E,IGVAL ; ASSUME GLOBAAL
CAIE B,GVAL ; SKIP IF OK
MOVEI E,ILVAL ; ELSE USE LOCAL
PUSH P,B ; SAVE SUBR
MOVE B,(D)+1 ; CLR BUG #1637 (GET THE ATOM FOR THE SUBR)
PUSHJ P,(E) ; AND GET VALUE
CAME A,$TUNBOU
JRST EFINIS ; RETURN FROM EVAL
POP P,B
MOVSI A,TSUBR ; CAUSE REAL SUBR TO GET EROR
JRST IAPPLY
; HERE FOR 1ST ELEMENT NOT A FORM
EV0: PUSHJ P,FASTEV ; EVAL IT
; HERE TO APPLY THINGS IN FORMS
IAPPLY: PUSH TP,(AB) ; SAVE THE FORM
PUSH TP,1(AB)
PUSH TP,A
PUSH TP,B ; SAVE THE APPLIER
PUSH TP,$TFIX ; AND THE ARG GETTER
PUSH TP,[ARGCDR]
PUSHJ P,APLDIS ; GO TO INTERNAL APPLIER
JRST EFINIS ; LEAVE EVAL
; HERE TO EVAL 1ST ELEMENT OF A FORM
FASTEV: SKIPE 1STEPR+1(PVP) ; BEING 1 STEPPED?
JRST EV02 ; YES, LET LOSER SEE THIS EVAL
GETYP A,(C) ; GET TYPE
SKIPE D,EVATYP+1(TVP) ; USER TABLE?
JRST EV01 ; YES, HACK IT
EV03: CAIG A,NUMPRI ; SKIP IF SELF
SKIPA A,EVTYPE(A) ; GET DISPATCH
MOVEI A,SELF ; USE SLEF
EV04: CAIE A,SELF ; IF EVAL'S TO SELF, JUST USE IT
JRST EV02
MOVSI A,TLIST
MOVEM A,CSTO(PVP)
INTGO
SETZM CSTO(PVP)
HLLZ A,(C) ; GET IT
MOVE B,1(C)
JSP E,CHKAB ; CHECK DEFERS
POPJ P, ; AND RETURN
EV01: ADDI D,(A) ; POINT TO SLOT OF USER EVAL TABLE
ADDI D,(A)
SKIPE (D) ; EITHER NOT GIVEN OR SIMPLE
JRST EV02
SKIPN 1(D) ; SKIP IF SIMPLE
JRST EV03 ; NOT GIVEN
MOVE A,1(D)
JRST EV04
EV02: PUSH TP,(C)
HLLZS (TP) ; FIX UP LH
PUSH TP,1(C)
JSP E,CHKARG
MCALL 1,EVAL
POPJ P,
; MAPF/MAPR CALL TO APPLY
MQUOTE APPLY
MAPPLY: JRST APPLY
; APPLY, FALLS INTO EVAL'S APPLY CODE AT APLDIS
MFUNCTION APPLY,SUBR
ENTRY
JUMPGE AB,TFA ; MUST BE AT LEAST 1 ARGUMENT
MOVE A,AB
ADD A,[2,,2]
PUSH TP,$TAB
PUSH TP,A
PUSH TP,(AB) ; SAVE FCN
PUSH TP,1(AB)
PUSH TP,$TFIX ; AND ARG GETTER
PUSH TP,[SETZ APLARG]
PUSHJ P,APLDIS
JRST FINIS
; STACKFROM, ALSO FALLS INTO EVAL'S APPLIER AT APLDIS
MFUNCTION STACKFORM,FSUBR
ENTRY 1
GETYP A,(AB)
CAIE A,TLIST
JRST WTYP1
MOVEI A,3 ; CHECK ALL GOODIES SUPPLIED
HRRZ B,1(AB)
JUMPE B,TFA
HRRZ B,(B) ; CDR IT
SOJG A,.-2
HRRZ C,1(AB) ; GET LIST BACK
PUSHJ P,FASTEV ; DO A FAST EVALUATION
PUSH TP,(AB)
HRRZ C,@1(AB) ; POINT TO ARG GETTING FORMS
PUSH TP,C
PUSH TP,A ; AND FCN
PUSH TP,B
PUSH TP,$TFIX
PUSH TP,[SETZ EVALRG]
PUSHJ P,APLDIS
JRST FINIS
; OFFSETS FOR TEMPORARIES ETC. USED IN APPLYING STUFF
E.FRM==0 ; POINTS TO FORM BEING EVALED (OR ARGS FOR APPLY STACKFORM)
E.FCN==2 ; FUNCTION/SUBR/RSUBR BEING APPLIED
E.ARG==4 ; POINTS TO ARG GETTING ROUTINE (<0 => MUST EVAL ARGS)
E.EXTR==6 ; CONTAINS 1ST ARG IN USER APPLY CASE
E.SEG==10 ; POINTS TO SEGMENT IN FORM BEING HACKED
E.CNT==12 ; COUNTER FOR TUPLES OF ARGS
E.DECL==14 ; POINTS TO DECLARATION LIST IN FUNCTIONS
E.ARGL==16 ; POINTS TO ARG LIST IN FUNCTIONS
E.HEW==20 ; POINTS TO HEWITT ATOM IF IT EXISTS
E.VAL==E.ARGL ; VALUE TYPE FOR RSUBRS
MINTM==E.EXTR+2 ; MIN # OF TEMPS EVER ALLOCATED
E.TSUB==E.CNT+2 ; # OF TEMPS FOR SUBR/NUMBER APPLICATION
XP.TMP==E.HEW-E.EXTR ; # EXTRA TEMPS FOR FUNCTION APPLICATION
R.TMP==4 ; TEMPS AFTER ARGS ARE BOUND
TM.OFF==E.HEW+2-R.TMP ; TEMPS TO FLUSH AFTER BIND OF ARGS
RE.FCN==0 ; AFTER BINDING CONTAINS FCN BODY
RE.ARG==2 ; ARG LIST AFTER BINDING
; GENERAL THING APPLYER
APLDIS: PUSH TP,[0] ; SLOT USED FOR USER APPLYERS
PUSH TP,[0]
APLDIX: GETYP A,E.FCN(TB) ; GET TYPE
APLDI: SKIPE D,APLTYP+1(TVP) ; USER TABLE EXISTS?
JRST APLDI1 ; YES, USE IT
APLDI2: CAIG A,NUMPRI ; SKIP IF NOT PRIM
JRST @APTYPE(A)
JRST NAPT
APLDI1: ADDI D,(A) ; POINT TO SLOT
ADDI D,(A)
SKIPE (D) ; SKIP IF NOT GIVEN OR STANDARD
JRST APLDI3
APLDI4: SKIPE D,1(D) ; GET DISP
JRST (D)
JRST APLDI2 ; USE SYSTEM DISPATCH
APLDI3: SKIPE E.EXTR+1(TB) ; SKIP IF HAVEN'T BEEN HERE BEFORE
JRST APLDI4
MOVE A,(D) ; GET ITS HANDLER
EXCH A,E.FCN(TB) ; AND USE AS FCN
MOVEM A,E.EXTR(TB) ; SAVE
MOVE A,1(D)
EXCH A,E.FCN+1(TB)
MOVEM A,E.EXTR+1(TB) ; STASH OLD FCN AS EXTRG
GETYP A,(D) ; GET TYPE
JRST APLDI
; APPLY DISPATCH TABLE
DISTBL APTYPE,<SETZ NAPTL>,[[TSUBR,APSUBR],[TFSUBR,APFSUB],[TRSUBR,APRSUB],[TFIX,APNUM]
[TEXPR,APEXPR],[TFUNAR,APFUNARG],[TENTER,APENTR],[TMACRO,APMACR]]
; SUBR TO SAY IF TYPE IS APPLICABLE
MFUNCTION APPLIC,SUBR,[APPLICABLE?]
ENTRY 1
GETYP A,(AB)
PUSHJ P,APLQ
JRST IFALSE
JRST TRUTH
; HERE TO DETERMINE IF A TYPE IS APPLICABLE
APLQ: PUSH P,B
SKIPN B,APLTYP+1(TVP)
JRST USEPUR ; USE PURE TABLE
ADDI B,(A)
ADDI B,(A) ; POINT TO SLOT
SKIPG 1(B) ; SKIP IF WINNER
SKIPE (B) ; SKIP IF POTENIAL LOSER
JRST CPPJ1B ; WIN
SKIPE 1(B) ; SKIP IF MUST USE PURE TABBLE
JRST CPOPJB
USEPUR: CAIG A,NUMPRI ; SKIP IF NOT PRIM
SKIPL APTYPE(A) ; SKIP IF APLLICABLE
CPPJ1B: AOS -1(P)
CPOPJB: POP P,B
POPJ P,
; FSUBR APPLYER
APFSUBR:
SKIPN E.EXTR(TB) ; IF EXTRA ARG
SKIPGE E.ARG+1(TB) ; OR APPLY/STACKFORM, LOSE
JRST BADFSB
MOVE A,E.FCN+1(TB) ; GET FCN
HRRZ C,@E.FRM+1(TB) ; GET ARG LIST
SUB TP,[MINTM,,MINTM] ; FLUSH UNWANTED TEMPS
PUSH TP,$TLIST
PUSH TP,C ; ARG TO STACK
.MCALL 1,(A) ; AND CALL
POPJ P, ; AND LEAVE
; SUBR APPLYER
APSUBR:
PUSHJ P,PSH4ZR ; SET UP ZEROED SLOTS
SKIPN A,E.EXTR(TB) ; FUNNY ARGS
JRST APSUB1 ; NO, GO
MOVE B,E.EXTR+1(TB) ; YES , GET VAL
JRST APSUB2 ; AND FALL IN
APSUB1: PUSHJ P,@E.ARG+1(TB) ; EAT AN ARG
JRST APSUBD ; DONE
APSUB2: PUSH TP,A
PUSH TP,B
AOS E.CNT+1(TB) ; COUNT IT
JRST APSUB1
APSUBD: MOVE A,E.CNT+1(TB) ; FINISHED, GET COUNT
MOVE B,E.FCN+1(TB) ; AND SUBR
GETYP 0,E.FCN(TB)
CAIN 0,TENTER
JRST APENDN
PUSHJ P,BLTDN ; FLUSH CRUFT
.ACALL A,(B)
POPJ P,
BLTDN: MOVEI C,(TB) ; POINT TO DEST
HRLI C,E.TSUB(C) ; AND SOURCE
BLT C,-E.TSUB(TP) ;BL..............T
SUB TP,[E.TSUB,,E.TSUB]
POPJ P,
APENDN: PUSHJ P,BLTDN
APNDN1: .ECALL A,(B)
POPJ P,
; FLAGS FOR RSUBR HACKER
F.STR==1
F.OPT==2
F.QUO==4
F.NFST==10
; APPLY OBJECTS OF TYPE RSUBR
APENTR:
APRSUBR:
MOVE C,E.FCN+1(TB) ; GET THE RSUBR
CAML C,[-5,,] ; IS IT LONG ENOUGH FOR DECLS
JRST APSUBR ; NO TREAT AS A SUBR
GETYP 0,4(C) ; GET TYPE OF 3D ELEMENT
CAIE 0,TDECL ; DECLARATION?
JRST APSUBR ; NO, TREAT AS SUBR
PUSHJ P,PSH4ZR ; ALLOCATE SOME EXTRA ROOM
PUSH TP,$TDECL ; PUSH UP THE DECLS
PUSH TP,5(C)
PUSH TP,$TLOSE ; SAVE ROOM FOR VAL DECL
PUSH TP,[0]
SKIPN E.EXTR(TB) ; "EXTRA" ARG?
JRST APRSU1 ; NO,
MOVE 0,[SETZ EXTRGT] ; CHANGE THE ACCESS FCN
EXCH 0,E.ARG+1(TB)
HRRM 0,E.ARG(TB) ; REMEMBER IT
APRSU1: MOVEI 0,0 ; INIT FLAG REGISTER
PUSH P,0 ; SAVE
APRSU2: HRRZ A,E.DECL+1(TB) ; GET DECL LIST
JUMPE A,APRSU3 ; DONE!
HRRZ B,(A) ; CDR IT
MOVEM B,E.DECL+1(TB)
PUSHJ P,NXTDCL ; IS NEXT THING A STRING?
JRST APRSU4 ; NO, BETTER BE A TYPE
CAMN B,[ASCII /VALUE/]
JRST RSBVAL ; SAVE VAL DECL
TRON 0,F.NFST ; IF NOT FIRST, LOSE
CAME B,[ASCII /CALL/] ; CALL DECL
JRST APRSU7
SKIPGE E.ARG+1(TB) ; LEGAL?
JRST MPD
MOVE C,E.FRM(TB)
MOVE D,E.FRM+1(TB) ; GET FORM
JRST APRS10 ; HACK IT
APRSU5: TROE 0,F.STR ; STRING STRING?
JRST MPD ; LOSER
CAME B,[<ASCII /OPTIO/>+1] ; OPTIONA?
JRST APRSU8
TROE 0,F.OPT ; CHECK AND SET
JRST MPD ; OPTINAL OPTIONAL LOSES
JRST APRSU2 ; TO MAIN LOOP
APRSU7: CAME B,[ASCII /QUOTE/]
JRST APRSU5
TRO 0,F.STR
TROE 0,F.QUO ; TURN ON AND CHECK QUOTE
JRST MPD ; QUOTE QUOTE LOSES
JRST APRSU2 ; GO TO END OF LOOP
APRSU8: CAME B,[ASCII /ARGS/]
JRST APRSU9
SKIPGE E.ARG+1(TB) ; SKIP IF LEGAL
JRST MPD
HRRZ D,@E.FRM+1(TB) ; GET ARG LIST
MOVSI C,TLIST
APRS10: HRRZ A,(A) ; GET THE DECL
MOVEM A,E.DECL+1(TB) ; CLOBBER
HRRZ B,(A) ; CHECK FOR TOO MUCH
JUMPN B,MPD
MOVE B,1(A) ; GET DECL
HLLZ A,(A) ; GOT THE DECL
MOVEM 0,(P) ; SAVE FLAGS
JSP E,CHKAB ; CHECK DEFER
PUSH TP,C
PUSH TP,D ; SAVE
PUSHJ P,TMATCH
JRST WTYP
AOS E.CNT+1(TB) ; COUNT ARG
JRST APRDON ; GO CALL RSUBR
RSBVAL: HRRZ A,E.DECL+1(TB) ; GET DECL
JUMPE A,MPD
HRRZ B,(A) ; POINT TO DECL
MOVEM B,E.DECL+1(TB) ; SAVE NEW DECL POINTER
PUSHJ P,NXTDCL
JRST .+2
JRST MPD
MOVEM A,E.VAL+1(TB) ; SAVE VAL DECL
MOVSI A,TDCLI
MOVEM A,E.VAL(TB) ; SET ITS TYPE
JRST APRSU2
APRSU9: CAME B,[ASCII /TUPLE/]
JRST MPD
MOVEM 0,(P) ; SAVE FLAGS
HRRZ A,(A) ; CDR DECLS
MOVEM A,E.DECL+1(TB)
HRRZ B,(A)
JUMPN B,MPD ; LOSER
PUSH P,[0] ; COUNT ELEMENTS IN TUPLE
APRTUP: PUSHJ P,@E.ARG+1(TB) ; GOBBLE ARGS
JRST APRTPD ; DONE
PUSH TP,A
PUSH TP,B
AOS (P) ; COUNT IT
JRST APRTUP ; AND GO
APRTPD: POP P,C ; GET COUNT
ADDM C,E.CNT+1(TB) ; UPDATE MAIN COUNT
ASH C,1 ; # OF WORDS
HRLI C,TINFO ; BUILD FENCE POST
PUSH TP,C
PUSHJ P,TBTOTP ; GEN REL OFFSET TO TOP
PUSH TP,D
HRROI D,-1(TP) ; POINT TO TOP
SUBI D,(C) ; TO BASE
TLC D,-1(C)
MOVSI C,TARGS ; BUILD TYPE WORD
HLR C,OTBSAV(TB)
MOVE A,E.DECL+1(TB)
MOVE B,1(A)
HLLZ A,(A) ; TYPE/VAL
JSP E,CHKAB ; CHECK
PUSHJ P,TMATCH ; GOTO TYPE CHECKER
JRST WTYP
SUB TP,[2,,2] ; REMOVE FENCE POST
APRDON: SUB P,[1,,1] ; FLUSH CRUFT
MOVE A,E.CNT+1(TB) ; GET # OF ARGS
MOVE B,E.FCN+1(TB)
GETYP 0,E.FCN(TB) ; COULD BE ENTRY
MOVEI C,(TB) ; PREPARE TO BLT DOWN
HRLI C,E.TSUB+2(C)
BLT C,-E.TSUB+2(TP)
SUB TP,[E.TSUB+2,,E.TSUB+2]
CAIE 0,TRSUBR
JRST APNDN1
.ACALL A,(B) ; CALL THE RSUBR
JRST PFINIS
APRSU4: MOVEM 0,(P) ; SAVE FLAGS
MOVE B,1(A) ; GET DECL
HLLZ A,(A)
JSP E,CHKAB
MOVE 0,(P) ; RESTORE FLAGS
PUSH TP,A
PUSH TP,B ; AND SAVE
SKIPL E.ARG+1(TB) ; ALREADY EVAL'D
TRZN 0,F.QUO
JRST APREVA ; MUST EVAL ARG
MOVEM 0,(P)
HRRZ C,@E.FRM+1(TB) ; GET ARG?
TRNE 0,F.OPT ; OPTIONAL
JUMPE C,APRDN
JUMPE C,TFA ; NO, TOO FEW ARGS
MOVEM C,E.FRM+1(TB)
HLLZ A,(C) ; GET ARG
MOVE B,1(C)
JSP E,CHKAB ; CHECK THEM
APRTYC: MOVE C,A ; SET UP FOR TMATCH
MOVE D,B
EXCH B,(TP)
EXCH A,-1(TP) ; SAVE STUFF
APRS11: PUSHJ P,TMATCH ; CHECK TYPE
JRST WTYP
MOVE 0,(P) ; RESTORE FLAGS
TRZ 0,F.STR
AOS E.CNT+1(TB)
JRST APRSU2 ; AND GO ON
APREVA: PUSHJ P,@E.ARG+1(TB) ; EVAL ONE
TDZA C,C ; C=0 ==> NONE LEFT
MOVEI C,1
MOVE 0,(P) ; FLAGS
JUMPN C,APRTYC ; GO CHECK TYPE
APRDN: SUB TP,[2,,2] ; FLUSH DECL
TRNE 0,F.OPT ; OPTIONAL?
JRST APRDON ; ALL DONE
JRST TFA
APRSU3: TRNE 0,F.STR ; END IN STRING?
JRST MPD
PUSHJ P,@E.ARG+1(TB) ; SEE IF ANYMORE ARGS
JRST APRDON
JRST TMA
; STANDARD ARGUMENT GETTERS USED IN APPLYING THINGS
ARGCDR: HRRZ C,@E.FRM+1(TB) ; POINT TO ARGLIST (NOTE: POINTS 1 BEFORE WHERE ARG IS)
JUMPE C,CPOPJ ; LEAVE IF DONE
MOVEM C,E.FRM+1(TB)
GETYP 0,(C) ; GET TYPE OF ARG
CAIN 0,TSEG
JRST ARGCD1 ; SEG MENT HACK
PUSHJ P,FASTEV
JRST CPOPJ1
ARGCD1: PUSH TP,$TFORM ; PRETEND WE ARE A FORM
PUSH TP,1(C)
MCALL 1,EVAL
MOVEM A,E.SEG(TB)
MOVEM B,E.SEG+1(TB)
PUSHJ P,TYPSEG ; GET SEG TYPE CODE
HRRM C,E.ARG(TB) ; SAVE IT IN OBSCCURE PLACE
MOVE C,[SETZ SGARG]
MOVEM C,E.ARG+1(TB) ; SET NEW ARG GETTER
; FALL INTO SEGARG
SGARG: INTGO
HRRZ C,E.ARG(TB) ; SEG CODE TO C
MOVE D,E.SEG+1(TB)
MOVE A,E.SEG(TB)
MOVEM A,DSTO(PVP)
PUSHJ P,NXTLM ; GET NEXT ELEMENT
JRST SEGRG1 ; DONE
MOVEM D,E.SEG+1(TB)
MOVE D,DSTO(PVP) ; KEEP TYPE WINNING
MOVEM D,E.SEG(TB)
SETZM DSTO(PVP)
JRST CPOPJ1 ; RETURN
SEGRG1: SETZM DSTO(PVP)
MOVEI C,ARGCDR
MOVEM C,E.ARG+1(TB) ; RESET ARG GETTER
JRST ARGCDR
; ARGUMENT GETTER FOR APPLY
APLARG: INTGO
SKIPL A,E.FRM+1(TB) ; ANY ARGS LEFT
POPJ P, ; NO, EXIT IMMEDIATELY
ADD A,[2,,2]
MOVEM A,E.FRM+1(TB)
MOVE B,-1(A) ; RET NEXT ARG
MOVE A,-2(A)
JRST CPOPJ1
; STACKFORM ARG GETTER
EVALRG: SKIPN C,@E.FRM+1(TB) ; ANY FORM?
POPJ P,
PUSHJ P,FASTEV
GETYP A,A ; CHECK FOR FALSE
CAIN A,TFALSE
POPJ P,
MOVE C,E.FRM+1(TB) ; GET OTHER FORM
PUSHJ P,FASTEV
JRST CPOPJ1
; HERE TOO APPLY NUMBERS
APNUM: PUSHJ P,PSH4ZR ; TP SLOSTS
SKIPN A,E.EXTR(TB) ; FUNNY ARG?
JRST APNUM1 ; NOPE
MOVE B,E.EXTR+1(TB) ; GET ARG
JRST APNUM2
APNUM1: PUSHJ P,@E.ARG+1(TB) ; GET ARG
JRST TFA
APNUM2: PUSH TP,A
PUSH TP,B
PUSH TP,E.FCN(TB)
PUSH TP,E.FCN+1(TB)
PUSHJ P,@E.ARG+1(TB)
JRST .+2
JRST TMA
PUSHJ P,BLTDN ; FLUSH JUNK
MCALL 2,NTH
POPJ P,
; HERE TO APPLY SUSSMAN FUNARGS
APFUNARG:
SKIPN C,E.FCN+1(TB)
JRST FUNERR
HRRZ D,(C) ; MUST BE AT LEAST 2 LONG
JUMPE D,FUNERR
GETYP 0,(D) ; CHECK FOR LIST
CAIE 0,TLIST
JRST FUNERR
HRRZ 0,(D) ; SHOULD BE END
JUMPN 0,FUNERR
GETYP 0,(C) ; 1ST MUST BE FCN
CAIE 0,TEXPR
JRST FUNERR
SKIPN C,1(C)
JRST NOBODY
PUSHJ P,APEXPF ; BIND THE ARGS AND AUX'S
HRRZ C,RE.FCN+1(TB) ; GET BODY OF FUNARG
MOVE B,1(C) ; GET FCN
MOVEM B,RE.FCN+1(TB) ; AND SAVE
HRRZ C,(C) ; CDR FUNARG BODY
MOVE C,1(C)
MOVSI 0,TLIST ; SET UP TYPE
MOVEM 0,CSTO(PVP) ; FOR INTS TO WIN
FUNLP: INTGO
JUMPE C,DOF ; RUN IT
GETYP 0,(C)
CAIE 0,TLIST ; BETTER BE LIST
JRST FUNERR
PUSH TP,$TLIST
PUSH TP,C
PUSHJ P,NEXTDC ; GET POSSIBILITY
JRST FUNERR ; LOSER
CAIE A,2
JRST FUNERR
HRRZ B,(B) ; GET TO VALUE
MOVE C,(TP)
SUB TP,[2,,2]
PUSH TP,BNDA
PUSH TP,E
HLLZ A,(B) ; GET VAL
MOVE B,1(B)
JSP E,CHKAB ; HACK DEFER
PUSHJ P,PSHAB4 ; PUT VAL IN
HRRZ C,(C) ; CDR
JUMPN C,FUNLP
; HERE TO RUN FUNARG
DOF: SETZM CSTO(PVP) ; DONT CONFUSE GC
PUSHJ P,SPECBIND ; BIND 'EM UP
JRST RUNFUN
; HERE TO DO MACROS
APMACR: HRRZ E,OTBSAV(TB)
HRRZ E,PCSAV(E) ; SEE WHERE FROM
CAIN E,AEVAL3 ; SKIP IF NOT RIGHT
JRST APMAC1
SKIPG E.ARG+1(TB) ; SKIP IF REAL FORM EXISTS
JRST BADMAC
MOVE A,E.FRM(TB)
MOVE B,E.FRM+1(TB)
SUB TP,[E.EXTR+2,,E.EXTR+2] ; FLUSH JUNK
PUSH TP,A
PUSH TP,B
MCALL 1,EXPAND ; EXPAND THE MACRO
PUSH TP,A
PUSH TP,B
MCALL 1,EVAL ; EVAL THE RESULT
POPJ P,
APMAC1: MOVE C,E.FCN+1(TB) ; GET MACRO BODY
GETYP A,(C)
MOVE B,1(C)
MOVSI A,(A)
JSP E,CHKAB ; FIX DEFERS
MOVEM A,E.FCN(TB)
MOVEM B,E.FCN+1(TB)
JRST APLDIX
; HERE TO APPLY EXPRS (FUNCTIONS)
APEXPR: PUSHJ P,APEXP ; BIND ARGS AND AUX'S
RUNFUN: HRRZ A,RE.FCN(TB) ; AMOUNT OF FCN TO SKIP
MOVEI C,RE.FCN+1(TB) ; POINT TO FCN
HRRZ C,(C) ; SKIP SOMETHING
SOJGE A,.-1 ; UNTIL 1ST FORM
MOVEM C,RE.FCN+1(TB) ; AND STORE
JRST DOPROG ; GO RUN PROGRAM
APEXP: SKIPN C,E.FCN+1(TB) ; CHECK FRO BODY
JRST NOBODY
APEXPF: PUSH P,[0] ; COUNT INIT CRAP
ADD TP,[XP.TMP,,XP.TMP] ; SLOTS FOR HACKING
SKIPL TP
PUSHJ P,TPOVFL
SETZM 1-XP.TMP(TP) ; ZERO OUT
MOVEI A,-XP.TMP+2(TP)
HRLI A,-1(A)
BLT A,(TP) ; ZERO SLOTS
PUSHJ P,CARATC ; SEE IF HEWITT ATOM EXISTS
JRST APEXP1 ; NO, GO LOOK FOR ARGLIST
MOVEM E,E.HEW+1(TB) ; SAVE ATOM
MOVSM 0,E.HEW(TB) ; AND TYPE
AOS (P) ; COUNT HEWITT ATOM
APEXP1: GETYP 0,(C) ; LOOK AT NEXT THING
CAIE 0,TLIST ; BETTER BE LIST!!!
JRST MPD.0 ; LOSE
MOVE B,1(C) ; GET LIST
MOVEM B,E.ARGL+1(TB) ; SAVE
MOVSM 0,E.ARGL(TB) ; WITH TYPE
HRRZ C,(C) ; CDR THE FCN
JUMPE C,NOBODY ; BODYLESS FCN
GETYP 0,(C) ; SEE IF DCL LIST SUPPLIED
CAIE 0,TDECL
JRST APEXP2 ; NO, START PROCESSING ARGS
AOS (P) ; COUNT DCL
MOVE B,1(C)
MOVEM B,E.DECL+1(TB)
MOVSM 0,E.DECL(TB)
HRRZ C,(C) ; CDR ON
JUMPE C,NOBODY
; CHECK FOR EXISTANCE OF EXTRA ARG
APEXP2: POP P,A ; GET COUNT
HRRM A,E.FCN(TB) ; AND SAVE
SKIPN E.EXTR(TB) ; SKIP IF FUNNY EXTRA ARG EXISTS
JRST APEXP3
MOVE 0,[SETZ EXTRGT]
EXCH 0,E.ARG+1(TB)
HRRM 0,E.ARG(TB) ; SAVE OLD GETTER AROUND
; FALL THROUGH
; LOOK FOR "BIND" DECLARATION
APEXP3: PUSHJ P,UNPROG ; UNASSIGN LPROG IF NEC
APXP3A: SKIPN A,E.ARGL+1(TB) ; GET ARGLIST
JRST APEXP4 ; NONE, VERIFY NONE WERE GIVEN
PUSHJ P,NXTDCL ; SEE IF A DECL IS THERE
JRST BNDRG ; NO, GO BIND NORMAL ARGS
HRRZ C,(A) ; CDR THE DCLS
CAME B,[ASCII /BIND/]
JRST CH.CAL ; GO LOOK FOR "CALL"
PUSHJ P,CARTMC ; MUST BE AN ATOM
MOVEM C,E.ARGL+1(TB) ; AND SAVE CDR'D ARGS
PUSHJ P,MAKENV ; GENERATE AN ENVIRONMENT
PUSHJ P,PSBND1 ; PUSH THE BINDING AND CHECK THE DCL
JRST APXP3A ; IN CASE <"BIND" B "BIND" C......
; LOOK FOR "CALL" DCL
CH.CAL: CAME B,[ASCII /CALL/]
JRST CHOPT ; TRY SOMETHING ELSE
SKIPG E.ARG+1(TB) ; DONT SKIP IF CANT WIN
JRST MPD.2
PUSHJ P,CARTMC ; BETTER BE AN ATOM
MOVEM C,E.ARGL+1(TB)
MOVE A,E.FRM(TB) ; RETURN FORM
MOVE B,E.FRM+1(TB)
PUSHJ P,PSBND1 ; BIND AND CHECK
JRST APEXP5
; BIND NORMAL ARGS BY CALLING BNDEM1, RETURNS WHEN ALL DONE
BNDRG: PUSHJ P,BNDEM1 ; GO BIND THEM UP
TRNN A,4 ; SKIP IF HIT A DCL
JRST APEXP4 ; NOT A DCL, MUST BE DONE
; LOOK FOR "OPTIONAL" DECLARATION
CHOPT: CAME B,[<ASCII /OPTIO/>+1]
JRST CHREST ; TRY TUPLE/ARGS
MOVEM C,E.ARGL+1(TB) ; SAVE RESTED ARGLIST
PUSHJ P,BNDEM2 ; DO ALL SUPPLIED OPTIONALS
TRNN A,4 ; SKIP IF NEW DCL READ
JRST APEXP4
; CHECK FOR "ARGS" DCL
CHREST: CAME B,[ASCII /ARGS/]
JRST CHRST1 ; GO LOOK FOR "TUPLE"
SKIPGE E.ARG+1(TB) ; SKIP IF LEGAL
JRST MPD.3
PUSHJ P,CARTMC ; GOBBLE ATOM
MOVEM C,E.ARGL+1(TB) ; SAVE CDR'D ARG
HRRZ B,@E.FRM+1(TB) ; GET ARG LIST
MOVSI A,TLIST ; GET TYPE
PUSHJ P,PSBND1
JRST APEXP5
; HERE TO CHECK FOR "TUPLE"
CHRST1: CAME B,[ASCII /TUPLE/]
JRST APXP10
PUSHJ P,CARTMC ; GOBBLE ATOM
MOVEM C,E.ARGL+1(TB)
SETZB A,B
PUSHJ P,PSHBND ; SET UP BINDING
SETZM E.CNT+1(TB) ; ZERO ARG COUNTER
TUPLP: PUSHJ P,@E.ARG+1(TB) ; GET AN ARG
JRST TUPDON ; FINIS
AOS E.CNT+1(TB)
PUSH TP,A
PUSH TP,B
JRST TUPLP
TUPDON: PUSHJ P,MAKINF ; MAKE INFO CELL
PUSH TP,$TINFO ; FENCE POST TUPLE
PUSHJ P,TBTOTP
ADDI D,TM.OFF ; COMPENSATE FOR MOVEMENT
PUSH TP,D
MOVE C,E.CNT+1(TB) ; GET COUNT
ASH C,1 ; TO WORDS
HRRM C,-1(TP) ; INTO FENCE POST
MOVEI B,-TM.OFF-1(TP) ; SETUP ARG POINTER
SUBI B,(C) ; POINT TO BASE OF TUPLE
MOVNS C ; FOR AOBJN POINTER
HRLI B,(C) ; GOOD ARGS POINTER
MOVEM A,TM.OFF-4(B) ; STORE
MOVEM B,TM.OFF-3(B)
; CHECK FOR VALID ENDING TO ARGS
APEXP5: PUSHJ P,NEXTD ; READ NEXT THING IN ARGLIST
JRST APEXP8 ; DONE
TRNN A,4 ; SKIP IF DCL
JRST MPD.4 ; LOSER
APEXP7: MOVSI A,-NWINS ; CHECK FOR A WINNER
CAME B,WINRS(A)
AOBJN A,.-1
JUMPE A,MPD.6 ; NOT A WINNER
; HERE TO BLT THE WORLD DOWN ON TOP OF ALL THE USELESS TEMPS
APEXP8: MOVE 0,E.HEW+1(TB) ; GET HEWITT ATOM
MOVE E,E.FCN(TB) ; SAVE COUNTER
MOVE C,E.FCN+1(TB) ; FCN
MOVE B,E.ARGL+1(TB) ; ARG LIST
MOVE D,E.DECL+1(TB) ; AND DCLS
MOVEI A,R.TMP(TB) ; SET UP BLT
HRLI A,TM.OFF(A)
BLT A,-TM.OFF(TP) ; BLLLLLLLLLLLLLT
SUB TP,[TM.OFF,,TM.OFF] ; FLUSH CRUFT
MOVEM E,RE.FCN(TB)
MOVEM C,RE.FCN+1(TB)
MOVEM B,RE.ARGL+1(TB)
MOVE E,TP
PUSH TP,$TATOM
PUSH TP,0
PUSH TP,$TDECL
PUSH TP,D
GETYP A,-5(TP) ; TUPLE ON TOP?