comparison list.rhope @ 75:0083b2f7b3c7

Partially working implementation of List. Modified build scripts to allow use of other compilers. Fixed some bugs involving method implementations on different types returning different numbers of outputs. Added Fold to the 'builtins' in the comipler.
author Mike Pavone <pavone@retrodev.com>
date Tue, 06 Jul 2010 07:52:59 -0400
parents 1bfcf5f8fa69
children 004f0fc8941f
comparison
equal deleted inserted replaced
74:a844c623c7df 75:0083b2f7b3c7
7 Index@List Leaf[list,index:out,not found] 7 Index@List Leaf[list,index:out,not found]
8 { 8 {
9 out, not found <- [[list]Buffer >>]Index[index] 9 out, not found <- [[list]Buffer >>]Index[index]
10 } 10 }
11 11
12 Set@List Leaf[list,index,value:out] 12 Set@List Leaf[list,index,value:out,invalid index]
13 { 13 {
14 If[[index] < [0]] 14 If[[index] < [0]]
15 { 15 {
16 }{ 16 rev index <- [[[list]Buffer >>]Length >>]+[index]
17 If[[index] > [[[list]Buffer >>]Length >>]] 17 invalid index <- If[[rev index] < [0]] {}
18 {
19 out,invalid index <- [list]Set[rev index, value]
20 }
21
22 }{
23 len <- [[list]Buffer >>]Length >>
24 If[[index] > [len]]
18 { 25 {
19 makeleft <- Yes 26 makeleft <- Yes
20 }{ 27 }{
21 If[[index] > [7]] 28 If[[[index] > [7]] And [[index] >= [len]]]
22 { 29 {
23 makeleft <- Yes 30 makeleft <- Yes
24 }{ 31 }{
25 out <- [list]Buffer <<[ [[list]Buffer >>]Set[index, value] ] 32 out <- [list]Buffer <<[ [[list]Buffer >>]Set[index, value] ]
26 } 33 }
37 ]Right Offset <<[[index]+[8i32]] 44 ]Right Offset <<[[index]+[8i32]]
38 ]Length << [ [[list]Length]+[1] ] 45 ]Length << [ [[list]Length]+[1] ]
39 } 46 }
40 } 47 }
41 48
49 _Right Set@List Leaf[list,index,val:out,didn't set]
50 {
51 len <- [[list]Buffer >>]Length >>
52 do it <- If[[index] < [len]] {}
53 {
54 ,didn't set <- If[[index]=[len]]
55 {
56 didn't set,do it <- If[[index]>[7]]
57 }
58 }
59 Val[do it]
60 {
61 out <- [list]Set[index,val]
62 }
63 }
64
65 Length@List Leaf[list:out]
66 {
67 out <- [[list]Buffer >>]Length >>
68 }
69
70 Last@List Leaf[list:out,none]
71 {
72 len <- [[list]Buffer >>]Length >>
73 ,none <-If[len]
74 {
75 out <- [len]-[1]
76 }
77 }
78
79 Append@List Leaf[list,val:out]
80 {
81 [list]Last
82 { index <- [~]+[1] }
83 { index <- 0 }
84 out <- [list]Set[index, val]
85 }
86
87 First@List Leaf[list:out,none]
88 {
89 Print["First@List Leaf"]
90 [[list]Buffer >>]Index[0]
91 { out <- 0 }
92 { none <- Yes }
93 }
94
95 Next@List Leaf[list,index:next,none]
96 {
97 Print["Next@List Leaf"]
98 { Print[index]
99 {
100 pos next <- [index]+[1]
101 ,none <- If[[pos next] < [[list]Length]]
102 {
103 next <- Val[pos next]
104 }
105 }}
106 }
107
42 Blueprint List 108 Blueprint List
43 { 109 {
44 Buffer 110 Buffer
45 Left 111 Left
46 Right 112 Right
67 out, not found <- [[list]Right >>]Index[[index]-[[list]Right Offset >>]] 133 out, not found <- [[list]Right >>]Index[[index]-[[list]Right Offset >>]]
68 } 134 }
69 } 135 }
70 } 136 }
71 137
72 Set@List[list,index,val:out,not found] 138 Length@List[list:out]
73 { 139 {
74 140 out <- [list]Length >>
75 } 141 }
76 142
77 143 Set@List[list,index,val:out,invalid index]
144 {
145 If[[index] < [0]]
146 {
147 , invalid index <- [list]Last
148 { rev index <- [[~]+[1]]+[index] }
149 invalid index <- If[[rev index] < [0]] {}
150 { out,invalid index <- [list]Set[rev index, val] }
151
152 }{
153 If[[index]<[[list]Offset >>]]
154 {
155 lsize <- [[list]Left >>]Length
156 [[list]Left >>]Set[index, val]
157 {
158 out <- [[list]Left <<[~]
159 ]Length <<[ [[list]Length >>]+[[[~]Length]-[lsize]] ]
160 }
161 }{
78 162
163 If[[index]<[[list]Right Offset >>]]
164 {
165 off index <- [index]-[[list]Offset >>]
166 bsize <- [[list]Buffer >>]Length >>
167 If[[off index]>[bsize]]
168 {
169 If[[[list]Right >>]Length]
170 {
171 my end <- [[list]Offset >>]+[[[list]Buffer >>]Length]
172 nroffset <- [[[index]-[my end]]/[2]]+[my end]
173 nright <- out <- [[[[[[Build[List()]
174 ]Buffer << [[Array[]]Append[val]]
175 ]Left << [List[]]
176 ]Right << [[list]Right >>]
177 ]Offset << [[index]-[nroffset]]
178 ]Right Offset <<[ [[list]Right Offset>>]-[nroffset] ]
179 ]Length << [ [[[list]Right >>]Length]+[1] ]
180
181 out <- [[[list]Right <<[nright]
182 ]Length <<[ [[list]Length >>]+[1] ]
183 ]Right Offset <<[nroffset]
184 }{
185
186 out <- [[[list]Right <<[ [[list]Right >>]Set[0, val] ]
187 ]Right Offset <<[index]
188 ]Length <<[ [[list]Length >>]+[1] ]
189 }
190 }{
191 [[list]Buffer >>]Set[off index, val]
192 {
193 out <- [[list]Buffer <<[~]
194 ]Length <<[ [[list]Length >>]+[[[~]Length >>]-[bsize]] ]
195 }
196 }
197 }{
198 rsize <- [[list]Right>>]Length
199 adj ind <- [index]-[[list]Right Offset>>]
200 If[[[[list]Left>>]Length] > [rsize]]
201 {
202 [[list]Right >>]Set[adj ind, val]
203 {
204 out <- [[list]Right <<[~]
205 ]Length <<[ [[list]Length >>]+[[[~]Length]-[rsize]] ]
206 }
207 }{
208 [[list]Right >>]_Right Set[adj ind, val]
209 {
210 out <- [[list]Right <<[~]
211 ]Length <<[ [[list]Length >>]+[[[~]Length]-[rsize]] ]
212 }{
213 out <- [[[[[[Build[List()]
214 ]Buffer << [[Array[]]Append[val]]
215 ]Left << [list]
216 ]Right << [List[]]
217 ]Offset << [index]
218 ]Right Offset <<[[index]+[8i32]]
219 ]Length << [ [[list]Length]+[1] ]
220 }
221 }
222 }
223 }
224 }
225 }
226
227 _Right Set@List[list,index,val:out,didn't set]
228 {
229 If[[[list]Right Offset >>]>[index]]
230 {
231 out <- [list]Set[index, val]
232 }{
233 out,did'nt set <- [list]_Right Set[[index]-[[list]Right Offset >>], val]
234 }
235 }
236
237 Last@List[list:out,none]
238 {
239 [[list]Right >>]Last
240 { out <- [~]+[[list]Right Offset >>] }
241 { out <- [[[[list]Buffer >>]Length >>]-[1]]+[[list]Offset >>] }
242 }
243
244 Append@List[list,val:out]
245 {
246 [list]Last
247 { index <- [~]+[1] }
248 { index <- 0 }
249 out <- [list]Set[index, val]
250 }
251
252 First@List[list:out,none]
253 {
254 Print["First@List"]
255 If[[[list]Left >>]Length]
256 {
257 out <- [[list]Left >>]First
258 }{
259 out <- [list]Offset >>
260 }
261 }
262
263 Next@List[list,index:next,none]
264 {
265 Print["Next@List"]
266 { Print[index]
267 { Print[[list]Offset >>]
268 {
269 If[[index] < [[[list]Offset >>]-[1]]]
270 {
271 Print["Left"]
272 next <- [[list]Left >>]Next[index] {}
273 { next <- Offset >>[list] }
274 }{
275 If[[index] < [[list]Right Offset >>]]
276 {
277 Print["Middle"]
278 pos next <- [index]+[1]
279 If[[pos next] < [[[[list]Buffer >>]Length >>]+[[list]Offset >>]]]
280 {
281 next <- Val[pos next]
282 }{
283 Print["Middle done going Right instead"]
284 ,none <- [[list]Right >>]First
285 { next <- [~]+[[list]Right Offset >>] }
286 {
287 Print["First on right returned none"]
288 { Print[[[list]Right >>]Length] }
289 }
290 }
291 }{
292 Print["right"]
293 ,none <- [[list]Right >>]Next[[index]-[[list]Right Offset >>]]
294 { next <- [~]+[[list]Right Offset >>] }
295 }
296 }
297 }}}
298 }
299