Skip to content

Commit fb0a551

Browse files
committed
[St] Adds ConsCell and Continuation packages which are dependencies of LispKit
1 parent 7ab67cc commit fb0a551

17 files changed

+1145
-0
lines changed
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
Extension { #name : #Array }
2+
3+
{ #category : #'*ConsCell' }
4+
Array >> arrayForm [
5+
6+
^ self
7+
]
8+
9+
{ #category : #'*ConsCell' }
10+
Array >> asCons [
11+
12+
| cons |
13+
14+
self size = 0 ifTrue: [^ nil].
15+
self size = 1 ifTrue: [^ ConsCell car: (self at: 1) asCons].
16+
17+
self reverseDo: [:elt |
18+
cons := ConsCell car: elt asCons cdr: cons].
19+
^ cons
20+
21+
22+
]
23+
24+
{ #category : #'*ConsCell' }
25+
Array >> asConsList [
26+
27+
^ ConsCell fromList: self
28+
]
29+
30+
{ #category : #'*ConsCell' }
31+
Array >> asCyclicCons [
32+
33+
^ self asCons in: [:cc | cc append: cc]
34+
35+
36+
]
37+
38+
{ #category : #'*ConsCell' }
39+
Array >> cycles [
40+
41+
^ self storeCycles: IdentityDictionary new with: IdentitySet new
42+
43+
]
44+
45+
{ #category : #'*ConsCell' }
46+
Array >> printOn: aStream depth: aNumber forLisp: aLisp level: cpl maxLevel: mpl length: len maxLength: mlen done: anIdentitySet cycles: anIdentityDictionary [
47+
48+
(anIdentityDictionary keys includes: self)
49+
ifTrue:
50+
[
51+
aStream nextPut: $#;
52+
nextPutAll: (anIdentityDictionary at: self) asString;
53+
nextPut: $=.
54+
anIdentitySet add: self.
55+
].
56+
57+
aStream nextPutAll: (aLisp ifNil: ['#(']
58+
ifNotNil: [aLisp class vectorOpeningString]).
59+
self do: [:element |
60+
(anIdentitySet includes: element)
61+
ifTrue:
62+
[
63+
aStream nextPut: $#;
64+
nextPutAll: (anIdentityDictionary at: element) asString;
65+
nextPut: $#
66+
]
67+
ifFalse:
68+
[
69+
element printOn: aStream depth: aNumber forLisp: aLisp
70+
level: cpl maxLevel: mpl length: len maxLength: mlen
71+
done: anIdentitySet cycles: anIdentityDictionary
72+
].
73+
aStream space
74+
].
75+
self ifNotEmpty: [aStream skip: -1].
76+
aStream nextPut: (aLisp ifNil: [$)]
77+
ifNotNil: [aLisp class vectorClosingChar])
78+
]
79+
80+
{ #category : #'*ConsCell' }
81+
Array >> printOn: aStream forLisp: aLisp [
82+
83+
| mlen mlev |
84+
85+
mlen := aLisp ifNil: [nil] ifNotNil: [aLisp printLength].
86+
mlev := aLisp ifNil: [nil] ifNotNil: [aLisp printLevel].
87+
88+
(aLisp isNil or: [aLisp printCircle == aLisp trueValue])
89+
ifTrue:
90+
[
91+
^ self printOn: aStream depth: 0 forLisp: aLisp
92+
level: 1 maxLevel: mlev length: mlen maxLength: mlen
93+
done: IdentitySet new cycles: self cycles
94+
].
95+
96+
self printOn: aStream depth: 0 forLisp: aLisp
97+
level: 1 maxLevel: mlev length: mlen maxLength: mlen
98+
done: IdentitySet new cycles: IdentityDictionary new
99+
100+
]
101+
102+
{ #category : #'*ConsCell' }
103+
Array >> storeCycles: anIdentityDictionary with: anIdentitySet [
104+
105+
(anIdentitySet includes: self)
106+
ifTrue:
107+
[
108+
(anIdentityDictionary keys includes: self)
109+
ifFalse: [anIdentityDictionary add: self -> (anIdentityDictionary size + 1)].
110+
^ anIdentityDictionary
111+
].
112+
anIdentitySet add: self.
113+
114+
self do: [:ea |
115+
(ea isConsCell | ea isArray) ifTrue:
116+
[ea storeCycles: anIdentityDictionary with: anIdentitySet]].
117+
118+
^ anIdentityDictionary
119+
]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Extension { #name : #Character }
2+
3+
{ #category : #'*ConsCell' }
4+
Character >> printOn: aStream forLisp: aLisp [
5+
6+
aLisp ifNotNil:
7+
[^ aStream nextPutAll: (aLisp class characterPrintString: self)].
8+
9+
aStream nextPutAll: (self codePoint caseOf:
10+
{
11+
[10] -> ['#\newline'] .
12+
[9] -> ['#\tab'] .
13+
[32] -> ['#\space'] .
14+
[8] -> ['#\backspace'] .
15+
[27] -> ['#\escape'] .
16+
[13] -> ['#\return'] .
17+
[127] -> ['#\rubout'] .
18+
}
19+
otherwise: ['#\', self asString])
20+
]

0 commit comments

Comments
 (0)