Mercurial > repos > rhope
comparison array.rhope @ 102:2f6f0867fd68
Added files I forgot to add in a previous commit
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Tue, 10 Aug 2010 20:55:52 -0400 |
parents | |
children | 43cc42df26cc |
comparison
equal
deleted
inserted
replaced
101:f4fc0a98088a | 102:2f6f0867fd68 |
---|---|
1 | |
2 Blueprint Array | |
3 { | |
4 Eltype(Blueprint) | |
5 Length(Int32,Naked) | |
6 Storage(Int32,Naked) | |
7 } | |
8 | |
9 Blueprint Boxed Array | |
10 { | |
11 Length(Int32,Naked) | |
12 Storage(Int32,Naked) | |
13 } | |
14 | |
15 Blueprint Empty Array | |
16 { | |
17 } | |
18 | |
19 Foreign C:runtime | |
20 { | |
21 _internal_array_copyout[array(Array), index(Int32,Naked), dest(Any Type,Boxed,Mutable):dest] | |
22 _internal_array_copyin[array(Array,Boxed,Mutable), index(Int32,Naked), val:array] | |
23 _internal_array_getboxed[array(Boxed Array), index(Int32,Naked):out] | |
24 _internal_array_setboxed[array(Boxed Array,Boxed,Mutable), index(Int32,Naked), val:array] | |
25 _internal_array_allocboxed[size(Int32,Naked):out(Boxed Array)] | |
26 _internal_array_allocboxedcopy[source(Boxed Array),size(Int32,Naked):out(Boxed Array)] | |
27 _internal_array_allocnaked[size(Int32,Naked),type(Blueprint):out(Array)] | |
28 _internal_array_allocnakedcopy[source(Array),size(Int32,Naked):out(Array)] | |
29 } | |
30 | |
31 Array[:out(Empty Array)] | |
32 { | |
33 out <- Build[Empty Array()] | |
34 } | |
35 | |
36 First@Empty Array[array:out,empty] | |
37 { | |
38 empty <- array | |
39 } | |
40 | |
41 First@Array[array:out(Int32),empty] | |
42 { | |
43 ,empty <- If[[array]Length >>] | |
44 { out <- 0 } | |
45 } | |
46 | |
47 First@Boxed Array[array:out(Int32),empty] | |
48 { | |
49 ,empty <- If[[array]Length >>] | |
50 { out <- 0 } | |
51 } | |
52 | |
53 Next@Empty Array[array:out,empty] | |
54 { | |
55 empty <- array | |
56 } | |
57 | |
58 Next@Array[array,current:out(Int32),empty] | |
59 { | |
60 next <- [current]+[1] | |
61 ,empty <- If[[next] < [[array]Length >>]] | |
62 { | |
63 out <- Val[next] | |
64 } | |
65 } | |
66 | |
67 Next@Boxed Array[array,current:out(Int32),empty] | |
68 { | |
69 next <- [current]+[1] | |
70 ,empty <- If[[next] < [[array]Length >>]] | |
71 { | |
72 out <- Val[next] | |
73 } | |
74 } | |
75 | |
76 Last@Empty Array[array:out,empty] | |
77 { | |
78 empty <- array | |
79 } | |
80 | |
81 Last@Array[array:out(Int32),empty] | |
82 { | |
83 ,empty <- If[[array]Length >>] | |
84 { out <- [[array]Length >>] - [1] } | |
85 } | |
86 | |
87 Last@Boxed Array[array:out(Int32),empty] | |
88 { | |
89 ,empty <- If[[array]Length >>] | |
90 { out <- [[array]Length >>] - [1] } | |
91 } | |
92 | |
93 Append@Empty Array[array,newval:out(Array)] | |
94 { | |
95 out <- [array]Set[0, newval] | |
96 } | |
97 | |
98 Append@Array[array,newval:out] | |
99 { | |
100 out <- [array]Set[[array]Length >>, newval] | |
101 } | |
102 | |
103 Append@Boxed Array[array,newval:out(Boxed Array)] | |
104 { | |
105 out <- [array]Set[[array]Length >>, newval] | |
106 } | |
107 | |
108 Index@Empty Array[array:out,notfound] | |
109 { | |
110 notfound <- array | |
111 } | |
112 | |
113 Index@Array[array,index(Int32):out,notfound] | |
114 { | |
115 ,notfound <- If[[index] >= [0]] | |
116 { | |
117 ,notfound <- If[[index] < [[array]Length >>]] | |
118 { | |
119 out <- _internal_array_copyout[array, index, Build[[array]Eltype >>]] | |
120 } | |
121 } | |
122 } | |
123 | |
124 Index@Boxed Array[array,index(Int32):out,notfound] | |
125 { | |
126 ,notfound <- If[[index] >= [0]] | |
127 { | |
128 ,notfound <- If[[index] < [[array]Length >>]] | |
129 { | |
130 out <- _internal_array_getboxed[array, index] | |
131 } | |
132 } | |
133 } | |
134 | |
135 _Copy to Boxed[source,dest,current:out] | |
136 { | |
137 ndest <- _internal_array_setboxed[dest, current, [source]Index[current]] | |
138 | |
139 [source]Next[current] | |
140 { | |
141 out <- _Copy to Boxed[source, ndest, ~] | |
142 }{ | |
143 out <- Val[ndest] | |
144 } | |
145 } | |
146 | |
147 _Copy Naked[source,dest,current:out] | |
148 { | |
149 ndest <- _internal_array_copyin[dest, current, [source]Index[current]] | |
150 | |
151 [source]Next[current] | |
152 { | |
153 out <- _Copy Naked[source, ndest, ~] | |
154 }{ | |
155 out <- Val[ndest] | |
156 } | |
157 } | |
158 | |
159 Set@Array[array,index(Int32),val:out,invalid] | |
160 { | |
161 invalid <- If[[index]<[0]] {} | |
162 { | |
163 len <- [array]Length >> | |
164 If[[index]>[len]] | |
165 { | |
166 out <- [[array]Set[[index]-[1],val]]Set[index, val] | |
167 }{ | |
168 If[[Blueprint Of[val]]=[[array]Eltype >>]] | |
169 { | |
170 If[[index]<[[array]Storage >>]] | |
171 { | |
172 out <- [_internal_array_copyin[array, index, val]]Length <<[Max[len, [index]+[1]]] | |
173 }{ | |
174 //Does this make sense given the copies we may have to make? | |
175 If[[index] < [4]] | |
176 { | |
177 new storage <- [index]+[index] | |
178 }{ | |
179 new storage <- [index]+[[index]RShift[1]] | |
180 } | |
181 out <- [_internal_array_copyin[_internal_array_allocnakedcopy[array, new storage], index, val]]Length <<[[index]+[1]] | |
182 } | |
183 }{ | |
184 out <-[[_Copy to Boxed[array, _internal_array_allocboxed[[array]Storage >>], [array]First]]Length <<[[array]Length >>]]Set[index, val] | |
185 } | |
186 } | |
187 } | |
188 } | |
189 | |
190 Set@Boxed Array[array,index(Int32),val:out(Boxed Array),invalid] | |
191 { | |
192 invalid <- If[[index]<[0]] {} | |
193 { | |
194 len <- [array]Length >> | |
195 If[[index]>[len]] | |
196 { | |
197 out <- [[array]Set[[index]-[1],val]]Set[index, val] | |
198 }{ | |
199 If[[index]<[[array]Storage >>]] | |
200 { | |
201 out <- [_internal_array_setboxed[array, index, val]]Length <<[Max[len, [index]+[1]]] | |
202 }{ | |
203 //Does this make sense given the copies we may have to make? | |
204 If[[index] < [4]] | |
205 { | |
206 new storage <- [index]+[index] | |
207 }{ | |
208 new storage <- [index]+[[index]RShift[1]] | |
209 } | |
210 out <- [_internal_array_setboxed[_internal_array_allocboxedcopy[array, new storage], index, val]]Length <<[[index]+[1]] | |
211 } | |
212 } | |
213 } | |
214 } | |
215 | |
216 Set@Empty Array[array,index(Int32),val:out(Array),invalid] | |
217 { | |
218 invalid <- If[[index]<[0]] {} | |
219 { | |
220 out <- [_internal_array_allocnaked[1, Blueprint Of[val]]]Set[index, val] | |
221 } | |
222 } | |
223 | |
224 Length@Empty Array[arr:out] | |
225 { | |
226 out <- 0 | |
227 } | |
228 | |
229 Length@Array[arr:out] | |
230 { | |
231 out <- [arr]Length >> | |
232 } | |
233 | |
234 Length@Boxed Array[arr:out] | |
235 { | |
236 out <- [arr]Length >> | |
237 } | |
238 | |
239 Call@Array[arr,index(Int32):out,not found] | |
240 { | |
241 out,not found <- [arr]Index[index] | |
242 } | |
243 | |
244 Call@Boxed Array[arr,index(Int32):out,not found] | |
245 { | |
246 out,not found <- [arr]Index[index] | |
247 } | |
248 |