Mercurial > repos > rhope
comparison kernel.rhope @ 136:fc3815b7462f
Javascript backend now produces working code for some simple examples, still more of the standard lib that needs to be ported.
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 14 Nov 2010 23:07:55 -0500 |
parents | 8aedae4f4ddd |
children | f2cb85c53ced |
comparison
equal
deleted
inserted
replaced
135:18a4403fe576 | 136:fc3815b7462f |
---|---|
1 Import kernelbase.rhope | |
1 Import array.rhope | 2 Import array.rhope |
2 Import string.rhope | 3 Import string.rhope |
3 Import list.rhope | 4 Import list.rhope |
4 Import functional.rhope | 5 Import functional.rhope |
5 Import file.rhope | 6 Import file.rhope |
6 Import dict.rhope | 7 Import dict.rhope |
7 Import range.rhope | 8 Import range.rhope |
8 | 9 |
9 Val[in:out] | |
10 { | |
11 out <- in | |
12 } | |
13 | |
14 Blueprint Boolean | 10 Blueprint Boolean |
15 { | 11 { |
16 Val(Int32,Naked) | 12 Val(Int32,Naked) |
17 } | 13 } |
18 | 14 |
37 If@Int64[num:yes,no] | 33 If@Int64[num:yes,no] |
38 { | 34 { |
39 yes,no <- If[[num]!=[0i64]] | 35 yes,no <- If[[num]!=[0i64]] |
40 } | 36 } |
41 | 37 |
42 Blueprint Int32 | |
43 { | |
44 Num(Int32,Naked) | |
45 } | |
46 | |
47 If@Int32[num:yes,no] | |
48 { | |
49 yes,no <- If[[num]!=[0i32]] | |
50 } | |
51 | |
52 Foreign C:libc | 38 Foreign C:libc |
53 { | 39 { |
54 write[filedes(Int32,Naked),buf(Array,Raw Pointer),nbyte(Int64,Naked):written(Int32,Naked)] | 40 write[filedes(Int32,Naked),buf(Array,Raw Pointer),nbyte(Int64,Naked):written(Int32,Naked)] |
55 read[filedes(Int32,Naked),buf(Array,Raw Pointer,Mutable),nbyte(Int64,Naked):read(Int64,Naked),buf] | 41 read[filedes(Int32,Naked),buf(Array,Raw Pointer,Mutable),nbyte(Int64,Naked):read(Int64,Naked),buf] |
56 } | |
57 | |
58 Trunc UInt8@UInt8[in:out] | |
59 { | |
60 out <- in | |
61 } | 42 } |
62 | 43 |
63 __String Int[n,buf,ten:out] | 44 __String Int[n,buf,ten:out] |
64 { | 45 { |
65 If[[n] < [ten]] | 46 If[[n] < [ten]] |
166 If@UInt64[num:yes,no] | 147 If@UInt64[num:yes,no] |
167 { | 148 { |
168 yes,no <- If[[num]!=[0u64]] | 149 yes,no <- If[[num]!=[0u64]] |
169 } | 150 } |
170 | 151 |
171 Blueprint UInt32 | |
172 { | |
173 Num(UInt32,Naked) | |
174 } | |
175 | |
176 If@UInt32[num:yes,no] | |
177 { | |
178 yes,no <- If[[num]!=[0u32]] | |
179 } | |
180 | |
181 Blueprint UInt16 | 152 Blueprint UInt16 |
182 { | 153 { |
183 Num(UInt16,Naked) | 154 Num(UInt16,Naked) |
184 } | 155 } |
185 | 156 |
186 If@UInt16[num:yes,no] | 157 If@UInt16[num:yes,no] |
187 { | 158 { |
188 yes,no <- If[[num]!=[0u16]] | 159 yes,no <- If[[num]!=[0u16]] |
189 } | |
190 | |
191 Blueprint UInt8 | |
192 { | |
193 Num(UInt8,Naked) | |
194 } | |
195 | |
196 If@UInt8[num:yes,no] | |
197 { | |
198 yes,no <- If[[num]!=[0u8]] | |
199 } | 160 } |
200 | 161 |
201 Abs@Int64[num:out] | 162 Abs@Int64[num:out] |
202 { | 163 { |
203 If[[num]<[0i64]] | 164 If[[num]<[0i64]] |
204 { out <- [0i64]-[num] } | 165 { out <- [0i64]-[num] } |
205 { out <- num } | 166 { out <- num } |
206 } | 167 } |
207 | 168 |
208 Abs@Int32[num:out] | |
209 { | |
210 If[[num]<[0i32]] | |
211 { out <- [0i32]-[num] } | |
212 { out <- num } | |
213 } | |
214 | |
215 Abs@Int16[num:out] | 169 Abs@Int16[num:out] |
216 { | 170 { |
217 If[[num]<[0i16]] | 171 If[[num]<[0i16]] |
218 { out <- [0i16]-[num] } | 172 { out <- [0i16]-[num] } |
219 { out <- num } | 173 { out <- num } |
222 Abs@Int8[num:out] | 176 Abs@Int8[num:out] |
223 { | 177 { |
224 If[[num]<[0i8]] | 178 If[[num]<[0i8]] |
225 { out <- [0i8]-[num] } | 179 { out <- [0i8]-[num] } |
226 { out <- num } | 180 { out <- num } |
227 } | |
228 | |
229 Mod[a,b:out] | |
230 { | |
231 out <- [a]-[[[a]/[b]]*[b]] | |
232 } | 181 } |
233 | 182 |
234 Foreign C:runtime | 183 Foreign C:runtime |
235 { | 184 { |
236 _internal_blueprint_eq[left(Blueprint),right(Blueprint):out(Int32,Naked)] | 185 _internal_blueprint_eq[left(Blueprint),right(Blueprint):out(Int32,Naked)] |
297 =@Blueprint[left,right:out] | 246 =@Blueprint[left,right:out] |
298 { | 247 { |
299 out <- [_internal_blueprint_eq[left,right]]!=[0] | 248 out <- [_internal_blueprint_eq[left,right]]!=[0] |
300 } | 249 } |
301 | 250 |
302 And[left,right:out] | |
303 { | |
304 ,out <- If[left] | |
305 { | |
306 out,out <- If[right] | |
307 } | |
308 } | |
309 | |
310 Or[left,right:out] | |
311 { | |
312 out <- If[left] {} | |
313 { | |
314 out <- right | |
315 } | |
316 } | |
317 | |
318 Min[a,b:out] | |
319 { | |
320 If[[a]<[b]] | |
321 { | |
322 out <- a | |
323 }{ | |
324 out <- b | |
325 } | |
326 } | |
327 | |
328 Max[a,b:out] | |
329 { | |
330 If[[a]>[b]] | |
331 { | |
332 out <- a | |
333 }{ | |
334 out <- b | |
335 } | |
336 } | |
337 | |
338 _Keys[list,val,key:out] | 251 _Keys[list,val,key:out] |
339 { | 252 { |
340 out <- [list]Append[key] | 253 out <- [list]Append[key] |
341 } | 254 } |
342 | 255 |