ranger-compiler 3.0.3 → 3.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -0
- package/README.md +1 -1
- package/dist/Lang.rgr +158 -9
- package/dist/lib/JSON.rgr +31 -4
- package/dist/lib/RangerProcess.rgr +273 -0
- package/dist/lib/stdlib.rgr +33 -3
- package/dist/package.json +1 -1
- package/dist/rgrc.js +1139 -47
- package/package.json +2 -2
- package/dist/lib/lib/ACEEditor.rgr +0 -5
- package/dist/lib/lib/Ajax.rgr +0 -196
- package/dist/lib/lib/CmdParams.rgr +0 -72
- package/dist/lib/lib/Crypto.rgr +0 -90
- package/dist/lib/lib/DOMLib.rgr +0 -307
- package/dist/lib/lib/Engine3D.rgr +0 -870
- package/dist/lib/lib/ImmutableVector.rgr +0 -364
- package/dist/lib/lib/IndexedDB.rgr +0 -32
- package/dist/lib/lib/JSON.rgr +0 -702
- package/dist/lib/lib/JinxProcess.rgr +0 -838
- package/dist/lib/lib/SQL.rgr +0 -44
- package/dist/lib/lib/ServiceLib.rgr +0 -9
- package/dist/lib/lib/Storage.rgr +0 -89
- package/dist/lib/lib/Time.rgr +0 -75
- package/dist/lib/lib/Timers.rgr +0 -176
- package/dist/lib/lib/TypedArrays.rgr +0 -14
- package/dist/lib/lib/ViewLib.rgr +0 -851
- package/dist/lib/lib/WebLib.rgr +0 -47
- package/dist/lib/lib/WebServerLib.rgr +0 -137
- package/dist/lib/lib/ranger-dir.rgr +0 -175
- package/dist/lib/lib/stdlib.rgr +0 -665
- package/dist/lib/lib/stdops.rgr +0 -168
package/dist/lib/lib/stdlib.rgr
DELETED
|
@@ -1,665 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
; union type operators
|
|
3
|
-
|
|
4
|
-
Import "stdops.rgr"
|
|
5
|
-
Import "JSON.rgr"
|
|
6
|
-
|
|
7
|
-
operators {
|
|
8
|
-
|
|
9
|
-
cast _:Any (arg:T target@(noeval):Any) {
|
|
10
|
-
templates {
|
|
11
|
-
go ( (e 1) )
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
case _@(newcontext):void ( arg@(union):T item2@(define):boolean code:block ) {
|
|
16
|
-
templates {
|
|
17
|
-
es6 (
|
|
18
|
-
(forkctx _ ) (def 2) "if( typeof(" (e 1) ") === 'boolean' ) /* union case for boolean */ {" nl I
|
|
19
|
-
"var " (e 2) " = " (e 1) ";" nl
|
|
20
|
-
(block 3)
|
|
21
|
-
nl i "}"
|
|
22
|
-
)
|
|
23
|
-
kotlin (
|
|
24
|
-
(forkctx _ ) (def 2) "if( " (e 1) " is Boolean ) /* union case for boolean */ {" nl I
|
|
25
|
-
"val " (e 2) " : Boolean = " (e 1) " as Boolean;" nl
|
|
26
|
-
(block 3)
|
|
27
|
-
nl i "}"
|
|
28
|
-
)
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
case _@(newcontext):void ( arg@(union):T item2@(define):int code:block ) {
|
|
32
|
-
templates {
|
|
33
|
-
es6 (
|
|
34
|
-
(forkctx _ ) (def 2) "if( " "Number.isInteger ? Number.isInteger(" (e 1) ") : (function(v) { return typeof v === 'number' && isFinite(v) && Math.floor(v) === v; })(" (e 1) ")" " ) /* union case for int */ {" nl I
|
|
35
|
-
"var " (e 2) " = " (e 1) ";" nl
|
|
36
|
-
(block 3)
|
|
37
|
-
nl i "}"
|
|
38
|
-
)
|
|
39
|
-
php (
|
|
40
|
-
(forkctx _ ) (def 2) "if( is_int(" (e 1) ") ) {" nl I
|
|
41
|
-
(e 2) " = " (e 1) ";" nl
|
|
42
|
-
(block 3)
|
|
43
|
-
nl i "}"
|
|
44
|
-
)
|
|
45
|
-
kotlin (
|
|
46
|
-
(forkctx _ ) (def 2) "if( " (e 1) " is Int ) /* union case for int */ {" nl I
|
|
47
|
-
"val " (e 2) " : Int = " (e 1) " as Int;" nl
|
|
48
|
-
(block 3)
|
|
49
|
-
nl i "}"
|
|
50
|
-
)
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
case _@(newcontext):void ( arg@(union):T item2@(define):double code:block ) {
|
|
54
|
-
templates {
|
|
55
|
-
es6 (
|
|
56
|
-
(forkctx _ ) (def 2) "if ( (function(v) { return typeof v === 'number' && isFinite(v); })(" (e 1) "))" " /* union case for double */ {" nl I
|
|
57
|
-
"var " (e 2) " = " (e 1) ";" nl
|
|
58
|
-
(block 3)
|
|
59
|
-
nl i "}"
|
|
60
|
-
)
|
|
61
|
-
php (
|
|
62
|
-
(forkctx _ ) (def 2) "if( is_double(" (e 1) ") ) {" nl I
|
|
63
|
-
(e 2) " = " (e 1) ";" nl
|
|
64
|
-
(block 3)
|
|
65
|
-
nl i "}"
|
|
66
|
-
)
|
|
67
|
-
kotlin (
|
|
68
|
-
(forkctx _ ) (def 2) "if( " (e 1) " is Double ) /* union case for double */ {" nl I
|
|
69
|
-
"val " (e 2) " : Double = " (e 1) " as Double;" nl
|
|
70
|
-
(block 3)
|
|
71
|
-
nl i "}"
|
|
72
|
-
)
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
case _@(newcontext):void ( arg@(union):T item2@(define):string code:block ) {
|
|
77
|
-
templates {
|
|
78
|
-
es6 (
|
|
79
|
-
(forkctx _ ) (def 2) "if( typeof(" (e 1) ") === 'string' ) /* union case for string */ {" nl I
|
|
80
|
-
"var " (e 2) " = " (e 1) ";" nl
|
|
81
|
-
(block 3)
|
|
82
|
-
nl i "}"
|
|
83
|
-
)
|
|
84
|
-
php (
|
|
85
|
-
(forkctx _ ) (def 2) "if( is_string(" (e 1) ") ) {" nl I
|
|
86
|
-
(e 2) " = " (e 1) ";" nl
|
|
87
|
-
(block 3)
|
|
88
|
-
nl i "}"
|
|
89
|
-
)
|
|
90
|
-
kotlin (
|
|
91
|
-
(forkctx _ ) (def 2) "if( " (e 1) " is String ) /* union case for string */ {" nl I
|
|
92
|
-
"val " (e 2) " : String = " (e 1) " as String;" nl
|
|
93
|
-
(block 3)
|
|
94
|
-
nl i "}"
|
|
95
|
-
)
|
|
96
|
-
ranger ( 'case ' (e 1) " " (e 2) ":" (typeof 2) " {" nl
|
|
97
|
-
I (block 3) i nl "}" nl
|
|
98
|
-
)
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
case _@(newcontext):void ( arg@(union):T item@(define):T code:block ) {
|
|
102
|
-
templates {
|
|
103
|
-
ranger ( "case " (e 1) " " (e 2) ":" (typeof 2) " {" nl
|
|
104
|
-
I (block 3) i nl "}" nl
|
|
105
|
-
)
|
|
106
|
-
php (
|
|
107
|
-
(forkctx _ ) (def 2) "if( is_object(" (e 1) ") && get_class(" (e 1) ") == \"" (typeof 2) "\" ) /* union case */ {" nl I
|
|
108
|
-
(e 2) " = " (e 1) ";" nl
|
|
109
|
-
(block 3)
|
|
110
|
-
nl i "}"
|
|
111
|
-
)
|
|
112
|
-
es6 (
|
|
113
|
-
(forkctx _ ) (def 2) "if( " (e 1) " instanceof " (typeof 2) " ) /* union case */ {" nl I
|
|
114
|
-
"var " (e 2) " = " (e 1) ";" nl
|
|
115
|
-
(block 3)
|
|
116
|
-
|
|
117
|
-
nl i "}"
|
|
118
|
-
)
|
|
119
|
-
go (
|
|
120
|
-
(forkctx _ ) (def 2) "switch " (e 1) ".(type) {" nl I
|
|
121
|
-
"case " (typeof 2) ":" nl
|
|
122
|
-
I nl
|
|
123
|
-
"var " (e 2) " " (typeof 2) " = " (e 1) ".(" (typeof 2) ");" nl
|
|
124
|
-
(block 3)
|
|
125
|
-
i nl
|
|
126
|
-
nl i "}"
|
|
127
|
-
)
|
|
128
|
-
csharp (
|
|
129
|
-
(forkctx _ ) (def 2) "if( " (e 1) " is " (typeof 2) " ) {" nl I
|
|
130
|
-
(typeof 2) " " (e 2) " = (" (typeof 2) ")" (e 1) ";" nl
|
|
131
|
-
(block 3)
|
|
132
|
-
nl i "}"
|
|
133
|
-
)
|
|
134
|
-
swift3 (
|
|
135
|
-
(forkctx _ ) (def 2) "if type(of: " (e 1) ") == " (typeof 2) ".self {" nl I
|
|
136
|
-
"let " (e 2) " = " (e 1) " as! " (typeof 2)";" nl
|
|
137
|
-
(block 3)
|
|
138
|
-
|
|
139
|
-
nl i "}"
|
|
140
|
-
)
|
|
141
|
-
java7 (
|
|
142
|
-
(forkctx _ ) (def 2) "if( " (e 1) " instanceof " (typeof 2) ") {" nl I
|
|
143
|
-
(typeof 2) " " (e 2) " = (" (typeof 2) ") " (e 1) ";" nl
|
|
144
|
-
(block 3)
|
|
145
|
-
|
|
146
|
-
nl i "}"
|
|
147
|
-
)
|
|
148
|
-
kotlin (
|
|
149
|
-
(forkctx _ ) (def 2) "if( " (e 1) " is " (typeof 2) " ) /* union case */ {" nl I
|
|
150
|
-
"val " (e 2) " : " (typeof 2) " = " (e 1) " as " (typeof 2) ";" nl
|
|
151
|
-
(block 3)
|
|
152
|
-
nl i "}"
|
|
153
|
-
)
|
|
154
|
-
cpp (
|
|
155
|
-
(forkctx _ ) (def 2) "if( mpark::holds_alternative<" (typeof 2) ">(" (e 1) ") ) {" nl I
|
|
156
|
-
(typeof 2) " " (e 2) " = mpark::get<" (typeof 2) ">(" (e 1) ");" nl
|
|
157
|
-
(block 3)
|
|
158
|
-
|
|
159
|
-
nl i "}"
|
|
160
|
-
|
|
161
|
-
(plugin 'makefile' ((dep 'variant.hpp' 'https://github.com/mpark/variant/releases/download/v1.2.2/variant.hpp')))
|
|
162
|
-
)
|
|
163
|
-
scala (
|
|
164
|
-
(forkctx _ ) (def 2) (e 1) " match {" nl
|
|
165
|
-
I "case " (e 2) " : " (typeof 2) " => {" nl I
|
|
166
|
-
(block 3)
|
|
167
|
-
nl i "}" nl
|
|
168
|
-
"case _ => {} " nl i
|
|
169
|
-
"}" nl
|
|
170
|
-
)
|
|
171
|
-
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
to _:T ( to@(union noeval):T item:T) {
|
|
175
|
-
templates {
|
|
176
|
-
cpp.disabled ( "(r_create_union<" (typeof 1) ", " (typeof 2)">(" (e 2) "))"
|
|
177
|
-
(create_polyfill
|
|
178
|
-
'
|
|
179
|
-
template<typename T, typename S>
|
|
180
|
-
T r_create_union (S value) {
|
|
181
|
-
T rv;
|
|
182
|
-
rv = value;
|
|
183
|
-
return rv;
|
|
184
|
-
};
|
|
185
|
-
'
|
|
186
|
-
)
|
|
187
|
-
)
|
|
188
|
-
* ( (e 2) )
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
operator type:[string:T] all {
|
|
195
|
-
fn forEach:void (cb:(_:void (item:T index:string )) ) {
|
|
196
|
-
def list (keys self)
|
|
197
|
-
for list kk:string i {
|
|
198
|
-
def value (unwrap (get self kk))
|
|
199
|
-
cb( value kk )
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
fn forKeys:void (cb:(_:void (index:string))) {
|
|
203
|
-
def list (keys self)
|
|
204
|
-
for list it:string i {
|
|
205
|
-
cb(it)
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
; commented out native ops, because they are not compatible with async operators
|
|
211
|
-
operator type:[T] all {
|
|
212
|
-
|
|
213
|
-
; pure function or operator could be simply inlined...
|
|
214
|
-
fn forEach@(pure):void (cb:(_:void (item:T index:int))) @doc('Call `fb` for each item in array') {
|
|
215
|
-
for self it:T i {
|
|
216
|
-
cb(it i)
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
fn has:boolen ( el:T) {
|
|
221
|
-
def idx (indexOf el)
|
|
222
|
-
return (idx >= 0)
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
fn map:[T] (cb:(_:T (item:T index:int))) {
|
|
226
|
-
def len (array_length self)
|
|
227
|
-
def res:[T]
|
|
228
|
-
for self it:T i {
|
|
229
|
-
push res (cb(it i))
|
|
230
|
-
}
|
|
231
|
-
return res
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
fn map:[S] (cb:(_:S (item:T index:int)) to@(noeval):[S] ) {
|
|
235
|
-
def len (array_length self)
|
|
236
|
-
def res:[S]
|
|
237
|
-
for self it:T i {
|
|
238
|
-
push res (cb(it i))
|
|
239
|
-
}
|
|
240
|
-
return res
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
fn filter:[T] (cb:(_:boolean (item:T index:int))) {
|
|
244
|
-
def res:[T]
|
|
245
|
-
for self it:T i {
|
|
246
|
-
if( cb(it i) ) {
|
|
247
|
-
push res it
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
return res
|
|
251
|
-
}
|
|
252
|
-
fn reduce@(weak):T (cb:(_:T (left:T right:T index:int)) initialValue:T) {
|
|
253
|
-
def len (array_length self)
|
|
254
|
-
def res:T initialValue
|
|
255
|
-
if( len >= 1 ) {
|
|
256
|
-
for self it:T i {
|
|
257
|
-
res = ( cb ( res it i))
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
return res
|
|
261
|
-
}
|
|
262
|
-
fn reduce@(weak):K (cb:(_:K (left:K right:T index:int)) initialValue:K) {
|
|
263
|
-
def len (array_length self)
|
|
264
|
-
def res initialValue
|
|
265
|
-
if( len >= 1 ) {
|
|
266
|
-
for self it:T i {
|
|
267
|
-
res = ( cb ( res it i ))
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
return res
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
fn groupBy:[T] ( cb:(_:string (item:T)) ) {
|
|
274
|
-
def res:[T]
|
|
275
|
-
def mapper:[string:boolean]
|
|
276
|
-
for self it:T i {
|
|
277
|
-
def key (cb(it))
|
|
278
|
-
if( false == ( has mapper key ) ) {
|
|
279
|
-
push res it
|
|
280
|
-
set mapper key true
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
return res
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
fn clone:[T] () {
|
|
287
|
-
def res:[T]
|
|
288
|
-
for self it:T i {
|
|
289
|
-
push res it
|
|
290
|
-
}
|
|
291
|
-
return res
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
; some useful functions from scala
|
|
296
|
-
fn find@(optional):T (cb:(_:boolean (item:T))) {
|
|
297
|
-
def res@(optional):T
|
|
298
|
-
for self it@(lives):T i {
|
|
299
|
-
if( cb(it) ) {
|
|
300
|
-
def res2@(optional):T
|
|
301
|
-
res2 = it
|
|
302
|
-
return res2
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
return res
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
fn count:int (cb:(_:boolean (item:T))) {
|
|
309
|
-
def res 0
|
|
310
|
-
for self it@(lives):T i {
|
|
311
|
-
if( cb(it) ) {
|
|
312
|
-
res = res + 1
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
return res
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
fn contains:boolean (cb:(_:boolean (item:T))) {
|
|
319
|
-
for self it@(lives):T i {
|
|
320
|
-
if( cb(it) ) {
|
|
321
|
-
return true
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
return false
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
; immutable map type
|
|
331
|
-
trait Map @params( K T S ) {
|
|
332
|
-
def elements@(weak):[K:T]
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
trait Vector @params( T S ) {
|
|
336
|
-
|
|
337
|
-
def start:int 0
|
|
338
|
-
def cardinality 3
|
|
339
|
-
def end:int 0
|
|
340
|
-
def elements@(weak):[T]
|
|
341
|
-
def parent@(weak):S
|
|
342
|
-
|
|
343
|
-
; inserting a new element inside the array
|
|
344
|
-
; you can re-use the arrays but the index ranges will change
|
|
345
|
-
|
|
346
|
-
fn localCopy:S () {
|
|
347
|
-
def obj (new S)
|
|
348
|
-
obj.start = start
|
|
349
|
-
obj.end = end
|
|
350
|
-
obj.parent = this.parent
|
|
351
|
-
obj.cardinality = cardinality
|
|
352
|
-
obj.elements = elements
|
|
353
|
-
return obj
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
fn set:S (idx:int item:T) {
|
|
357
|
-
|
|
358
|
-
if( idx >= start ) {
|
|
359
|
-
def res (this.localCopy())
|
|
360
|
-
res.elements = (make _:[T] (res.cardinality) item)
|
|
361
|
-
for elements e@(lives):T i {
|
|
362
|
-
if ( (res.start + i) != idx ) {
|
|
363
|
-
set res.elements i e
|
|
364
|
-
} {
|
|
365
|
-
set res.elements i item
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
return res
|
|
369
|
-
}
|
|
370
|
-
def root (this.localCopy())
|
|
371
|
-
def res root
|
|
372
|
-
|
|
373
|
-
def p@(weak):S parent
|
|
374
|
-
while( (!null? p) && (idx < p.start) ) {
|
|
375
|
-
def newSlice@(lives) (p.localCopy())
|
|
376
|
-
res.parent = newSlice
|
|
377
|
-
res = newSlice
|
|
378
|
-
if(!null? p.parent) {
|
|
379
|
-
p = p.parent
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
def newSlice@(lives) (p.localCopy())
|
|
383
|
-
newSlice.elements = (make _:[T] (newSlice.cardinality) item)
|
|
384
|
-
for p.elements e@(lives):T i {
|
|
385
|
-
set newSlice.elements i e
|
|
386
|
-
}
|
|
387
|
-
set newSlice.elements (idx - newSlice.start) item
|
|
388
|
-
res.parent = newSlice
|
|
389
|
-
return root
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
fn insert:S (idx:int item:T) {
|
|
393
|
-
if( idx >= start ) {
|
|
394
|
-
def res (this.localCopy())
|
|
395
|
-
def use_card cardinality
|
|
396
|
-
if( ( array_length res.elements) >= (use_card - 1) ) {
|
|
397
|
-
use_card = ( array_length res.elements) + 1
|
|
398
|
-
}
|
|
399
|
-
res.elements = (make _:[T] (use_card) item)
|
|
400
|
-
for elements e@(lives):T i {
|
|
401
|
-
if ( res.start + i < idx ) {
|
|
402
|
-
set res.elements i e
|
|
403
|
-
} {
|
|
404
|
-
if( idx == ( res.start + i )) {
|
|
405
|
-
set res.elements i item
|
|
406
|
-
set res.elements (i + 1) e
|
|
407
|
-
} {
|
|
408
|
-
set res.elements (i + 1) e
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
if( (idx - start) >= (array_length elements)) {
|
|
413
|
-
set res.elements (idx - start) item
|
|
414
|
-
}
|
|
415
|
-
res.start = start
|
|
416
|
-
res.end = end + 1
|
|
417
|
-
res.cardinality = use_card
|
|
418
|
-
return res
|
|
419
|
-
}
|
|
420
|
-
def root (this.localCopy())
|
|
421
|
-
def res root
|
|
422
|
-
res.start = start + 1
|
|
423
|
-
res.end = end + 1
|
|
424
|
-
def p@(weak):S parent
|
|
425
|
-
while( (!null? p) && (idx < p.start) ) {
|
|
426
|
-
def newSlice@(lives) (p.localCopy())
|
|
427
|
-
newSlice.start = newSlice.start + 1
|
|
428
|
-
newSlice.end = newSlice.end + 1
|
|
429
|
-
res.parent = newSlice
|
|
430
|
-
res = newSlice
|
|
431
|
-
if(!null? p.parent) {
|
|
432
|
-
p = p.parent
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
def newSlice@(lives) (p.localCopy())
|
|
437
|
-
def use_card newSlice.cardinality
|
|
438
|
-
if( ( array_length p.elements) >= (use_card - 1) ) {
|
|
439
|
-
use_card = ( array_length p.elements) + 1
|
|
440
|
-
}
|
|
441
|
-
newSlice.elements = (make _:[T] (use_card) item)
|
|
442
|
-
for p.elements e@(lives):T i {
|
|
443
|
-
if ( newSlice.start + i < idx ) {
|
|
444
|
-
set newSlice.elements i e
|
|
445
|
-
} {
|
|
446
|
-
if( idx == ( newSlice.start + i )) {
|
|
447
|
-
set newSlice.elements i item
|
|
448
|
-
set newSlice.elements (i + 1) e
|
|
449
|
-
} {
|
|
450
|
-
set newSlice.elements (i + 1) e
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
newSlice.end = newSlice.end + 1
|
|
456
|
-
newSlice.cardinality = use_card
|
|
457
|
-
if ( (idx - newSlice.start) >= p.cardinality ) {
|
|
458
|
-
newSlice.end = idx + 1
|
|
459
|
-
}
|
|
460
|
-
newSlice.parent = p.parent
|
|
461
|
-
res.parent = newSlice
|
|
462
|
-
return root
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
fn get:T (idx:int) {
|
|
466
|
-
if( idx < 0 ) {
|
|
467
|
-
; should be runtime error here...
|
|
468
|
-
return (itemAt elements 0)
|
|
469
|
-
}
|
|
470
|
-
if( idx >= start && idx < end ) {
|
|
471
|
-
return (itemAt elements (idx - start))
|
|
472
|
-
}
|
|
473
|
-
def p@(weak):S parent
|
|
474
|
-
while( (!null? p) && (idx < p.start) ) {
|
|
475
|
-
p = p.parent
|
|
476
|
-
}
|
|
477
|
-
if(!null? p ) {
|
|
478
|
-
return (itemAt p.elements (idx - p.start))
|
|
479
|
-
}
|
|
480
|
-
return (itemAt elements 0)
|
|
481
|
-
}
|
|
482
|
-
fn add:S (item:T) {
|
|
483
|
-
if((end - start) >= cardinality) {
|
|
484
|
-
def res (new S)
|
|
485
|
-
res.start = this.end
|
|
486
|
-
res.end = (this.end + 1)
|
|
487
|
-
res.parent = this
|
|
488
|
-
res.cardinality = (cardinality + 1)
|
|
489
|
-
res.elements = (make _:[T] (res.cardinality) item)
|
|
490
|
-
set res.elements 0 item
|
|
491
|
-
return res
|
|
492
|
-
}
|
|
493
|
-
def res (new S)
|
|
494
|
-
res.elements = (make _:[T] (cardinality) item)
|
|
495
|
-
for elements e@(lives):T i {
|
|
496
|
-
set res.elements i e
|
|
497
|
-
}
|
|
498
|
-
set res.elements (end - start) item
|
|
499
|
-
res.parent = parent
|
|
500
|
-
res.start = start
|
|
501
|
-
res.end = end + 1
|
|
502
|
-
res.cardinality = cardinality
|
|
503
|
-
return res
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
fn count:int () {
|
|
507
|
-
return end
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
; TODO: create faster version which uses (make ) operator
|
|
511
|
-
fn map:S (cb:(_:T (item:T)) ) {
|
|
512
|
-
def res:S (new S)
|
|
513
|
-
def cnt (this.count())
|
|
514
|
-
def i 0
|
|
515
|
-
while( i < cnt ) {
|
|
516
|
-
def item (this.get(i))
|
|
517
|
-
def new_value (cb(item))
|
|
518
|
-
res = (res.add(new_value))
|
|
519
|
-
i = i + 1
|
|
520
|
-
}
|
|
521
|
-
return res
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
operator type:Vector all {
|
|
527
|
-
|
|
528
|
-
; TODO: strict type checking for this
|
|
529
|
-
; fn for (iIndex@(ignore):T iteIndex@(ignore):int code:block ) (
|
|
530
|
-
; "def " (e 3) ":int 0" nl
|
|
531
|
-
; "def loop_cnt (" (e 1) ".count())" nl
|
|
532
|
-
; "while( " (e 3) " < loop_cnt ) {" nl
|
|
533
|
-
; I
|
|
534
|
-
; "def " (e 2) " (" (e 1) ".get(" (e 3) "))" nl
|
|
535
|
-
; (block 4)
|
|
536
|
-
; (e 3) " = " (e 3) " + 1" nl
|
|
537
|
-
; i
|
|
538
|
-
; "}" nl
|
|
539
|
-
; )
|
|
540
|
-
|
|
541
|
-
fn indexOf:int ( elem:T ) {
|
|
542
|
-
def cnt (self.count())
|
|
543
|
-
def i 0
|
|
544
|
-
while( i < cnt ) {
|
|
545
|
-
def item (itemAt self i)
|
|
546
|
-
if(item == elem) {
|
|
547
|
-
return i
|
|
548
|
-
}
|
|
549
|
-
i = i + 1
|
|
550
|
-
}
|
|
551
|
-
return -1
|
|
552
|
-
}
|
|
553
|
-
fn clear:T (idx:int) {
|
|
554
|
-
; def val (self.get(idx))
|
|
555
|
-
return (new T)
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
fn itemAt:T (idx:int) {
|
|
559
|
-
def val (self.get(idx))
|
|
560
|
-
return val
|
|
561
|
-
}
|
|
562
|
-
fn at:T (idx:int) {
|
|
563
|
-
def val (self.get(idx))
|
|
564
|
-
return val
|
|
565
|
-
}
|
|
566
|
-
fn push:S (item:T) {
|
|
567
|
-
return (self.add(item))
|
|
568
|
-
}
|
|
569
|
-
fn last:T () {
|
|
570
|
-
return (itemAt self ((self.count()) - 1) )
|
|
571
|
-
}
|
|
572
|
-
fn array_length:int () {
|
|
573
|
-
return (self.count())
|
|
574
|
-
}
|
|
575
|
-
fn length:int () {
|
|
576
|
-
return (self.count())
|
|
577
|
-
}
|
|
578
|
-
fn size:int () {
|
|
579
|
-
return (self.count())
|
|
580
|
-
}
|
|
581
|
-
fn forEach:void (cb:(_:void (item:T))) {
|
|
582
|
-
def cnt (self.count())
|
|
583
|
-
def i 0
|
|
584
|
-
while( i < cnt ) {
|
|
585
|
-
def item (itemAt self i)
|
|
586
|
-
cb(item)
|
|
587
|
-
i = i + 1
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
fn forUntil:void (cb:(_:boolean (item:T))) {
|
|
592
|
-
def cnt (self.count())
|
|
593
|
-
def i 0
|
|
594
|
-
while( i < cnt ) {
|
|
595
|
-
def item (itemAt self i)
|
|
596
|
-
if( (cb(item)) == false ) {
|
|
597
|
-
return
|
|
598
|
-
}
|
|
599
|
-
i = i + 1
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
fn map:S ( cb:(_:T (item:T)) ) {
|
|
604
|
-
def res (new S)
|
|
605
|
-
def cnt (self.count())
|
|
606
|
-
def i 0
|
|
607
|
-
while( i < cnt ) {
|
|
608
|
-
def item (itemAt self i)
|
|
609
|
-
def value (cb(item))
|
|
610
|
-
res = res.add(value)
|
|
611
|
-
i = i + 1
|
|
612
|
-
}
|
|
613
|
-
return res
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
; TODO: faster version ....
|
|
617
|
-
fn map:[K] (cb:(_:K (item:T)) to@(noeval):[K] ) {
|
|
618
|
-
def res:[K]
|
|
619
|
-
def cnt (self.count())
|
|
620
|
-
def i 0
|
|
621
|
-
while( i < cnt ) {
|
|
622
|
-
def item (itemAt self i)
|
|
623
|
-
push res (cb(item))
|
|
624
|
-
i = i + 1
|
|
625
|
-
}
|
|
626
|
-
return res
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
operator type:Map all {
|
|
633
|
-
fn keys:[K] () {
|
|
634
|
-
return (keys self.elements)
|
|
635
|
-
}
|
|
636
|
-
fn get@(optional):T (key:K) {
|
|
637
|
-
return (get self.elements key)
|
|
638
|
-
}
|
|
639
|
-
fn has:boolean (key:K) {
|
|
640
|
-
return (has self.elements key)
|
|
641
|
-
}
|
|
642
|
-
fn set:S (key:K value:T) {
|
|
643
|
-
def c (new S)
|
|
644
|
-
def keys ( keys self.elements)
|
|
645
|
-
for keys k:string i {
|
|
646
|
-
if(k==key) {
|
|
647
|
-
|
|
648
|
-
} {
|
|
649
|
-
set c.elements k (unwrap (get self.elements k))
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
set c.elements key value
|
|
653
|
-
return c
|
|
654
|
-
}
|
|
655
|
-
fn forEach@(weak):S ( cb:(_:void (item:T index:K)) ) {
|
|
656
|
-
def keys (keys self.elements)
|
|
657
|
-
for keys key:K i {
|
|
658
|
-
cb( (unwrap (get self.elements key)) key )
|
|
659
|
-
}
|
|
660
|
-
return self
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
}
|
|
664
|
-
|
|
665
|
-
|