comparison arrayjs.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
children
comparison
equal deleted inserted replaced
135:18a4403fe576 136:fc3815b7462f
1
2 Blueprint Array
3 {
4
5 }
6
7 Foreign Javascript:runtime
8 {
9 _internal_js_length[array:out(Int32,Naked)]
10 _internal_array_set[array(Array,Boxed,Mutable),index(Int32,Naked),val:array]
11 _internal_array_get[array(Array),index(Int32,Naked):out]
12 }
13
14 Array[:out(Empty Array)]
15 {
16 out <- Build[Array()]
17 }
18
19 First@Array[array:out(Int32),empty]
20 {
21 ,empty <- If[[array]Length]
22 { out <- 0 }
23 }
24
25
26 Next@Array[array,current:out(Int32),empty]
27 {
28 next <- [current]+[1]
29 ,empty <- If[[next] < [[array]Length]]
30 {
31 out <- Val[next]
32 }
33 }
34
35
36 Last@Array[array:out(Int32),empty]
37 {
38 ,empty <- If[[array]Length]
39 { out <- [[array]Length] - [1] }
40 }
41
42 Append@Array[array,newval:out]
43 {
44 out <- [array]Set[[array]Length, newval]
45 }
46
47 Index@Array[array,index(Int32):out,notfound]
48 {
49 ,notfound <- If[[index] >= [0]]
50 {
51 ,notfound <- If[[index] < [[array]Length]]
52 {
53 out <- _internal_array_get[array, index]
54 }
55 }
56 }
57
58 Set@Array[array,index(Int32),val:out,invalid]
59 {
60 invalid <- If[[index]<[0]] {}
61 {
62 len <- [array]Length
63 If[[index]>[len]]
64 {
65 out <- [[array]Set[[index]-[1],val]]Set[index, val]
66 }{
67 out <- _internal_array_set[array,index,val]
68 }
69 }
70 }
71
72 Length@Array[arr:out]
73 {
74 out <- _internal_js_length[arr]
75 }
76
77 Call@Array[arr,index(Int32):out,not found]
78 {
79 out,not found <- [arr]Index[index]
80 }
81