Mercurial > repos > rhope
comparison kernel.rhope @ 49:3e20ed8959c4
Added initial FFI implementation, Array type and 64-bit integers
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Thu, 08 Apr 2010 01:02:18 -0400 |
parents | a24eb366195c |
children | 689fb73e7612 |
comparison
equal
deleted
inserted
replaced
48:a24eb366195c | 49:3e20ed8959c4 |
---|---|
1 | |
2 Val[in:out] | |
3 { | |
4 out <- in | |
5 } | |
1 | 6 |
2 Blueprint Boolean | 7 Blueprint Boolean |
3 { | 8 { |
4 Val(Int32,Naked) | 9 Val(Int32,Naked) |
5 } | 10 } |
6 | 11 |
12 /* | |
13 Blueprint Blueprint | |
14 { | |
15 Val(Blueprint,Naked) | |
16 }*/ | |
17 | |
18 Blueprint Int64 | |
19 { | |
20 Num(Int64,Naked) | |
21 } | |
22 | |
23 If@Int64[num:yes,no] | |
24 { | |
25 yes,no <- If[[num]!=[0]] | |
26 } | |
27 | |
7 Blueprint Int32 | 28 Blueprint Int32 |
8 { | 29 { |
9 Num(Int32,Naked) | 30 Num(Int32,Naked) |
10 } | 31 } |
11 | 32 |
12 If@Int32[num:yes,no] | 33 If@Int32[num:yes,no] |
13 { | 34 { |
14 yes,no <- If[[num]=[0]] | 35 yes,no <- If[[num]!=[0]] |
15 } | 36 } |
16 | 37 |
17 Blueprint Int16 | 38 Blueprint Int16 |
18 { | 39 { |
19 Num(Int16,Naked) | 40 Num(Int16,Naked) |
20 } | 41 } |
21 | 42 |
22 If@Int16[num:yes,no] | 43 If@Int16[num:yes,no] |
23 { | 44 { |
24 yes,no <- If[[num]=[0]] | 45 yes,no <- If[[num]!=[0]] |
25 } | 46 } |
26 | 47 |
27 Blueprint Int8 | 48 Blueprint Int8 |
28 { | 49 { |
29 Num(Int8,Naked) | 50 Num(Int8,Naked) |
30 } | 51 } |
31 | 52 |
32 If@Int8[num:yes,no] | 53 If@Int8[num:yes,no] |
33 { | 54 { |
34 yes,no <- If[[num]=[0]] | 55 yes,no <- If[[num]!=[0]] |
56 } | |
57 | |
58 Blueprint UInt64 | |
59 { | |
60 Num(UInt64,Naked) | |
61 } | |
62 | |
63 If@UInt64[num:yes,no] | |
64 { | |
65 yes,no <- If[[num]!=[0]] | |
35 } | 66 } |
36 | 67 |
37 Blueprint UInt32 | 68 Blueprint UInt32 |
38 { | 69 { |
39 Num(UInt32,Naked) | 70 Num(UInt32,Naked) |
40 } | 71 } |
41 | 72 |
42 If@UInt32[num:yes,no] | 73 If@UInt32[num:yes,no] |
43 { | 74 { |
44 yes,no <- If[[num]=[0]] | 75 yes,no <- If[[num]!=[0]] |
45 } | 76 } |
46 | 77 |
47 Blueprint UInt16 | 78 Blueprint UInt16 |
48 { | 79 { |
49 Num(UInt16,Naked) | 80 Num(UInt16,Naked) |
50 } | 81 } |
51 | 82 |
52 If@UInt16[num:yes,no] | 83 If@UInt16[num:yes,no] |
53 { | 84 { |
54 yes,no <- If[[num]=[0]] | 85 yes,no <- If[[num]!=[0]] |
55 } | 86 } |
56 | 87 |
57 Blueprint UInt8 | 88 Blueprint UInt8 |
58 { | 89 { |
59 Num(UInt8,Naked) | 90 Num(UInt8,Naked) |
60 } | 91 } |
61 | 92 |
62 If@UInt8[num:yes,no] | 93 If@UInt8[num:yes,no] |
63 { | 94 { |
64 yes,no <- If[[num]=[0]] | 95 yes,no <- If[[num]!=[0]] |
65 } | 96 } |
66 | 97 |
67 | 98 |
99 Blueprint Array | |
100 { | |
101 Eltype(Blueprint) | |
102 Length(Int32,Naked) | |
103 Storage(Int32,Naked) | |
104 } | |
105 | |
106 Foreign C:runtime | |
107 { | |
108 _internal_array_copyout[array(Array), index(Int32,Naked), dest(Any Type,Boxed,Mutable):dest] | |
109 _internal_array_copyin[array(Array,Boxed,Mutable), index(Int32,Naked), val:array] | |
110 _internal_array_getboxed[array(Array), index(Int32,Naked):out] | |
111 _internal_array_setboxed[array(Array,Boxed,Mutable), index(Int32,Naked), val:array] | |
112 _internal_array_allocboxed[size(Int32,Naked):out(Array)] | |
113 _internal_array_allocnaked[size(Int32,Naked),type(Blueprint):out(Array)] | |
114 _internal_blueprint_eq[left(Blueprint),right(Blueprint):out(Int32,Naked)] | |
115 } | |
116 | |
117 =@Blueprint[left,right:out] | |
118 { | |
119 out <- [_internal_blueprint_eq[left,right]]!=[0] | |
120 } | |
121 | |
122 Array[n:out(Array)] | |
123 { | |
124 out <- [[_internal_array_allocboxed[0] | |
125 ]Length <<[0] | |
126 ]Storage <<[0] | |
127 } | |
128 | |
129 First@Array[array:out(Int32),empty] | |
130 { | |
131 ,empty <- If[[array]Length >>] | |
132 { out <- 0 } | |
133 } | |
134 | |
135 Next@Array[array,current:out(Int32),empty] | |
136 { | |
137 next <- [current]+[1] | |
138 ,empty <- If[[next] < [[array]Length >>]] | |
139 { | |
140 out <- Val[next] | |
141 } | |
142 } | |
143 | |
144 Last@Array[array:out(Int32),empty] | |
145 { | |
146 ,empty <- If[[array]Length >>] | |
147 { out <- [[array]Length >>] - [1] } | |
148 } | |
149 | |
150 Append@Array[array,newval:out(Array)] | |
151 { | |
152 out <- [array]Set[[array]Length >>, newval] | |
153 } | |
154 | |
155 Index@Array[array,index(Int32):out,notfound] | |
156 { | |
157 ,notfound <- If[[index] >= [0]] | |
158 { | |
159 ,notfound <- If[[index] < [[array]Length >>]] | |
160 { | |
161 eltype <- [array]Eltype >> | |
162 If[[eltype] = [Any Type()]] | |
163 { | |
164 out <- _internal_array_getboxed[array, index] | |
165 }{ | |
166 out <- _internal_array_copyout[array, index, Build[eltype]] | |
167 } | |
168 } | |
169 } | |
170 } | |
171 | |
172 _Copy to Boxed[source,dest,current:out] | |
173 { | |
174 ndest <- _internal_array_setboxed[dest, current, [source]Index[current]] | |
175 | |
176 [source]Next[current] | |
177 { | |
178 out <- _Copy to Boxed[source, ndest, ~] | |
179 }{ | |
180 out <- Val[ndest] | |
181 } | |
182 } | |
183 | |
184 _Copy Naked[source,dest,current:out] | |
185 { | |
186 ndest <- _internal_array_copyin[dest, current, [source]Index[current]] | |
187 | |
188 [source]Next[current] | |
189 { | |
190 out <- _Copy Naked[source, ndest, ~] | |
191 }{ | |
192 out <- Val[ndest] | |
193 } | |
194 } | |
195 | |
196 Set@Array[array,index(Int32),val:out(Array)] | |
197 { | |
198 If[[index] < [[array]Storage >>]] | |
199 { | |
200 If[[index] > [[array]Length >>]] | |
201 { | |
202 farray <- [[array]Set[[index]-[1], val]]Length <<[ [index]+[1] ] | |
203 }{ | |
204 If[[index] = [[array]Length >>]] | |
205 { | |
206 farray <- [array]Length <<[ [index]+[1] ] | |
207 }{ | |
208 farray <- Val[array] | |
209 } | |
210 } | |
211 eltype <- [array]Eltype >> | |
212 If[[eltype] = [Any Type()]] | |
213 { | |
214 out <- _internal_array_setboxed[farray, index, val] | |
215 }{ | |
216 If[[Blueprint Of[val]] = [eltype]] | |
217 { | |
218 out <- _internal_array_copyin[farray, index, val] | |
219 }{ | |
220 boxed <- _internal_array_allocboxed[[farray]Storage >>] | |
221 [array]First | |
222 { | |
223 copied <- _Copy to Boxed[farray, boxed, ~] | |
224 }{ | |
225 //I don't think this case should happen normally | |
226 copied <- Val[boxed] | |
227 } | |
228 out <- _internal_array_setboxed[copied, index, val] | |
229 } | |
230 } | |
231 }{ | |
232 If[[array]Length >>] | |
233 { | |
234 If[[index] < [4]] | |
235 { | |
236 new storage <- [index]+[index] | |
237 }{ | |
238 new storage <- [index]+[[index]RShift[1]] | |
239 } | |
240 | |
241 do boxed <- If[[[array]Eltype >>] = [Any Type()]] | |
242 { | |
243 copied <- _Copy to Boxed[array, _internal_array_allocboxed[new storage], 0] | |
244 }{ | |
245 bp <- Blueprint Of[val] | |
246 If[[[array]Eltype >>] = [bp]] | |
247 { | |
248 copied <- _Copy Naked[array, _internal_array_allocnaked[new storage, bp], 0] | |
249 }{ | |
250 copied <- _Copy to Boxed[array, _internal_array_allocboxed[new storage], 0] | |
251 } | |
252 } | |
253 out <- [[copied]Length <<[[array]Length >>]]Set[index,val] | |
254 }{ | |
255 len <- [index]+[1] | |
256 out <- [_internal_array_allocnaked[len, Blueprint Of[val]] | |
257 ]Set[index,val] | |
258 } | |
259 } | |
260 } | |
261 | |
262 |