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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
|
PACKET lisp heap and oblist management (* Autor: J.Durchholz *)
(* Datum: 09.05.1984 *)
DEFINES (* Version 1.7.2 *)
(* hey 25.2.83 *)
initialize lisp system,
dump lisp heap,
lisp storage,
collect lisp heap garbage,
SYM,
:=,
nil,
pname,
head,
set head,
tail,
set tail,
cons,
eq,
equal,
null,
atom,
is named atom,
begin oblist dump,
next atom,
new atom,
create atom,
delete atom,
begin property list dump,
next property,
add property,
alter property,
property,
delete property,
property exists,
add flag,
flag,
delete flag,
text,
is text,
character,
is character,
sym character,
int 1,
int 2,
is int pair,
sym:
(* NOTE: All internal routines are prefixed by x *)
(***************************** heap management ****************************)
LET
max size = 32767,
NODE = STRUCT (INT status,
head, tail);
LET HEAP = STRUCT (INT size,
ROW max size NODE node);
BOUND HEAP VAR heap;
PROC initialize lisp system (DATASPACE CONST ds):
IF type (ds) < 0 THEN
heap := ds;
x initialize oblist and heap size;
create atom ("NIL");
create atom ("PNAME");
ELSE
heap := ds
FI
END PROC initialize lisp system;
PROC dump lisp heap (FILE VAR f):
put line (f, "Groesse :" + text (CONCR (heap).size));
line (f);
put (CONCR (heap).size);
BOOL VAR is char := FALSE;
INT VAR i;
FOR i FROM 1 UPTO CONCR (heap).size REP
cout (i);
dump ith node
PER.
dump ith node:
put (f, text (i, 6));
put (f, status);
put (f, head);
put (f, tail);
line (f).
status:
SELECT ith node.status OF
CASE atomic : "ATOMIC............"
CASE non atomic : "NON ATOMIC........"
CASE oblist bone : "OBLIST BONE......."
CASE property indicator : "PROPERTY INDICATOR"
CASE property root : "PROPERTY ROOT....."
CASE flag indicator : "FLAG INDICATOR...."
CASE text data : "TEXT DATA........."
CASE character data : is char := TRUE; "CHARACTER DATA...."
CASE int data : "INT DATA.........."
OTHERWISE "????." + text (ith node.status, 6) + ".????"
END SELECT.
head:
maybe a code + text (ith node.head, 6).
maybe a code:
IF is char THEN
is char := FALSE;
IF ith node.head > 31 AND 128 > ith node.head THEN
" " + code (ith node.head) + " "
ELSE
" "
FI
ELSE
" "
FI.
tail:
text (ith node.tail, 6).
ith node:
CONCR (heap).node (i).
END PROC dump lisp heap;
PROC lisp storage (INT VAR size, used):
size := max size;
used := CONCR (heap).size
END PROC lisp storage;
PROC collect lisp heap garbage:
mark all used nodes;
transfer all used high address nodes to unused low address nodes;
adjust all pointers to cleared high address area and unmark all nodes;
adjust size.
mark all used nodes:
INT VAR i;
FOR i FROM 2 UPTO 28 REP
x mark (i)
PER.
transfer all used high address nodes to unused low address nodes:
INT VAR high address :: CONCR (heap).size + 1,
low address :: 0;
REP
find next lower used high address node;
IF no used high address node found THEN
LEAVE transfer all used high address nodes to unused low address nodes
FI;
find next higher unused low address node;
IF no unused low address node found THEN
LEAVE transfer all used high address nodes to unused low address nodes
FI;
transfer high address node to low address node
PER.
find next lower used high address node:
REP
high address DECR 1
UNTIL high address node marked PER.
high address node marked:
high address node.status < 0.
no used high address node found:
low address = high address.
find next higher unused low address node:
REP
low address INCR 1
UNTIL low address node not marked OR low address = high address PER.
low address node not marked:
low address node.status > 0.
no unused low address node found :
low address = high address.
transfer high address node to low address node:
low address node.status := high address node.status;
low address node.head := high address node.head;
low address node.tail := high address node.tail;
high address node.head := low address.
adjust all pointers to cleared high address area and unmark all nodes:
(* 'high address' should now point to the last node of the used area *)
FOR low address FROM 1 UPTO high address REP
unmark low address node;
SELECT low address node.status OF
CASE oblist bone: adjust head
CASE atomic,
non atomic,
property indicator,
property root,
flag indicator: adjust head; adjust tail
CASE text data, character data: adjust tail
CASE int data:
OTHERWISE x lisp error ("Status " + text (low address node.status) +
" gefunden bei pointer Justage")
END SELECT
PER.
unmark low address node:
low address node.status := - low address node.status.
adjust head:
IF low address node.head > high address THEN
low address node.head := node (low address node.head).head
FI.
adjust tail:
IF low address node.tail > high address THEN
low address node.tail := node (low address node.tail).head
FI.
adjust size:
CONCR (heap).size := high address.
low address node:
node (low address).
high address node:
node (high address).
node:
CONCR (heap).node.
END PROC collect lisp heap garbage;
PROC x mark (INT CONST ptr):
IF node not yet marked THEN
mark node;
SELECT - ptr node.status OF
CASE oblist bone: x mark (ptr node.head)
CASE atomic,
non atomic,
property indicator,
property root,
flag indicator: x mark (ptr node.head); x mark (ptr node.tail)
CASE text data, character data: x mark (ptr node.tail)
CASE int data:
OTHERWISE error stop ("Status " + text (- ptr node.status) +
" gefunden beim Markieren")
END SELECT
FI.
node not yet marked:
ptr node.status > 0.
mark node:
ptr node.status := - ptr node.status.
ptr node:
CONCR (heap).node (ptr)
END PROC x mark;
TYPE SYM = INT;
OP := (SYM VAR left, SYM CONST right):
CONCR (left) := CONCR (right)
END OP :=;
LET atomic = 1,
non atomic = 2,
oblist bone = 3,
property indicator = 4,
property root = 5,
flag indicator = 6,
text data = 7,
character data = 8,
int data = 9;
SYM CONST nil :: SYM :(35), (* 'x initialize oblist and heap size' will *)
pname :: SYM :(44); (* place the atom NIL at node 35 and PNAME *)
(* at node 44 *)
(***************************** basic functions ****************************)
SYM PROC head (SYM CONST sym):
SELECT status of sym OF
CASE atomic: error stop ("Atome haben keinen head"); nil
CASE non atomic: SYM :(head of sym)
CASE oblist bone,
property indicator,
property root,
flag indicator : x lisp error ("Versteckter Knoten, Type:" +
text (status of sym));
nil
CASE text data,
character data,
int data : error stop ("Daten haben keinen head"); nil
OTHERWISE x lisp error ("Illegaler Status " + text (status of sym));
nil
END SELECT.
status of sym:
sym node.status.
head of sym:
sym node.head.
sym node:
CONCR (heap).node (CONCR (sym))
END PROC head;
SYM PROC x head (SYM CONST sym):
SYM :(CONCR (heap).node (CONCR (sym)).head)
END PROC x head;
PROC set head (SYM CONST sym, new head):
SELECT status of sym OF
CASE atomic: errorstop ("Atome haben keinen head")
CASE non atomic: head of sym := CONCR (new head)
CASE oblist bone,
property indicator,
property root,
flag indicator : x lisp error ("Versteckter Knoten, Type:" +
text (status of sym))
CASE text data,
character data,
int data : error stop ("Daten haben keinen head")
OTHERWISE x lisp error ("Illegaler Status " + text (status of sym))
END SELECT.
status of sym:
sym node.status.
head of sym:
sym node.head.
sym node:
CONCR (heap).node (CONCR (sym)).
END PROC set head;
PROC x set head (SYM CONST sym, new head):
CONCR (heap).node (CONCR (sym)).head := CONCR (new head)
END PROC x set head;
SYM PROC tail (SYM CONST sym):
SELECT status of sym OF
CASE atomic: error stop ("Atome haben keinen tail"); nil
CASE non atomic: SYM :(tail of sym)
CASE oblist bone,
property indicator,
flag indicator : x lisp error ("Versteckter Knoten:" +
text (status of sym));
nil
CASE text data,
character data,
int data : error stop ("Daten haben keinen tail"); nil
OTHERWISE x lisp error ("Illegaler Status: "+ text (status of sym));
nil
END SELECT.
status of sym:
sym node.status.
tail of sym:
sym node.tail.
sym node:
CONCR (heap).node (CONCR (sym)).
END PROC tail;
SYM PROC x tail (SYM CONST sym):
SYM :(CONCR (heap).node (CONCR (sym)).tail)
END PROC x tail;
PROC set tail (SYM CONST sym, new tail):
SELECT status of sym OF
CASE atomic: error stop ("Atome haben keinen tail")
CASE non atomic: tail of sym := CONCR (new tail)
CASE oblist bone,
property indicator,
property root,
flag indicator : x lisp error ("Versteckter Knoten, Type: " +
text (status of sym))
CASE text data,
character data,
int data : error stop ("Daten tails sind unveraenderbar")
OTHERWISE x lisp error ("Illegaler Status: " + text (status of sym))
END SELECT.
status of sym:
sym node.status.
tail of sym:
sym node.tail.
sym node:
CONCR (heap).node (CONCR (sym)).
END PROC set tail;
PROC x set tail (SYM CONST sym, new tail):
CONCR (heap).node (CONCR (sym)).tail := CONCR (new tail)
END PROC x set tail;
SYM PROC cons (SYM CONST head, tail):
SYM VAR result;
search free node;
result node.status := non atomic;
result node.head := CONCR (head);
result node.tail := CONCR (tail);
result.
search free node:
IF CONCR (heap).size = max size THEN
error stop ("LISP Heap Ueberlauf");
LEAVE cons WITH nil
ELSE
CONCR (heap).size INCR 1;
CONCR (result) := CONCR (heap).size; cout(CONCR(result))
FI.
result node:
CONCR (heap).node (CONCR (result)).
END PROC cons;
BOOL PROC eq (SYM CONST sym 1, sym 2):
CONCR (sym 1) = CONCR (sym 2)
END PROC eq;
BOOL PROC equal (SYM CONST sym 1, sym 2):
eq (sym 1, sym 2) COR have same value.
have same value:
IF sym 1 node.status <> sym 2 node.status THEN
FALSE
ELSE
SELECT sym 1 node.status OF
CASE atomic: FALSE
CASE non atomic: equal (head (sym 1), head (sym 2)) CAND
equal (tail (sym 1), tail (sym 2))
CASE oblist bone,
property indicator,
property root,
flag indicator: x lisp error ("Versteckter Knoten, Type: " +
text (x status (sym 1))); FALSE
CASE text data: equal texts
CASE character data: sym 1 node.head = sym 2 node.head
CASE int data: sym 1 node.head = sym 2 node.head AND
sym 1 node.tail = sym 2 node.tail
OTHERWISE x lisp error ("Ilegaler Status " + text (x status (sym 1)));
FALSE
END SELECT
FI.
equal texts:
equal length CAND equal character sequence.
equal length:
eq (x head (sym 1), x head (sym 2)).
equal character sequence:
SYM VAR actual sym 1 character :: sym 1,
actual sym 2 character :: sym 2;
INT VAR i;
FOR i FROM 1 UPTO sym 1 node. head REP
actual sym 1 character := x tail (actual sym 1 character);
actual sym 2 character := x tail (actual sym 2 character);
IF eq (actual sym 1 character, actual sym 2 character) THEN
LEAVE equal character sequence WITH TRUE
FI;
IF x status (actual sym 1 character) <> character data OR
x status (actual sym 2 character) <> character data THEN
x lisp error ("Ungueltiges Zeichen im text");
LEAVE equal character sequence WITH FALSE
FI;
IF CONCR (x head (actual sym 1 character)) <>
CONCR (x head (actual sym 2 character)) THEN
LEAVE equal character sequence WITH FALSE
FI
PER;
TRUE.
sym 1 node:
CONCR (heap).node (CONCR (sym 1)).
sym 2 node:
CONCR (heap).node (CONCR (sym 2)).
END PROC equal;
BOOL PROC null (SYM CONST sym):
CONCR (sym) = CONCR (nil)
END PROC null;
BOOL PROC atom (SYM CONST sym):
SELECT x status (sym) OF
CASE atomic,
text data,
character data,
int data: TRUE
CASE non atomic: FALSE
CASE oblist bone,
property indicator,
property root,
flag indicator : x lisp error ("Versteckter Knoten, Type:" +
text (x status (sym))); TRUE
OTHERWISE x lisp error ("Illegaler Status " +
text (x status (sym))); TRUE
END SELECT
END PROC atom;
BOOL PROC is named atom (SYM CONST sym):
x status (sym) = atomic
END PROC is named atom;
(*------------------- internal heap management routines ------------------*)
SYM PROC x new node (INT CONST status, head, tail):
IF CONCR (heap).size = max size THEN
error stop ("LISP Heap Ueberlauf"); nil
ELSE
CONCR (heap).size INCR 1;
new node.status := status;
new node.head := head;
new node.tail := tail;
SYM :(CONCR (heap).size)
FI.
new node:
node (CONCR (heap).size).
node:
CONCR (heap).node.
END PROC x new node;
INT PROC x status (SYM CONST sym):
CONCR (heap).node (CONCR (sym)).status
END PROC x status;
(**************************** oblist management ***************************)
(* Oblist organization:
(NOTE:
+-----------------+
l <status> l
All nodes are represented as +--------+--------+ in all comments
l <head> l <tail> l of this packet.
+--------+--------+
END OF NOTE)
The 'oblist' (object list) is organized as follows:
+-------------+
l oblist bone l
+------+------+ +--> list of all atoms whose print names begin with "§"
l o l XXXX l l
+---+--+------+ l
+------------+
+-------------+
l oblist bone l
+------+------+ +--> list of all atoms whose print names begin with "A"
l o l XXXX l l
+---+--+------+ l
+------------+
.
.
.
+-------------+
l oblist bone l
+------+------+ +--> list of all atoms whose print names begin with "Z"
l o l XXXX l l
+---+--+------+ l
+------------+
These nodes with status 'oblist bone' form the oblist skeleton. As long as
the lisp heap exists, they are stored contiguously in nodes 2 - 28; they
cannot be changed directly by the user. This way of storing the oblist
skeleton allows a hashing scheme to be applied when searching for an atom
with a given name. The hash width of 27 is the smallest one thas distributes
all atoms according to their character; with a smaller hash size, two or
more lists would be merged, with the effect that some of the atom lists
would contain atoms beginning with different characters.
The list of all atoms whose print names begin with a certain character
is organized as follows:
+-------------+
l atomic l
+------+------+
l o l o---+--> property list of first atom
+---+--+------+
l
V
+-------------+
l atomic l
+------+------+
l o l o---+--> property list of 2nd atom
+---+--+------+
l
V
.
.
.
l
V
+-------------+
l atomic l
+------+------+
l o l o---+--> property list of last atom
+---+--+------+
l
V
oblist bone where the atom list began
These lists cannot be acessed directly by the user, too.
*)
PROC x initialize oblist and heap size:
node (1).status := text data;
node (1).head := 32 (* blank *);
node (1).tail := 1;
INT VAR i;
FOR i FROM 2 UPTO 28 REP
node (i).status := oblist bone;
node (i).head := i
PER;
CONCR (heap).size := 28.
node:
CONCR (heap).node.
END PROC x initialize oblist and heap size;
(*++++++++++++++++++++++++++++++ oblist dump +++++++++++++++++++++++++++++*)
SYM VAR actual oblist bone :: SYM :(0),
actual atom :: SYM :(0);
PROC begin oblist dump:
actual oblist bone := SYM :(2);
actual atom := SYM :(2)
END PROC begin oblist dump;
SYM PROC next atom:
actual atom := x head (actual atom);
WHILE no more atoms in this atom list REP
try next oblist bone
PER;
actual atom.
no more atoms in this atom list:
(* NIL is given as last atom when 'next atom' is called repeatedly, so *)
(* it can serve as a terminator. So NIL "does not count" if it is *)
(* encountered during one of the calls. *)
IF null (actual atom) THEN
actual atom := x head (actual atom)
FI;
eq (actual atom, actual oblist bone).
try next oblist bone:
IF actual oblist bone is last oblist bone THEN
actual atom := SYM :(2);
LEAVE next atom WITH nil
FI;
CONCR (actual oblist bone) INCR 1;
actual atom := x head (actual oblist bone).
actual oblist bone is last oblist bone:
CONCR (actual oblist bone) = 28.
END PROC next atom;
(*+++++++++++++++++++++++ atom search and creation +++++++++++++++++++++++*)
SYM VAR predecessor, result;
(* Variables used for communication between the internal search *)
(* procedures and the procedures calling them. *)
SYM PROC atom (TEXT CONST name):
x search atom (name);
IF atom not already existing THEN
nil
ELSE
result
FI.
atom not already existing:
x status (result) = oblist bone.
END PROC atom;
SYM PROC new atom (TEXT CONST name):
x search atom (name);
IF atom not already existing THEN
x create new atom (name);
FI;
result.
atom not already existing:
x status (result) = oblist bone.
END PROC new atom;
PROC create atom (TEXT CONST name):
x search atom (name);
IF atom already existing THEN
error stop ("Atom " + name + " existiert bereits")
ELSE
x create new atom (name)
FI.
atom already existing:
x status (result) <> oblist bone.
END PROC create atom;
PROC delete atom (SYM CONST atom):
IF is named atom (atom) THEN
IF null (atom) OR eq (atom, pname) THEN
error stop ("Dies Atom darf nicht geloescht werden")
ELSE
search predecessor;
delete atom from atom list
FI
ELSE
error stop ("Nur benannte Atome können geloescht werden")
FI.
search predecessor:
predecessor := x head (atom);
WHILE NOT eq (x head (predecessor), atom) REP
predecessor := x head (predecessor)
PER.
delete atom from atom list:
x set head (predecessor, x head (atom)).
END PROC delete atom;
PROC x search atom (TEXT CONST name):
CONCR (result) := (code (name SUB 1) + 17) MOD 27 + 2;
(* This formula places the list of atoms beginning with "§" at the *)
(* first oblist bone, the list of atoms beginning with "A" at the *)
(* at the second one, and so on. (See also the big comment in lines *)
(* 600 - 700) *)
REP
predecessor := result;
result := x head (predecessor);
UNTIL end of atom list reached COR right atom found PER.
end of atom list reached:
x status (result) = oblist bone.
right atom found:
SYM VAR actual character node := property (result, pname);
IF NOT is text (actual character node) THEN
x lisp error ("Namen erwartet");
LEAVE right atom found WITH FALSE
FI;
IF CONCR (x head (actual character node)) <> length (name) THEN
FALSE
ELSE
INT VAR i;
FOR i FROM 1 UPTO length (name) REP
to next character node;
check wether is character data node;
check wether character matches;
PER;
TRUE
FI.
to next character node:
actual character node := x tail (actual character node).
check wether is character data node:
IF x status (actual character node) <> character data THEN
x lisp error ("Zeichenkette erwartet");
LEAVE right atom found WITH FALSE
FI.
check wether character matches:
IF code (name SUB i) <> CONCR (x head (actual character node)) THEN
LEAVE right atom found WITH FALSE
FI.
END PROC x search atom;
PROC x create new atom (TEXT CONST name):
(* It is necessary that 'x search atom' has been executed before *)
(* calling 'x create new atom' because this procedure relies on the *)
(* value of 'predecessor'. *)
enable stop;
SYM CONST sym name :: sym (name);
IF CONCR (heap).size + 3 > max size THEN
error stop ("LISP Heap Ueberlauf")
FI;
result := newly created atom;
x set head (predecessor, result).
newly created atom:
x new node (atomic, CONCR (oblist bone node), CONCR (property list)).
oblist bone node:
x head (predecessor).
property list:
x new node (property indicator, CONCR (pname), property root node).
property root node:
CONCR (x new node (property root, CONCR (sym name), CONCR (nil))).
END PROC x create new atom;
(************************* property list handling *************************)
(*
The property lists consist of chained units of the structure
+--------------------+ +---------------+
l property indicator l l property root l
+----------+---------+ +-------+-------+
l o l o----+-->l o l o---+--> . . .
+----+-----+---------+ +---+---+-------+
l l
V V
property id property
or
+----------------+
l flag indicator l
+--------+-------+
l o l o---+--> . . .
+---+----+-------+
l
V
flag id
The property lists cannot be altered or read directly, too.
For property list handling there exist procedures that insert, change, read
and delete properties resp. flags. Thus, the only thing that can be done
with any property of an atom without using these special procedures, is
comparing to or 'cons'ing with some other S-expression.
At any given time the property list of any atom (including 'NIL') contains
the property 'PNAME' giving the print name of the atom, stored as a list of
characters. This special property cannot be altered, overwritten by 'add
property' or deleted.
*)
(*++++++++++++++++++++++++++ property list dump ++++++++++++++++++++++++++*)
SYM VAR actual property list node :: nil;
PROC begin property list dump (SYM CONST atom):
actual property list node := x tail (atom)
END PROC begin property list dump;
PROC next property (SYM VAR property id, property):
IF null (actual property list node) THEN
property id := nil;
property := nil
ELSE
SELECT x status (actual property list node) OF
CASE flag indicator: get flag id
CASE property indicator: get property id and property
OTHERWISE x lisp error ("Flagge oder Eigenschaft erwartet und nicht: "
+ text (x status (actual property list node)))
END SELECT
FI.
get flag id:
property id := x head (actual property list node);
actual property list node := x tail (actual property list node);
property := nil.
get property id and property:
property id := x head (actual property list node);
actual property list node := x tail (actual property list node);
IF x status (actual property list node) = property root THEN
property := x head (actual property list node);
actual property list node := x tail (actual property list node)
ELSE
x lisp error ("Eigenschaftswurzel erwartet, nicht:" +
text (x status (actual property list node)));
property := nil
FI.
END PROC next property;
(*+++++++++++++++++++++++++++++ properties +++++++++++++++++++++++++++++++*)
SYM VAR last atom :: SYM :(0),
p list predecessor,
p list result;
PROC add property (SYM CONST atom, property id, property):
IF eq (property id, pname) THEN
errorstop ("Der PNAME eines Atoms darf nicht versteckt sein")
ELSE
IF CONCR (heap).size + 2 > max size THEN
error stop ("LISP Heap Ueberlauf");
LEAVE add property
FI;
x set tail (atom, new property plus old property list);
IF eq (atom, last atom) AND
eq (property id, x head (p list result)) THEN
p list predecessor := atom;
p list result := x tail (atom)
FI
FI.
new property plus old property list:
x new node (property indicator,
CONCR (property id), CONCR (property root plus old property list)).
property root plus old property list:
x new node (property root, CONCR (property), CONCR (old property list)).
old property list:
x tail (atom)
END PROC add property;
PROC alter property (SYM CONST atom, property id, new property):
IF eq (property id, pname) THEN
error stop ("Namen kann man nicht aendern")
ELSE
x search property id (atom, property id);
IF null (p list result) THEN
error stop ("Eigenschaft existiert nicht")
ELSE
x set head (x tail (p list result), new property)
FI
FI
END PROC alter property;
SYM PROC property (SYM CONST atom, property id):
x search property id (atom, property id);
IF null (p list result) THEN
nil
ELSE
x head (x tail (p list result))
FI
END PROC property;
PROC delete property (SYM CONST atom, property id):
IF eq (property id, pname) THEN
errorstop ("Der Name eines Atoms darf nicht geloescht werden")
ELSE
x search property id (atom, property id);
IF NOT null (p list result) THEN
x set tail (p list predecessor, x tail (x tail (p list result)));
last atom := SYM :(0)
FI
FI
END PROC delete property;
BOOL PROC property exists (SYM CONST atom, property id):
x search property id (atom, property id);
NOT null (p list result)
END PROC property exists;
PROC x search property id (SYM CONST atom, property id):
IF eq (last atom, atom) AND eq (x head (p list result), property id) THEN
LEAVE x search property id
FI;
last atom := atom;
p list predecessor := atom;
REP
p list result := x tail (p list predecessor);
IF end of property list THEN
last atom := SYM :(0);
LEAVE x search property id
FI;
SELECT x status (p list result) OF
CASE flag indicator: p list predecessor := p list result
CASE property indicator: check wether property root node follows;
IF correct property id found THEN
LEAVE x search property id
ELSE
p list predecessor := xtail (p list result)
FI
CASE property root: xlisperror("Unordentliche Eigenschaftwurzel");
p list result := nil;
last atom := SYM :(0);
LEAVE x search property id
OTHERWISE x lisp error ("Eigenschaften erwartet und nicht: " +
text (x status (p list result)));
p list result := nil;
last atom := SYM :(0);
LEAVE x search property id
END SELECT
PER.
end of property list:
null (p list result).
check wether property root node follows:
IF x status (x tail (p list result)) <> property root THEN
x lisp error ("Eigenschaftswurzel erwartet");
p list result := nil;
last atom := SYM :(0);
LEAVE x search property id
FI.
correct property id found:
eq (x head (p list result), property id).
END PROC x search property id;
(*++++++++++++++++++++++++++++++++ flags +++++++++++++++++++++++++++++++++*)
PROC add flag (SYM CONST atom, flag id):
enable stop;
x set tail (atom, new flag plus old property list).
new flag plus old property list:
x new node (flag indicator, CONCR (flag id), old property list).
old property list:
CONCR (x tail (atom))
END PROC add flag;
BOOL PROC flag (SYM CONST atom, flag id):
x search flag id (atom, flag id);
NOT null (result)
END PROC flag;
PROC delete flag (SYM CONST atom, flag id):
x search flag id (atom, flag id);
IF NOT (is error COR null (result)) THEN
x set tail (predecessor, x tail (result))
FI
END PROC delete flag;
PROC x search flag id (SYM CONST atom, flag id):
predecessor := atom;
REP
result := x tail (predecessor);
IF end of property list THEN
LEAVE x search flag id
FI;
SELECT x status (result) OF
CASE property root, property indicator: predecessor := result
CASE flag indicator: IF correct flag id found THEN
LEAVE x search flag id
ELSE
predecessor := result
FI
OTHERWISE x lisp error ("Eigenschaften erwartet und nicht:" +
text (x status (result)));
result := nil;
LEAVE x search flag id
END SELECT
PER.
end of property list:
null (result).
correct flag id found:
eq (x head (result), flag id).
END PROC x search flag id;
(****** Conversion of non-LISP data to LISP structures and vice versa *****)
TEXT PROC text (SYM CONST sym):
IF is text (sym) THEN
TEXT VAR result := "";
SYM VAR actual node :: sym;
INT VAR i;
FOR i FROM 1 UPTO CONCR (x head (sym)) REP
actual node := x tail (actual node);
result CAT actual character
PER;
result
ELSE
error stop ("ist kein text");
""
FI.
actual character:
IF x status (actual node) <> character data THEN
x lisp error ("Zeichenfolge erwartet");
LEAVE text WITH result
FI;
code (CONCR (x head (actual node))).
END PROC text;
BOOL PROC is text (SYM CONST sym):
x status (sym) = text data
END PROC is text;
SYM PROC sym (TEXT CONST text):
SYM VAR result :: x new node (text data,
length (text), CONCR (nil)),
actual character node :: result;
INT VAR length of text;
ignore blanks at end of text;
INT VAR i;
FOR i FROM 1 UPTO length of text REP
x set tail (actual character node, new next character node);
actual character node := x tail (actual character node)
PER;
result.
ignore blanks at end of text:
FOR length of text FROM length (text) DOWNTO 0 REP
IF (text SUB length of text) <> " " THEN
LEAVE ignore blanks at end of text
FI
PER;
length of text := 0.
new next character node:
x new node (character data, code (text SUB i), 1).
END PROC sym;
INT PROC character (SYM CONST sym):
IF x status (sym) = character data THEN
CONCR (x head (sym))
ELSE
error stop ("ist kein Charakter");
-1
FI
END PROC character;
BOOL PROC is character (SYM CONST sym):
x status (sym) = character data
END PROC is character;
SYM PROC sym character (INT CONST char):
x new node (character data, char MOD 256, 1)
END PROC sym character;
INT PROC int 1 (SYM CONST sym):
IF x status (sym) = int data THEN
CONCR (x head (sym))
ELSE
error stop ("ist keine Zahl");
-1
FI
END PROC int 1;
INT PROC int 2 (SYM CONST sym):
IF x status (sym) = int data THEN
CONCR (x tail (sym))
ELSE
error stop ("ist keine Zahl");
-1
FI
END PROC int 2;
BOOL PROC is int pair (SYM CONST sym):
x status (sym) = int data
END PROC is int pair;
SYM PROC sym (INT CONST int 1, int 2):
x new node (int data, int 1, int 2)
END PROC sym;
(********************* internal error routine *****************************)
PROC x lisp error (TEXT CONST error message):
error stop (""13"LISP SYSTEM FEHLER: " + error message )
END PROC x lisp error;
END PACKET lisp heap and oblist management;
PACKET name (* Autor: J.Durchholz *)
(* Datum: 15.06.1982 *)
DEFINES (* Version 1.1.1 *)
name:
TEXT PROC name (SYM CONST sym):
IF is named atom (sym) THEN
text (property (sym, pname))
ELSE
""15"IST_KEIN_ATOM"14""
FI
END PROC name;
END PACKET name;
PACKET lisp storage info (* Autor: J.Durchholz *)
(* Datum: 23.08.1982 *)
DEFINES (* Version 1.1.1 *)
lisp storage info:
PROC lisp storage info:
INT VAR size, used;
lisp storage (size, used);
out (""13""10" ");
put (used);
put ("Knoten von");
put (size);
put line ("Knoten des LISP-Heaps sind belegt!")
END PROC lisp storage info;
END PACKET lisp storage info;
|