-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLOOPSSTRUC
1450 lines (1196 loc) · 66.9 KB
/
LOOPSSTRUC
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
(DEFINE-FILE-INFO PACKAGE "INTERLISP" READTABLE "INTERLISP" BASE 10)
(FILECREATED "19-Aug-2022 14:47:13" {DSK}<home>larry>loops>system>LOOPSSTRUC.;2 67241
:CHANGES-TO (VARS LOOPSSTRUCCOMS)
:PREVIOUS-DATE " 6-Jul-2022 15:03:42" {DSK}<home>larry>loops>system>LOOPSSTRUC.;1)
(* ; "
Copyright (c) 1983-1988, 1990-1991, 1993 by Venue & Xerox Corporation.
")
(PRETTYCOMPRINT LOOPSSTRUCCOMS)
(RPAQQ LOOPSSTRUCCOMS
(
(* ;;;
"Basic records, operations and macros for dealing with implementation of classes and instances")
(* ;; "Variables and constants used by LOOPS")
(GLOBALVARS ErrorOnNameConflict ListMixinNames DefaultComment LASTCLASS LispClassTable
NotSetValue NoValueFound ObjNameTable)
(ADDVARS (GLOBALVARS ErrorOnNameConflict ListMixinNames DefaultComment LASTCLASS
LispClassTable NotSetValue NoValueFound ObjNameTable))
(INITVARS (NoValueFound NIL)
(ListMixinNames)
(DefaultComment)
(OutInstances)
(PPDefault T)
(LASTCLASS)
(ErrorOnNameConflict)
(ObjNameTable (HASHARRAY 8000))
(LispClassTable (HASHARRAY 16)))
(* ;
"Bootstrap value for NotSetValue. This gets fixed later on in the loadup.")
(INITVARS (NotSetValue (create annotatedValue)))
(* ;; "Access macros for instances")
(DECLARE%: EVAL@COMPILE DONTCOPY (FILES (LOADCOMP)
LOOPSDATATYPES)
(EXPORT (FUNCTIONS Once-Only)
(FUNCTIONS WithIVValue ChangeIVValue)
(RECORDS IVPropDescr)
(MACROS FetchIVPropDescr)
(FUNCTIONS MakeIVPropDescr WithIVPropDescr WithIVPropDescr!)
(MACROS InstGetProp InstPutProp InstRemProp)
(MACROS ExtractRealValue))
DONTEVAL@LOAD
(FILES (LOADCOMP)
LOOPSDATATYPES)
DONTEVAL@COMPILE DOCOPY (INITRECORDS IVPropDescr))
(* ;; "Access macros for classes and the like")
(DECLARE%: EVAL@COMPILE DONTCOPY (EXPORT (RECORDS IVDescr))
DONTEVAL@COMPILE DOCOPY (INITRECORDS IVDescr))
(COMS (MACROS /PutNth Class ClassVariables FetchCIVDescr FetchCVDescr FetchIVDescr FindIndex
GetCIVNth GetClassDescr GetInstanceIVValue GetNth GetVarNth NDescrs NotSetValue
NoValueFound ValueFound ObjGetProp ObjPutProp ObjRemProp ObjSetValue PutIVDescr
PutNth PutVarNth Supers)
(FUNCTIONS GetInitialValue))
(* ;; "Access expressions")
(MACROS $ @ @* _@)
(FNS Parse@ Parse@* ParseAccess ParseBang ParseExpr ParsePut@)
(PROP ARGNAMES @ _@)
(PROP INFO $ @ @* _@)
(* ;; "Interface Functions")
(FNS CreateEntity DeleteObjectName FastClassInitialize GetIVHere GetValueOnly GetClassRec
GetLispClass GetObjectName GetObjectRec MakeMixinClass NameEntity NewEntity
PutObjectName PutValueOnly $!)
(* ;; "IV Lookup cache stuff")
(DECLARE%: EVAL@COMPILE DONTCOPY (EXPORT (MACROS FindVarIndex FastFindIndex)))
(* ;; "Functions which build and change structure")
(FNS BlankInstance BootNameObject FullNameObject FillInst FillIVs IVSource ModifyInstance
NewClass NewObject UpdateClassIVs UpdateIVDescrs)
(P (MOVD? 'BootNameObject 'NameObject))
(ADDVARS (NLAMA DEFINST DEFINSTANCES DEFCLASS DEFCLASSES @ _@))
(I.S.OPRS IN-SUPERS-OF)))
(* ;;; "Basic records, operations and macros for dealing with implementation of classes and instances"
)
(* ;; "Variables and constants used by LOOPS")
(DECLARE%: DOEVAL@COMPILE DONTCOPY
(GLOBALVARS ErrorOnNameConflict ListMixinNames DefaultComment LASTCLASS LispClassTable NotSetValue
NoValueFound ObjNameTable)
)
(ADDTOVAR GLOBALVARS ErrorOnNameConflict ListMixinNames DefaultComment LASTCLASS LispClassTable
NotSetValue NoValueFound ObjNameTable)
(RPAQ? NoValueFound NIL)
(RPAQ? ListMixinNames )
(RPAQ? DefaultComment )
(RPAQ? OutInstances )
(RPAQ? PPDefault T)
(RPAQ? LASTCLASS )
(RPAQ? ErrorOnNameConflict )
(RPAQ? ObjNameTable (HASHARRAY 8000))
(RPAQ? LispClassTable (HASHARRAY 16))
(* ; "Bootstrap value for NotSetValue. This gets fixed later on in the loadup.")
(RPAQ? NotSetValue (create annotatedValue))
(* ;; "Access macros for instances")
(DECLARE%: EVAL@COMPILE DONTCOPY
(FILESLOAD (LOADCOMP)
LOOPSDATATYPES)
(* "FOLLOWING DEFINITIONS EXPORTED")
(DEFMACRO Once-Only (vars &BODY body)
[LET ((Gensym-Var (GENSYM))
(Run-time-Vars (GENSYM))
(Run-time-Vals (GENSYM))
(Expand-time-Val-Forms NIL))
[SETQ Expand-time-Val-Forms (for var in vars
collect `(COND
([OR (LITATOM ,var)
(NUMBERP ,var)
(AND (LISTP ,var)
(MEMB (CAR ,var)
''FUNCTION]
,var)
(T (LET ((,Gensym-Var (GENSYM)))
(push ,Run-time-Vars ,Gensym-Var)
(push ,Run-time-Vals ,var)
,Gensym-Var]
`(LET* (,Run-time-Vars ,Run-time-Vals (WRAPPED-BODY ([LAMBDA ,vars ., body]
., Expand-time-Val-Forms)))
(COND
((NULL ,Run-time-Vars)
WRAPPED-BODY)
(T `([LAMBDA ,(DREVERSE ,Run-time-Vars)
(DECLARE (LOCALVARS . T))
,WRAPPED-BODY]
.,
(DREVERSE ,Run-time-Vals])
(DEFMACRO WithIVValue (self ivName ifFound ifNotFound &OPTIONAL (cache NIL))
[Once-Only (self ivName cache)
(LET [(value (GENSYM 'value))
(varDescr (GENSYM 'varDescr]
(if cache
then `[if [AND (\GETBASEPTR ,cache 0)
(EQ (\GETBASEPTR ,cache 0)
(fetch (OBJECT VARNAMES) of ,self]
then (,ifFound ,self ,ivName (GetVarNth ,self (\GETBASEPTR ,cache 2))
(\GETBASEPTR ,cache 2))
else (PROG (,value ,varDescr)
(DECLARE (LOCALVARS . T))
(SETQ ,varDescr (FindVarIndex ,ivName ,self))
(COND
(,varDescr (\PUTBASEPTR ,cache 0 (fetch (OBJECT VARNAMES)
of ,self))
(\PUTBASEPTR ,cache 2 ,varDescr)
(SETQ ,value (GetVarNth ,self ,varDescr))
(GO IVFound)))
[SETQ ,varDescr (ASSOC ,ivName (fetch (instance otherIVs)
of ,self]
(COND
(,varDescr (SETQ ,value (CDR ,varDescr))
(GO IVFound)))
(COND
((FIXP ,ivName)
(SETQ ,value (FetchNthDescr ,self ,ivName))
(GO IVFound)))
(RETURN (,ifNotFound ,self ,ivName))
IVFound
(RETURN (,ifFound ,self ,ivName ,value ,varDescr]
else `(PROG (,value ,varDescr)
(DECLARE (LOCALVARS . T))
(SETQ ,varDescr (FindVarIndex ,ivName ,self))
(COND
(,varDescr (SETQ ,value (GetVarNth ,self ,varDescr))
(GO IVFound)))
[SETQ ,varDescr (ASSOC ,ivName (fetch (instance otherIVs)
of ,self]
(COND
(,varDescr (SETQ ,value (CDR ,varDescr))
(GO IVFound)))
(COND
((FIXP ,ivName)
(SETQ ,value (FetchNthDescr ,self ,ivName))
(GO IVFound)))
(RETURN (,ifNotFound ,self ,ivName))
IVFound
(RETURN (,ifFound ,self ,ivName ,value ,varDescr])
(DEFMACRO ChangeIVValue (self varName ivLoc newValue)
[Once-Only (self varName ivLoc newValue)
`(PROGN (COND
((FIXP ,ivLoc)
(PutVarNth ,self ,ivLoc ,newValue))
((LISTP ,ivLoc)
(RPLACD ,ivLoc ,newValue))
(T (SHOULDNT)))
,newValue])
(DECLARE%: EVAL@COMPILE
(RECORD IVPropDescr (IVName . IVPropList)
(SYSTEM))
)
(DECLARE%: EVAL@COMPILE
(PUTPROPS FetchIVPropDescr MACRO ((self ivName)
(ASSOC ivName (fetch instIVProps of self))))
)
(DEFMACRO MakeIVPropDescr (self varName)
`[CAR (push (fetch (instance instIVProps) of ,self)
(create IVPropDescr
IVName _ ,varName])
(DEFMACRO WithIVPropDescr (self ivName ifFound ifIVNotFound &OPTIONAL (cache NIL))
`(WithIVValue ,self ,ivName [LAMBDA (self ivName)
(,ifFound self ivName (FetchIVPropDescr self ivName]
,ifIVNotFound
,cache))
(DEFMACRO WithIVPropDescr! (self ivName ifFound ifIVNotFound &OPTIONAL (cache NIL))
`(WithIVValue ,self ,ivName [LAMBDA (self ivName)
(,ifFound self ivName (OR (FetchIVPropDescr self ivName)
(MakeIVPropDescr self ivName]
,ifIVNotFound
,cache))
(DECLARE%: EVAL@COMPILE
(PUTPROPS InstGetProp MACRO [OPENLAMBDA (descr propName)
(COND
((NULL descr)
NotSetValue)
(T (for tail on (fetch IVPropList of descr)
declare%: (LOCALVARS . T) by (CDDR tail)
do [COND
((EQ propName (CAR tail))
(RETURN (CADR tail] finally (RETURN NotSetValue])
(PUTPROPS InstPutProp MACRO (OPENLAMBDA (descr propName value)
(if (NULL (fetch IVPropList of descr))
then (change (fetch IVPropList of descr)
(LIST propName value))
value
else (LISTPUT (fetch IVPropList of descr)
propName value))))
(PUTPROPS InstRemProp MACRO
[OPENLAMBDA (descr propName)
(* * descr in an IVPropDescr with fields IVName and IVPropList Removes a property
from that list. RETURNS NIL if not found, propname otherwise)
(AND descr (LET ((propList (fetch IVPropList of descr)))
(if (NULL propList)
then NIL
elseif (EQ propName (CAR propList))
then (replace IVProps of descr with (CDDR propList))
propName
else (for tail on (CDR propList) by (CDDR tail)
do (if (NULL (CDR tail))
then (RETURN NIL)
elseif (EQ propName (CADR tail))
then (RPLACD tail (CDDDR tail))
(RETURN propName])
)
(DECLARE%: EVAL@COMPILE
(PUTPROPS ExtractRealValue MACRO (OPENLAMBDA (self varName value propName type)
(* Called by Fetches and Gets which want to notice activeValues.
type is one of NIL for instance variables, CLASS for class properties, METHOD for
method properties and CV for class variables and properties.
Returns either the value found or the result of evaluating the GETFN)
(COND
((type? annotatedValue value)
(_ (fetch annotatedValue of value)
GetWrappedValue self varName propName type))
(T value))))
)
(* "END EXPORTED DEFINITIONS")
DONTEVAL@LOAD
(FILESLOAD (LOADCOMP)
LOOPSDATATYPES)
DONTEVAL@COMPILE DOCOPY
)
(* ;; "Access macros for classes and the like")
(DECLARE%: EVAL@COMPILE DONTCOPY
(* "FOLLOWING DEFINITIONS EXPORTED")(DECLARE%: EVAL@COMPILE
(RECORD IVDescr (IVValue . IVProps)
IVValue _ NotSetValue IVProps _ NIL (SYSTEM))
)
(* "END EXPORTED DEFINITIONS")
DONTEVAL@COMPILE DOCOPY
)
(DECLARE%: EVAL@COMPILE
(PUTPROPS /PutNth MACRO ((list index entry)
(/RPLACA (FNTH list index)
entry)))
(PUTPROPS Class MACRO [OPENLAMBDA (self)
(COND
((Object? self)
(fetch (OBJECT CLASS) of self))
(T (GetLispClass self])
(PUTPROPS ClassVariables MACRO ((self)
(APPEND (fetch (class cvNames) of self))))
(PUTPROPS FetchCIVDescr MACRO [(self varName)
(PROG NIL
(RETURN (GetNth (fetch VARDESCRS of self)
(OR (FindIndex varName (fetch VARNAMES
of self))
(RETURN NIL])
(PUTPROPS FetchCVDescr MACRO [(classRec varName)
(PROG [(index (FindIndex varName (fetch cvNames of classRec]
(RETURN (COND
(index (GetNth (fetch cvDescrs of classRec)
index])
(PUTPROPS FetchIVDescr MACRO [OPENLAMBDA (self varName)
(LET (descr (varIndex (FindVarIndex varName self)))
(DECLARE (LOCALVARS varIndex descr))
(COND
(varIndex (OR (GetVarNth self varIndex)
(create IVDescr)))
[(SETQ descr (ASSOC varName (fetch otherIVs of self)))
(OR (CDR descr)
(CDR (NCONC1 descr (create IVDescr]
((FIXP varName)
(FetchNthDescr self varName])
(PUTPROPS FindIndex MACRO (OPENLAMBDA (entry table)
(for item in table as pos from 0 declare%: (LOCALVARS . T)
do (if (EQ item entry)
then (RETURN pos)) finally (RETURN NIL))))
(PUTPROPS GetCIVNth MACRO (OPENLAMBDA (obj n)
(GetNth (fetch VARDESCRS of obj)
n)))
(PUTPROPS GetClassDescr MACRO (OPENLAMBDA (class)
(CONS (fetch metaClass of class)
(fetch otherClassDescription of class))))
(PUTPROPS GetInstanceIVValue MACRO [OPENLAMBDA (object ivName)
(WithIVValue object ivName [LAMBDA (self varName value)
(ExtractRealValue self varName
value NIL 'IV]
(LAMBDA (self varName)
(_ self IVMissing varName NIL 'GetValue)])
(PUTPROPS GetNth MACRO [OPENLAMBDA (table index)
(CAR (FNTH table (ADD1 index])
(PUTPROPS GetVarNth MACRO (OPENLAMBDA (obj n)
(\GETBASEPTR (fetch VARDESCRS of obj)
(LLSH n 1))))
(PUTPROPS NDescrs MACRO (OPENLAMBDA (n)
(\ALLOCBLOCK n T)))
(PUTPROPS NotSetValue MACRO ((arg)
(EQ NotSetValue arg)))
(PUTPROPS NoValueFound MACRO ((arg)
(EQ NoValueFound arg)))
(PUTPROPS ValueFound MACRO ((arg)
(NEQ NoValueFound arg)))
(PUTPROPS ObjGetProp MACRO [OPENLAMBDA (descr propName)
(COND
((NULL descr)
NotSetValue)
((NULL propName)
(fetch IVValue of descr))
(T (for tail on (fetch IVProps of descr) by (CDDR tail)
do [COND
((EQ propName (CAR tail))
(RETURN (CADR tail] finally (RETURN NotSetValue])
(PUTPROPS ObjPutProp MACRO (OPENLAMBDA (descr propName value)
(COND
((NULL propName)
(replace IVValue of descr with value))
(T (change (fetch IVProps of descr)
(if (NULL DATUM)
then (LIST propName value)
else (LISTPUT DATUM propName value)
DATUM))
value))))
(PUTPROPS ObjRemProp MACRO [OPENLAMBDA (descr propName)
(LET ((propList (fetch IVPropList of descr)))
(if (NULL propList)
then NIL
elseif (EQ propName (CAR propList))
then (replace IVProps of descr with (CDDR propList))
propName
else (for tail on (CDR propList) by (CDDR tail)
do (if (NULL (CDR tail))
then (RETURN NIL)
elseif (EQ propName (CADR tail))
then (RPLACD tail (CDDDR tail))
(RETURN propName])
(PUTPROPS ObjSetValue MACRO [(self varName newValue descr aValue propName type)
(COND
((type? annotatedValue aValue)
(_ (fetch annotatedValue of aValue)
PutWrappedValue self varName newValue propName type))
(T (ObjPutProp descr propName newValue])
(PUTPROPS PutIVDescr MACRO [OPENLAMBDA (obj ivName ivDescr)
[WithIVValue obj ivName [LAMBDA (self varName oldValue loc)
(ChangeIVValue self varName loc (CAR ivDescr]
(LAMBDA (self varName)
(AddIV self varName (CAR ivDescr]
(if (CDR ivDescr)
then (WithIVPropDescr! obj ivName [LAMBDA (self varName propDescr)
(replace IVPropList of propDescr
with (CDR ivDescr]
(LAMBDA (self varName)
(HELPCHECK])
(PUTPROPS PutNth MACRO ((list index entry)
(RPLACA (FNTH list (ADD1 index))
entry)))
(PUTPROPS PutVarNth MACRO (OPENLAMBDA (obj n desc)
(\RPLPTR (fetch VARDESCRS of obj)
(LLSH n 1)
desc)))
(PUTPROPS Supers MACRO ((classRec)
(fetch supers of classRec)))
)
(DEFMACRO GetInitialValue (self varName ivDescr)
(* ;;; "Compute the initial value to store in the self iv")
`[for p on (fetch (IVDescr IVProps) of ,ivDescr) by CDDR declare%: (LOCALVARS . T)
thereis (EQ (CAR p)
'%:initForm) finally (RETURN (if (NULL $$VAL)
then NotSetValue
else (LET ((self ,self)
(varName ,varName))
(DECLARE (SPECVARS self varName))
(EVAL (CADR $$VAL])
(* ;; "Access expressions")
(DECLARE%: EVAL@COMPILE
(PUTPROPS $ MACRO [name (LIST 'GetObjectRec (KWOTE (CAR name])
(PUTPROPS @ MACRO (arg (Parse@ arg 'IV)))
(PUTPROPS @* MACRO (accessPath (Parse@* accessPath)))
(PUTPROPS _@ MACRO (arg (ParsePut@ arg 'IV)))
)
(DEFINEQ
(Parse@
[LAMBDA (exp type) (* smL "13-Apr-87 16:05")
(* exp is a list with 1, 2 or 3 elements.
If 1, then it is a reference to a variable of self determined by type.
If 2 elements, then the first one is an expression to be evaluated to give an
object and the second like the previous single element.
If 3 then it is like 2 but with a property of that variable specified)
(LET (n val (v (CAR exp))
(obj 'self))
[COND
((CDR exp)
(SETQ obj v)
(SETQ v (CADR exp]
(COND
((AND (NLISTP v)
(SETQ n (STRPOSL (CONSTANT (CHCON '_))
v))) (* This has an embedded assignment)
(ParsePut@ [LIST obj (SUBATOM v 1 (SUB1 n))
(COND
((EQ n (NCHARS v)) (* _ at end)
(AND [NEQ v (SETQ val (CAR (LAST exp]
(OR (AND (ATOM val)
(ParseAccess val 'IV 'self 1))
val)))
(T (ParseAccess v 'IV 'self (ADD1 n]
type))
(T (LET ((trans (ParseAccess v type obj 1))
(v (CDDR exp)))
[COND
(v (* Now take care of property)
(SETQ trans (ParseAccess (CAR v)
'PROP trans 1]
(if (GREATERP (LENGTH trans)
4)
then
(ERROR "Invalid access expression" exp))
trans])
(Parse@*
[LAMBDA (path objectExpr) (* ; "Edited 27-May-87 15:33 by smL")
(* * Parse@* parses (@* X ivName1 ivName2 ivName3) into
(GetValue (GetValue (GetValue X (QUOTE ivName1))
(QUOTE ivName2)) (QUOTE ivName3)) to)
(COND
((NULL path)
objectExpr)
((NULL objectExpr)
(Parse@* (CDR path)
(CAR path)))
(T (Parse@* (CDR path)
`(GetValue ,objectExpr ',(CAR path])
(ParseAccess
[LAMBDA (input exprType currentExpr start) (* ; "Edited 27-May-87 15:33 by smL")
(* * Parse an expression containing %: (iv) |::| cv %:, prop and those followed
by !. expr type is IV CV PROP MSG PERSP.)
(DECLARE (SPECVARS input))
(PROG [a e (n start)
(nt exprType)
(charList (CONSTANT (CHCON '|,.:|]
(COND
((NULL input) (* Dont Parse NIL)
(RETURN))
((NOT (OR (ATOM input)
(STRINGP input))) (* needs to be evaluated, and not
parsed)
(SETQ a input)
(GO MKEXPR)))
BANGLOOP
(* The following SELECTQ used to contain a branch
((\, (SETQ nt (QUOTE PERSP)))) (\, but) that got removed with the goings of
perspectives)
(SELECTQ (NTHCHAR input n)
($ (SETQ nt 'LOOPSNAME))
(! [COND
((EQ nt 'MSG)
(SETQ nt 'MSG!]
(SETQ e (ParseBang input 'IV currentExpr (ADD1 n)
a))
(SETQ a (CAR e))
(SETQ n (CDR e))
(GO MKEXPR))
(\ (SETQ nt 'LISP))
(%: (SELECTQ (NTHCHAR input (add n 1))
(%: (SETQ nt 'CV))
(%, (SETQ nt 'PROP))
(PROGN (SETQ nt 'IV)
(GO BANGLOOP))))
(%. (SETQ nt 'MSG))
(GO ENDSYMBOL))
(add n 1)
(GO BANGLOOP)
ENDSYMBOL
[SETQ a (SUBATOM input n (COND
((SETQ n (STRPOSL charList input n))
(* there is some infix operator)
(SUB1 n))
(T (* through the end of the input)
NIL] (* Create next level of nesting)
(OR (EQ nt 'LISP)
(SETQ a (KWOTE a)))
MKEXPR
(SETQ e (ParseExpr nt currentExpr a))
(COND
((NULL n) (* No further nesting)
(RETURN e)))
(* * Get new exprType. n will end up pointing to first char of operator.
type is irrelevant)
(RETURN (ParseAccess input NIL e n])
(ParseBang
[LAMBDA (input exprType currentExpr start) (* ; "Edited 27-May-87 15:33 by smL")
(* Parse an expression after a bang containing %:
(iv) |::| cv %:, prop and those followed by !.
expr type is IV CV PROP MSG PERSP.)
(DECLARE (SPECVARS input))
(PROG [a (n start)
(nt exprType)
(charList (CONSTANT (CHCON '|,.:|]
(SELECTQ (NTHCHAR input n)
(\ (SETQ nt 'LISP))
(%: (SELECTQ (NTHCHAR input (add n 1))
(%: (SETQ nt 'CV))
(%, (ERROR "Can't have a property at top level"))
(PROGN (SETQ nt 'IV)
(GO ENDSYMBOL))))
(%, (ERROR "Can't use perspective as name"))
(%. (SETQ nt 'MSG))
(GO ENDSYMBOL))
(add n 1)
ENDSYMBOL
[SETQ a (SUBATOM input n (COND
((SETQ n (STRPOSL charList input n))
(* there is some infix operator)
(SUB1 n))
(T (* through the end of the input)
NIL] (* Create next level of nesting)
MKEXPR
(RETURN (CONS [ParseExpr nt 'self (COND
((EQ nt 'LISP)
a)
(T (KWOTE a]
n])
(ParseExpr
[LAMBDA (type currentExpr firstAtom) (* ; "Edited 27-May-87 15:33 by smL")
(* * Sub-function of ParseAccess)
(DECLARE (SPECVARS input))
(* The following SELECTQ used to contain a branch
(PERSP (LIST (QUOTE _) currentExpr (QUOTE GetPersp) firstAtom))
(\, but) that got removed with the goings of perspectives)
(SELECTQ type
(LISP (COND
((NEQ currentExpr 'self)
(ERROR "\ must follow ! or appear at beginning" input)))
firstAtom)
(LOOPSNAME (COND
((NEQ currentExpr 'self)
(ERROR "$ must appear at beginning" input)))
(LIST 'GetObjectRec firstAtom))
(IV (LIST 'GetValue currentExpr firstAtom))
(CV (LIST 'GetClassValue currentExpr firstAtom))
(PROP (NCONC1 currentExpr firstAtom))
(MSG! (LIST '_! currentExpr firstAtom))
(MSG (LIST '_ currentExpr (CADR firstAtom)))
(ERROR "Invalid form in access expression:" firstAtom])
(ParsePut@
[LAMBDA (arg type) (* smL "13-Apr-87 16:04")
(* Produce translation for _@ and _@@)
(PROG (first trans (last (LAST arg)))
(SETQ trans (Parse@ (LDIFF arg last)
type))
(RPLACA trans (SELECTQ (SETQ first (CAR trans))
(GetValue 'PutValue)
(GetClassValue 'PutClassValue)
(GO CHECKSEND)))
(RPLACD (CDDR trans)
(CONS (CAR last)
(CDDDR trans)))
(RETURN trans)
CHECKSEND
(COND
((AND (EQ first '_)
(EQ (CADDR trans)
'GetPersp))
(RPLACA (CDDR trans)
'AddPersp)
(RPLACD (CDDDR trans)
(CONS (CAR last)
(CDDDDR trans)))
(RETURN trans)))
(SHOULDNT "Bad translation in Parse@"])
)
(PUTPROPS @ ARGNAMES ({object} accessPath))
(PUTPROPS _@ ARGNAMES ({object} accessPath newValue))
(PUTPROPS $ INFO (NOEVAL))
(PUTPROPS @ INFO (NOEVAL))
(PUTPROPS @* INFO (NOEVAL))
(PUTPROPS _@ INFO (NOEVAL))
(* ;; "Interface Functions")
(DEFINEQ
(CreateEntity
[LAMBDA (obj uid) (* ; "Edited 15-Aug-90 13:01 by jds")
(* * Creates an entity for the object, putting in uid in entity and obj.)
(OR (Object? obj)
(HELPCHECK obj "not object for CreateEntity"))
(SETQ uid (if (NULL uid)
then (Make-UID)
else uid))
(PutObjectUID uid obj)
(replace (OBJECT OBJUID) of obj with uid)
uid])
(DeleteObjectName
[LAMBDA (obj name) (* smL " 9-Apr-87 17:10")
(* * In ObjNameTable Delete name as name of object, or all names for object if
name is NIL)
(LET [(allNames (GETHASH obj ObjNameTable))
(type (if (Class? obj)
then
'CLASSES else 'INSTANCES]
(COND
((NULL allNames)
NIL)
((NULL name)
(PUTHASH obj NIL ObjNameTable)
(for n inside allNames do (PUTHASH n NIL ObjNameTable)
(SELECTQ type
(CLASSES (if (LISTP n)
then (* Remove the dynamic mixin name)
(change ListMixinNames (REMOVE n DATUM))))
NIL)) (* Return nonNIL so marking of change
will take place)
allNames)
((EQ name allNames)
(PUTHASH obj NIL ObjNameTable)
(PUTHASH name NIL ObjNameTable)
name)
((OR (LITATOM allNames)
(NOT (MEMBER name allNames)))
(ERROR name "Not a name for object"))
(T (PUTHASH obj (REMOVE name allNames)
ObjNameTable)
(PUTHASH name NIL ObjNameTable)
(SELECTQ type
(CLASSES (if (LISTP name)
then (* Remove the dynamic mixin name)
(change ListMixinNames (REMOVE name DATUM))))
NIL)
name])
(FastClassInitialize
[LAMBDA (class self) (* ; "Edited 15-Aug-90 13:00 by jds")
(* * Fill in the IVs with initial values)
(DECLARE (LOCALVARS . T))
(for varName in (fetch (class ivNames) of class) as descr
in (fetch (class ivDescrs) of class)
do (WithIVValue self varName [LAMBDA (self varName oldValue loc)
(if (NotSetValue oldValue)
then (for p
on (fetch (IVDescr IVProps)
of descr)
by (CDDR p)
when (EQ (CAR p)
'%:initForm)
do (ChangeIVValue
self varName loc
(EVAL (CADR p)))
(RETURN]
(LAMBDA (self varName)
NIL])
(GetIVHere
[LAMBDA (self varName propName) (* smL "27-May-86 18:36")
(* * Gets the value found in the instance, without invoking activeValues.
Returns NotSetValue if not found in instance)
(COND
((NOT (type? instance self))
(_ (GetLispClass self)
GetIVHere self varName propName))
[propName (WithIVPropDescr self varName [LAMBDA (self varName propDescr)
(InstGetProp propDescr propName]
(LAMBDA (self varName)
NotSetValue]
(T (WithIVValue self varName [LAMBDA (self varName value)
value]
(LAMBDA (self varName)
NotSetValue])
(GetValueOnly
[LAMBDA (self varName propName) (* smL "10-Apr-87 10:48")
(* * Like GetValue except that it ignores the special status of ActiveValues
and just returns them as a data structure without activating any procedures)
(COND
((type? class self)
(GetClassIV self varName propName))
((NOT (type? instance self))
(GetItOnly self varName propName 'IV))
((FIXP varName) (* Here for indexed variables.)
(FetchNthValueOnly self varName propName))
[propName (* Get an IV prop from an instance)
(WithIVPropDescr self varName [LAMBDA (self varName propDescr)
(LET ((value (InstGetProp propDescr propName)))
(COND
((OR (NULL propDescr)
(NotSetValue value))
(_ self IVValueMissing varName propName
'GetValueOnly))
(T value]
(LAMBDA (self varName)
(_ self IVMissing varName propName 'GetValueOnly)]
(T (* usual case)
(WithIVValue self varName [LAMBDA (self varName value)
(COND
((NotSetValue value)
(_ self IVValueMissing varName NIL 'GetValueOnly))
(T value]
(LAMBDA (self varName)
(_ self IVMissing varName NIL 'GetValueOnly)])
(GetClassRec
[LAMBDA (className) (* dgb%: "29-Feb-84 15:35")
(* Given an atom, returns the class which is named by that atom.
If there is no such definition, returns NIL)
(COND
((type? class className)
className)
(T (PROG ((classRec (GetObjectRec className)))
(COND
((AND classRec (NOT (type? class classRec)))
(LoopsHelp className " is a defined object, but is not a class.")))
(RETURN classRec])
(GetLispClass
[LAMBDA (obj) (* smL " 6-May-86 14:46")
(* * Gets the class corresponding to the Lisp object as specified in
LispClassTable)
(LET ((convertForm (GETHASH (TYPENAME obj)
LispClassTable)))
(if (NULL convertForm)
then
($ Tofu)
elseif
(type? class convertForm)
then convertForm else (APPLY* convertForm obj])
(GetObjectName
[LAMBDA (object) (* smL " 2-Apr-86 15:03")
(* Returns the name of an object if it has one other than its UID)
(COND
((NULL object)
NIL)
((type? class object)
(ClassName object))
(T (LET ((names (GETHASH object ObjNameTable)))
(COND
((LITATOM object) (* This is the name of an object)
(AND names object))
((LISTP names) (* If it has more than one, then
return first)
(CAR names))
(T names])
(GetObjectRec
[LAMBDA (name) (* ; "Edited 25-Nov-87 14:20 by Bane")
(* ;;; "Given a name (or UID) returns the object which is named by that atom. else returns NIL.")
(COND
((Object? name)
name)
((UIDP name)
(GetObjFromUID name))
(T (* ;;
"If name is a list Return a class which has this list as supers provided all are classes.")
(OR (GETHASH name ObjNameTable)
(AND (LISTP name)
(MakeMixinClass name])
(MakeMixinClass
[LAMBDA (nameList) (* smL " 8-Apr-87 19:22")
(* * Make a class with supers specified by nameList, and with canonical name
also specified by nameList)
(DECLARE (GLOBALVARS ListMixinNames))
(if [for c in nameList always (AND (LITATOM c)
(type? class ($! c]
then
(LET [(canonicalClassName (CAR (MEMBER nameList ListMixinNames]
(COND
((NOT canonicalClassName)
(* We have never seen this dynamic class, so create it anew)
(* Be careful that we name a new list for the canonical name, so the user can't
smash it by accident)
(LET* ((nameListCopy (COPYALL nameList))
(class (NewClass nameListCopy)))
(InstallSupers class nameList)
(push ListMixinNames nameListCopy)
class))
(($! canonicalClassName))
(T
(* We thought we had a class by that name already, but we didn't)
(change ListMixinNames (REMOVE canonicalClassName ListMixinNames))
(MakeMixinClass nameList])
(NameEntity
[LAMBDA (self name) (* smL "18-Sep-86 10:17")
(* * Associate a name with entity in current environment An object can have
more than one name. RETURN NIL if already has name)
(COND
((NULL name)
(ERROR "Can't name object NIL" self))
((NOT (LITATOM name))
(ERROR name "should be an atom to be a name"))
(T (LET ((oldObj (GetObjectRec name)))
(COND
((EQ self oldObj) (* already has name)
NIL)
(T (COND
((AND oldObj (NEQ self oldObj))
(AND ErrorOnNameConflict (HELPCHECK name
"is already used as a name for an object. To continue type OK."
))
(_ oldObj UnSetName name)))
(PutObjectName name self)
self])
(NewEntity
[LAMBDA (facts names) (* dgb%: "26-DEC-83 15:00")
(* * Creates a new entity and names it if name given)
[COND