Mercurial > repos > tabletprog
annotate modules/array.tp @ 377:93c28eee141e default tip
Merge
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 15 Aug 2015 22:45:33 -0700 |
parents | e857104bd183 810b6115c1d4 |
children |
rev | line source |
---|---|
84
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1 #{ |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2 llProperty: size withType: uint32_t |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
3 llProperty: storage withType: uint32_t |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
4 llProperty: data withType: ((object ptr) ptr) |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
5 llMessage: get withVars: { |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 index <- obj_int32 ptr |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 } andCode: :index { |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
8 if: (index num) >= 0 && (index num) < size { |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
9 (self data) get: (index num) |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
10 } else: { |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
11 false |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
12 } |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
13 } |
144
547153211389
Fix fold:with foldr:with and map in the array module
Mike Pavone <pavone@retrodev.com>
parents:
84
diff
changeset
|
14 |
84
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
15 llMessage: set withVars: { |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
16 index <- obj_int32 ptr |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
17 value <- object ptr |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
18 } andCode: :index value { |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 if: (index num) >= 0 && (index num) < size { |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
20 data set: (index num) value |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 } |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
22 self |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
23 } |
144
547153211389
Fix fold:with foldr:with and map in the array module
Mike Pavone <pavone@retrodev.com>
parents:
84
diff
changeset
|
24 |
84
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
25 llMessage: foreach withVars: { |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
26 clos <- lambda ptr |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
27 i <- uint32_t |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
28 index <- obj_int32 ptr |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
29 } andCode: :clos { |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
30 i <- 0 |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
31 while: { i < size } do: { |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
32 index <- make_object: (addr_of: obj_int32_meta) NULL 0 |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
33 index num!: i |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
34 ccall: clos 2 index (data get: i) |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
35 i <- i + 1 |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
36 } |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
37 self |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
38 } |
144
547153211389
Fix fold:with foldr:with and map in the array module
Mike Pavone <pavone@retrodev.com>
parents:
84
diff
changeset
|
39 |
84
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
40 llMessage: append withVars: { |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
41 value <- object ptr |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
42 tmp <- (object ptr) ptr |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
43 } andCode: :value { |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
44 if: storage = size { |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
45 storage <- storage * 2 |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
46 tmp <- GC_REALLOC: data storage * (sizeof: (object ptr)) |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
47 if: (not: tmp) { |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
48 fputs: "Failed to increase array size\n" stderr |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
49 exit: 1 |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
50 } |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
51 data <- tmp |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
52 } |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
53 data set: size value |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
54 size <- size + 1 |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
55 self |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
56 } |
366
810b6115c1d4
Add a pop method to array
Michael Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
57 |
810b6115c1d4
Add a pop method to array
Michael Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
58 llMessage: pop withVars: { |
810b6115c1d4
Add a pop method to array
Michael Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
59 } andCode: { |
810b6115c1d4
Add a pop method to array
Michael Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
60 if: size > 0 { |
810b6115c1d4
Add a pop method to array
Michael Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
61 size <- size - 1 |
810b6115c1d4
Add a pop method to array
Michael Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
62 data get: size |
810b6115c1d4
Add a pop method to array
Michael Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
63 } else: { |
810b6115c1d4
Add a pop method to array
Michael Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
64 false |
810b6115c1d4
Add a pop method to array
Michael Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
65 } |
810b6115c1d4
Add a pop method to array
Michael Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
66 } |
144
547153211389
Fix fold:with foldr:with and map in the array module
Mike Pavone <pavone@retrodev.com>
parents:
84
diff
changeset
|
67 |
249
fd9005253861
Added resize method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
191
diff
changeset
|
68 llMessage: resize withVars: { |
fd9005253861
Added resize method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
191
diff
changeset
|
69 newsize <- obj_uint32 ptr |
fd9005253861
Added resize method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
191
diff
changeset
|
70 tmp <- (object ptr) ptr |
fd9005253861
Added resize method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
191
diff
changeset
|
71 } andCode: :newsize { |
fd9005253861
Added resize method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
191
diff
changeset
|
72 self storage!: (newsize num) |
fd9005253861
Added resize method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
191
diff
changeset
|
73 tmp <- GC_REALLOC: data storage * (sizeof: (object ptr)) |
fd9005253861
Added resize method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
191
diff
changeset
|
74 if: (not: tmp) { |
fd9005253861
Added resize method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
191
diff
changeset
|
75 fputs: "Failed to adjust array size\n" stderr |
fd9005253861
Added resize method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
191
diff
changeset
|
76 exit: 1 |
fd9005253861
Added resize method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
191
diff
changeset
|
77 } |
fd9005253861
Added resize method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
191
diff
changeset
|
78 data <- tmp |
fd9005253861
Added resize method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
191
diff
changeset
|
79 if: size > storage { |
fd9005253861
Added resize method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
191
diff
changeset
|
80 size <- storage |
fd9005253861
Added resize method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
191
diff
changeset
|
81 } |
fd9005253861
Added resize method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
191
diff
changeset
|
82 self |
fd9005253861
Added resize method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
191
diff
changeset
|
83 } |
372
e857104bd183
Added reverse method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
84 |
e857104bd183
Added reverse method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
85 llMessage: reverse withVars: { |
e857104bd183
Added reverse method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
86 front <- int32_t |
e857104bd183
Added reverse method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
87 back <- int32_t |
e857104bd183
Added reverse method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
88 tmpo <- object ptr |
e857104bd183
Added reverse method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
89 } andCode: { |
e857104bd183
Added reverse method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
90 front <- 0 |
e857104bd183
Added reverse method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
91 back <- size |
e857104bd183
Added reverse method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
92 while: { front < back } do: { |
e857104bd183
Added reverse method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
93 tmpo <- data get: front |
e857104bd183
Added reverse method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
94 data set: front (data get: back) |
e857104bd183
Added reverse method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
95 data set: back tmpo |
e857104bd183
Added reverse method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
96 front <- front + 1 |
e857104bd183
Added reverse method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
97 back <- back - 1 |
e857104bd183
Added reverse method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
98 } |
e857104bd183
Added reverse method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
99 self |
e857104bd183
Added reverse method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
100 } |
249
fd9005253861
Added resize method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
191
diff
changeset
|
101 |
84
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
102 llMessage: length withVars: { |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
103 intret <- obj_int32 ptr |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
104 } andCode: { |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
105 intret <- make_object: (addr_of: obj_int32_meta) NULL 0 |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
106 intret num!: size |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
107 intret |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
108 } |
144
547153211389
Fix fold:with foldr:with and map in the array module
Mike Pavone <pavone@retrodev.com>
parents:
84
diff
changeset
|
109 |
84
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
110 fold:with <- :acc :fun { |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
111 foreach: self :idx el { |
144
547153211389
Fix fold:with foldr:with and map in the array module
Mike Pavone <pavone@retrodev.com>
parents:
84
diff
changeset
|
112 acc <- fun: acc el |
84
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
113 } |
144
547153211389
Fix fold:with foldr:with and map in the array module
Mike Pavone <pavone@retrodev.com>
parents:
84
diff
changeset
|
114 acc |
84
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
115 } |
144
547153211389
Fix fold:with foldr:with and map in the array module
Mike Pavone <pavone@retrodev.com>
parents:
84
diff
changeset
|
116 |
84
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
117 foldr:with <- :acc :fun { |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
118 idx <- length - 1 |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
119 while: {idx >= 0} do: { |
144
547153211389
Fix fold:with foldr:with and map in the array module
Mike Pavone <pavone@retrodev.com>
parents:
84
diff
changeset
|
120 acc <- fun: acc (get: idx) |
323
eb5f1fca9b78
Fix infinite loop in foldr:with
Michael Pavone <pavone@retrodev.com>
parents:
322
diff
changeset
|
121 idx <- idx - 1 |
84
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
122 } |
144
547153211389
Fix fold:with foldr:with and map in the array module
Mike Pavone <pavone@retrodev.com>
parents:
84
diff
changeset
|
123 acc |
84
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
124 } |
144
547153211389
Fix fold:with foldr:with and map in the array module
Mike Pavone <pavone@retrodev.com>
parents:
84
diff
changeset
|
125 |
84
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
126 map <- :fun { |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
127 new <- #[] |
342
884cd5d54c0f
Bugfix to array find:withDefault and a small optimization to array map
Michael Pavone <pavone@retrodev.com>
parents:
329
diff
changeset
|
128 new resize: length |
84
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
129 foreach: self :idx el { |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
130 new append: (fun: el) |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
131 } |
144
547153211389
Fix fold:with foldr:with and map in the array module
Mike Pavone <pavone@retrodev.com>
parents:
84
diff
changeset
|
132 new |
84
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
133 } |
144
547153211389
Fix fold:with foldr:with and map in the array module
Mike Pavone <pavone@retrodev.com>
parents:
84
diff
changeset
|
134 |
260
56409de95f55
Untested implementation of filter for arrays
Michael Pavone <pavone@retrodev.com>
parents:
249
diff
changeset
|
135 filter <- :fun { |
56409de95f55
Untested implementation of filter for arrays
Michael Pavone <pavone@retrodev.com>
parents:
249
diff
changeset
|
136 new <- #[] |
56409de95f55
Untested implementation of filter for arrays
Michael Pavone <pavone@retrodev.com>
parents:
249
diff
changeset
|
137 foreach: self :idx el { |
56409de95f55
Untested implementation of filter for arrays
Michael Pavone <pavone@retrodev.com>
parents:
249
diff
changeset
|
138 if: (fun: el) { |
56409de95f55
Untested implementation of filter for arrays
Michael Pavone <pavone@retrodev.com>
parents:
249
diff
changeset
|
139 new append: el |
56409de95f55
Untested implementation of filter for arrays
Michael Pavone <pavone@retrodev.com>
parents:
249
diff
changeset
|
140 } |
56409de95f55
Untested implementation of filter for arrays
Michael Pavone <pavone@retrodev.com>
parents:
249
diff
changeset
|
141 } |
56409de95f55
Untested implementation of filter for arrays
Michael Pavone <pavone@retrodev.com>
parents:
249
diff
changeset
|
142 new |
56409de95f55
Untested implementation of filter for arrays
Michael Pavone <pavone@retrodev.com>
parents:
249
diff
changeset
|
143 } |
56409de95f55
Untested implementation of filter for arrays
Michael Pavone <pavone@retrodev.com>
parents:
249
diff
changeset
|
144 |
84
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
145 find:withDefault <- :pred :default{ |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
146 idx <- 0 |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
147 l <- length |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
148 ret <- default |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
149 while: {idx < l} do: { |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
150 v <- get: idx |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
151 if: (pred: v) { |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
152 ret <- #{ |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
153 key <- idx |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
154 value <- v |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
155 } |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
156 idx <- l |
342
884cd5d54c0f
Bugfix to array find:withDefault and a small optimization to array map
Michael Pavone <pavone@retrodev.com>
parents:
329
diff
changeset
|
157 } else: { |
884cd5d54c0f
Bugfix to array find:withDefault and a small optimization to array map
Michael Pavone <pavone@retrodev.com>
parents:
329
diff
changeset
|
158 idx <- idx + 1 |
84
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
159 } |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
160 } |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
161 ret |
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
162 } |
322
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
163 |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
164 sort <- { |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
165 n <- length |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
166 tmp <- #[] |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
167 tmp resize: n |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
168 while: { (tmp length) < n} do: { |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
169 tmp append: false |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
170 } |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
171 src <- self |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
172 dst <- tmp |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
173 |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
174 merge <- :lStart rStart rEnd { |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
175 dstIdx <- lStart |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
176 left <- lStart |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
177 right <- rStart |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
178 |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
179 while: { dstIdx < rEnd } do: { |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
180 if: left < rStart && (right >= rEnd || (src get: left) <= (src get: right)) { |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
181 dst set: dstIdx (src get: left) |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
182 left <- left + 1 |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
183 } else: { |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
184 dst set: dstIdx (src get: right) |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
185 right <- right + 1 |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
186 } |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
187 dstIdx <- dstIdx + 1 |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
188 } |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
189 } |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
190 |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
191 needsCopy? <- false |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
192 subSize <- 1 |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
193 while: { subSize < n} do: { |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
194 group <- subSize * 2 |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
195 i <- 0 |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
196 while: { i < n} do: { |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
197 right <- i + subSize |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
198 end <- i + group |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
199 if: right > n { |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
200 right <- n |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
201 end <- n |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
202 } else: { |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
203 if: end > n { |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
204 end <- n |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
205 } |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
206 } |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
207 merge: i right end |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
208 i <- i + group |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
209 } |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
210 tmp <- dst |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
211 dst <- src |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
212 src <- tmp |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
213 needsCopy? <- not: needsCopy? |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
214 |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
215 subSize <- subSize + subSize |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
216 } |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
217 if: needsCopy? { |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
218 foreach: src :index val { |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
219 self set: index val |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
220 } |
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
221 } |
342
884cd5d54c0f
Bugfix to array find:withDefault and a small optimization to array map
Michael Pavone <pavone@retrodev.com>
parents:
329
diff
changeset
|
222 self |
322
fb54a3af9c86
Add sort method to arrays
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
223 } |
184 | 224 |
225 join <- :sep { | |
226 if: length > 0 { | |
186
35d2cc193d99
Add string conversion inside array join so callers don't need to worry about doing string conversions themselves
Mike Pavone <pavone@retrodev.com>
parents:
184
diff
changeset
|
227 str <- string: (get: 0) |
184 | 228 idx <- 1 |
229 l <- length | |
230 while: { idx < l } do: { | |
231 str <- str . sep . (get: idx) | |
191
abde5d2918cf
Fix infinite loop in array join
Mike Pavone <pavone@retrodev.com>
parents:
186
diff
changeset
|
232 idx <- idx + 1 |
184 | 233 } |
234 str | |
235 } else: { | |
236 "" | |
237 } | |
238 } | |
271
bb4723fec05e
Support for encoding objects, dictionaries, lists and arrays to JSON in json module
Michael Pavone <pavone@retrodev.com>
parents:
260
diff
changeset
|
239 |
bb4723fec05e
Support for encoding objects, dictionaries, lists and arrays to JSON in json module
Michael Pavone <pavone@retrodev.com>
parents:
260
diff
changeset
|
240 jsonEncode <- { |
329
eef8a5cea812
Use a smarter algorithm for calculating module init order and break some circular module dependencies in the standard library
Michael Pavone <pavone@retrodev.com>
parents:
323
diff
changeset
|
241 parts <- map: :el { jsonEncoder encode: el } |
271
bb4723fec05e
Support for encoding objects, dictionaries, lists and arrays to JSON in json module
Michael Pavone <pavone@retrodev.com>
parents:
260
diff
changeset
|
242 "[" . (parts join: ",") . "]" |
bb4723fec05e
Support for encoding objects, dictionaries, lists and arrays to JSON in json module
Michael Pavone <pavone@retrodev.com>
parents:
260
diff
changeset
|
243 } |
84
9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
244 } |