1 IN: compiler.tree.cleanup.tests
2 USING: tools.test kernel.private kernel arrays sequences
3 math.private math generic words quotations alien alien.c-types
4 strings sbufs sequences.private slots.private combinators
5 definitions system layouts vectors math.partial-dispatch
6 math.order math.functions accessors hashtables classes assocs
7 io.encodings.utf8 io.encodings.ascii io.encodings fry slots
8 sorting.private combinators.short-circuit grouping prettyprint
10 compiler.tree.combinators
13 compiler.tree.recursive
14 compiler.tree.normalization
15 compiler.tree.propagation
16 compiler.tree.propagation.info
18 compiler.tree.debugger ;
20 [ t ] [ [ [ 1 ] [ 2 ] if ] cleaned-up-tree [ #if? ] contains-node? ] unit-test
22 [ f ] [ [ f [ 1 ] [ 2 ] if ] cleaned-up-tree [ #if? ] contains-node? ] unit-test
24 [ f ] [ [ { array } declare [ 1 ] [ 2 ] if ] cleaned-up-tree [ #if? ] contains-node? ] unit-test
26 [ t ] [ [ { sequence } declare [ 1 ] [ 2 ] if ] cleaned-up-tree [ #if? ] contains-node? ] unit-test
28 : recursive-test ( a -- b ) dup [ not recursive-test ] when ; inline recursive
30 [ t ] [ [ recursive-test ] cleaned-up-tree [ #recursive? ] contains-node? ] unit-test
32 [ f ] [ [ f recursive-test ] cleaned-up-tree [ #recursive? ] contains-node? ] unit-test
34 [ t ] [ [ t recursive-test ] cleaned-up-tree [ #recursive? ] contains-node? ] unit-test
37 [ { integer } declare >fixnum ]
41 GENERIC: mynot ( x -- y )
45 M: object mynot drop f ;
47 GENERIC: detect-f ( x -- y )
52 [ dup [ mynot ] [ ] if detect-f ] \ detect-f inlined?
55 GENERIC: xyz ( n -- n )
62 [ { integer } declare xyz ] \ xyz inlined?
66 [ dup fixnum? [ xyz ] [ drop "hi" ] if ]
70 : (fx-repeat) ( i n quot: ( i -- i ) -- )
74 [ swap [ call 1 fixnum+fast ] dip ] keep (fx-repeat)
75 ] if ; inline recursive
77 : fx-repeat ( n quot -- )
78 0 -rot (fx-repeat) ; inline
80 ! The + should be optimized into fixnum+, if it was not, then
81 ! the type of the loop index was not inferred correctly
83 [ [ dup 2 + drop ] fx-repeat ] \ + inlined?
86 : (i-repeat) ( i n quot: ( i -- i ) -- )
87 2over dup xyz drop >= [
90 [ swap [ call 1+ ] dip ] keep (i-repeat)
91 ] if ; inline recursive
93 : i-repeat ( n quot -- ) [ { integer } declare ] dip 0 -rot (i-repeat) ; inline
96 [ [ dup xyz drop ] i-repeat ] \ xyz inlined?
100 [ { fixnum } declare dup 100 >= [ 1 + ] unless ] \ fixnum+ inlined?
104 [ { fixnum fixnum } declare dupd < [ 1 + 1 + ] when ]
109 [ { fixnum fixnum } declare dupd < [ 1 + 1 + ] when ]
114 [ { fixnum } declare [ ] times ] \ >= inlined?
118 [ { fixnum } declare [ ] times ] \ 1+ inlined?
122 [ { fixnum } declare [ ] times ] \ + inlined?
126 [ { fixnum } declare [ ] times ] \ fixnum+ inlined?
130 [ { integer fixnum } declare dupd < [ 1 + ] when ]
135 [ { integer fixnum } declare dupd < [ 1 + ] when ]
136 \ +-integer-fixnum inlined?
139 [ f ] [ [ dup 0 < [ neg ] when ] \ - inlined? ] unit-test
144 [ 1array dup quotation? [ >quotation ] unless ] times
145 ] \ quotation? inlined?
150 1000000000000000000000000000000000 [ ] times
155 1000000000000000000000000000000000 [ ] times
156 ] \ +-integer-fixnum inlined?
160 [ { bignum } declare [ ] times ]
161 \ +-integer-fixnum inlined?
165 [ { array-capacity } declare 0 < ] \ < inlined?
169 [ { array-capacity } declare 0 < ] \ fixnum< inlined?
173 [ { array-capacity } declare 1 fixnum- ] \ fixnum- inlined?
177 [ 5000 [ 5000 [ ] times ] times ] \ 1+ inlined?
181 [ 5000 [ [ ] times ] each ] \ 1+ inlined?
185 [ 5000 0 [ dup 2 - swap [ 2drop ] curry each ] reduce ]
189 GENERIC: annotate-entry-test-1 ( x -- )
191 M: fixnum annotate-entry-test-1 drop ;
193 : (annotate-entry-test-2) ( from to -- )
197 [ dup annotate-entry-test-1 1+ ] dip (annotate-entry-test-2)
198 ] if ; inline recursive
200 : annotate-entry-test-2 ( from to -- obj ) 0 -rot (annotate-entry-test-2) ; inline
203 [ { bignum } declare annotate-entry-test-2 ]
204 \ annotate-entry-test-1 inlined?
208 [ { float } declare 10 [ 2.3 * ] times >float ]
212 GENERIC: detect-float ( a -- b )
214 M: float detect-float ;
217 [ { real float } declare + detect-float ]
218 \ detect-float inlined?
222 [ { float real } declare + detect-float ]
223 \ detect-float inlined?
227 [ { fixnum fixnum } declare 7 bitand neg shift ]
228 \ fixnum-shift-fast inlined?
232 [ { fixnum fixnum } declare 7 bitand neg shift ]
233 { shift fixnum-shift } inlined?
237 [ { fixnum fixnum } declare 1 swap 7 bitand shift ]
238 { shift fixnum-shift } inlined?
242 [ { fixnum fixnum } declare 1 swap 7 bitand shift ]
243 { fixnum-shift-fast } inlined?
248 [ { fixnum fixnum } declare 1 swap 31 bitand shift ]
253 [ { fixnum fixnum } declare 1 swap 31 bitand shift ]
254 \ fixnum-shift inlined?
259 [ B{ 1 0 } *short 0 number= ]
264 [ B{ 1 0 } *short 0 { number number } declare number= ]
269 [ B{ 1 0 } *short 0 = ]
274 [ B{ 1 0 } *short dup number? [ 0 number= ] [ drop f ] if ]
279 [ HEX: ff bitand 0 HEX: ff between? ]
284 [ HEX: ff swap HEX: ff bitand >= ]
289 [ { vector } declare nth-unsafe ] \ nth-unsafe inlined?
305 [ 1000 iota [ 1+ ] map ] { 1+ fixnum+ } inlined?
309 dup 0 > [ 1 - rec ] when ; inline recursive
312 [ { fixnum } declare rec 1 + ]
317 dup 2 < [ drop 1 ] [ dup 1 - fib swap 2 - fib + ] if ; inline recursive
320 [ 27.0 fib ] { < - + } inlined?
324 [ 27.0 fib ] { +-integer-integer } inlined?
328 [ 27 fib ] { < - + } inlined?
332 [ 27 >bignum fib ] { < - + } inlined?
336 [ 27/2 fib ] { < - } inlined?
340 [ { fixnum } declare 10 [ -1 shift ] times ] \ shift inlined?
344 [ { integer } declare 10 [ -1 shift ] times ] \ shift inlined?
348 [ { fixnum } declare 1048575 fixnum-bitand 524288 fixnum- ]
349 \ fixnum-bitand inlined?
353 [ { fixnum } declare [ drop ] each-integer ]
354 { < <-integer-fixnum +-integer-fixnum + } inlined?
358 [ { fixnum } declare length [ drop ] each-integer ]
359 { < <-integer-fixnum +-integer-fixnum + } inlined?
363 [ { fixnum } declare [ drop ] each ]
364 { < <-integer-fixnum +-integer-fixnum + } inlined?
368 [ { fixnum } declare 0 [ + ] reduce ]
369 { < <-integer-fixnum nth-unsafe } inlined?
373 [ { fixnum } declare 0 [ + ] reduce ]
374 \ +-integer-fixnum inlined?
379 { integer } declare [ ] map
385 { integer } declare { } set-nth-unsafe
391 { integer } declare 1 + { } set-nth-unsafe
397 { array } declare length
398 1 + dup 100 fixnum> [ 1 fixnum+ ] when
403 [ [ resize-array ] keep length ] \ length inlined?
407 [ dup 0 > [ sqrt ] when ] \ sqrt inlined?
411 [ { utf8 } declare decode-char ] \ decode-char inlined?
415 [ { ascii } declare decode-char ] \ decode-char inlined?
418 [ t ] [ [ { 1 2 } length ] { length length>> slot } inlined? ] unit-test
422 { integer } declare [ 0 >= ] map
423 ] { >= fixnum>= } inlined?
428 4 pick array-capacity?
429 [ set-slot ] [ \ array-capacity 2nip bad-slot-value ] if
430 ] cleaned-up-tree drop
434 [ { merge } declare accum>> 0 >>length ] cleaned-up-tree drop
440 [ dupd dup -1 < [ 0 >= [ ] [ "X" throw ] if ] [ drop ] if ]
442 ] cleaned-up-tree drop
446 [ [ 2array ] [ 0 3array ] if first ]
447 { nth-unsafe < <= > >= } inlined?
451 [ [ [ "A" throw ] dip ] [ "B" throw ] if ]
455 ! Regression from benchmark.nsieve
456 : chicken-fingers ( i seq -- )
461 ] if ; inline recursive
463 : buffalo-wings ( i seq -- )
466 [ 1+ ] dip buffalo-wings
469 ] if ; inline recursive
472 [ 2 swap >fixnum buffalo-wings ]
473 { <-integer-fixnum +-integer-fixnum } inlined?
477 : buffalo-sauce ( -- value ) f ;
480 buffalo-sauce [ steak ] when ; inline recursive
488 ] if ; inline recursive
491 [ 2 swap >fixnum ribs ]
492 { <-integer-fixnum +-integer-fixnum } inlined?
496 [ hashtable new ] \ new inlined?
500 [ { array-capacity } declare 1 fixnum+ ] cleaned-up-tree
501 [ { [ #call? ] [ node-input-infos second literal>> 1 = ] } 1&& ] any?
505 [ { null } declare [ 1 ] [ 2 ] if ]
506 build-tree normalize propagate cleanup check-nodes
510 [ { array } declare 2 <groups> [ . . ] assoc-each ]
511 \ nth-unsafe inlined?
515 [ { fixnum fixnum } declare = ]
516 \ both-fixnums? inlined?
520 [ { integer integer } declare + drop ]
521 { + +-integer-integer } inlined?