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?
142 [ 1array dup quotation? [ >quotation ] unless ] times
143 ] \ quotation? inlined?
148 1000000000000000000000000000000000 [ ] times
153 1000000000000000000000000000000000 [ ] times
154 ] \ +-integer-fixnum inlined?
158 [ { bignum } declare [ ] times ]
159 \ +-integer-fixnum inlined?
163 [ { array-capacity } declare 0 < ] \ < inlined?
167 [ { array-capacity } declare 0 < ] \ fixnum< inlined?
171 [ { array-capacity } declare 1 fixnum- ] \ fixnum- inlined?
175 [ 5000 [ 5000 [ ] times ] times ] \ 1+ inlined?
179 [ 5000 [ [ ] times ] each ] \ 1+ inlined?
183 [ 5000 0 [ dup 2 - swap [ 2drop ] curry each ] reduce ]
187 GENERIC: annotate-entry-test-1 ( x -- )
189 M: fixnum annotate-entry-test-1 drop ;
191 : (annotate-entry-test-2) ( from to -- )
195 [ dup annotate-entry-test-1 1+ ] dip (annotate-entry-test-2)
196 ] if ; inline recursive
198 : annotate-entry-test-2 ( from to -- obj ) 0 -rot (annotate-entry-test-2) ; inline
201 [ { bignum } declare annotate-entry-test-2 ]
202 \ annotate-entry-test-1 inlined?
206 [ { float } declare 10 [ 2.3 * ] times >float ]
210 GENERIC: detect-float ( a -- b )
212 M: float detect-float ;
215 [ { real float } declare + detect-float ]
216 \ detect-float inlined?
220 [ { float real } declare + detect-float ]
221 \ detect-float inlined?
225 [ { fixnum fixnum } declare 7 bitand neg shift ]
226 \ fixnum-shift-fast inlined?
230 [ { fixnum fixnum } declare 7 bitand neg shift ]
231 { shift fixnum-shift } inlined?
235 [ { fixnum fixnum } declare 1 swap 7 bitand shift ]
236 { shift fixnum-shift } inlined?
240 [ { fixnum fixnum } declare 1 swap 7 bitand shift ]
241 { fixnum-shift-fast } inlined?
246 [ { fixnum fixnum } declare 1 swap 31 bitand shift ]
251 [ { fixnum fixnum } declare 1 swap 31 bitand shift ]
252 \ fixnum-shift inlined?
257 [ B{ 1 0 } *short 0 number= ]
262 [ B{ 1 0 } *short 0 { number number } declare number= ]
267 [ B{ 1 0 } *short 0 = ]
272 [ B{ 1 0 } *short dup number? [ 0 number= ] [ drop f ] if ]
277 [ HEX: ff bitand 0 HEX: ff between? ]
282 [ HEX: ff swap HEX: ff bitand >= ]
287 [ { vector } declare nth-unsafe ] \ nth-unsafe inlined?
303 [ 1000 iota [ 1+ ] map ] { 1+ fixnum+ } inlined?
307 dup 0 > [ 1 - rec ] when ; inline recursive
310 [ { fixnum } declare rec 1 + ]
315 dup 2 < [ drop 1 ] [ dup 1 - fib swap 2 - fib + ] if ; inline recursive
318 [ 27.0 fib ] { < - + } inlined?
322 [ 27.0 fib ] { +-integer-integer } inlined?
326 [ 27 fib ] { < - + } inlined?
330 [ 27 >bignum fib ] { < - + } inlined?
334 [ 27/2 fib ] { < - } inlined?
338 [ { fixnum } declare 10 [ -1 shift ] times ] \ shift inlined?
342 [ { integer } declare 10 [ -1 shift ] times ] \ shift inlined?
346 [ { fixnum } declare 1048575 fixnum-bitand 524288 fixnum- ]
347 \ fixnum-bitand inlined?
351 [ { fixnum } declare [ drop ] each-integer ]
352 { < <-integer-fixnum +-integer-fixnum + } inlined?
356 [ { fixnum } declare length [ drop ] each-integer ]
357 { < <-integer-fixnum +-integer-fixnum + } inlined?
361 [ { fixnum } declare [ drop ] each ]
362 { < <-integer-fixnum +-integer-fixnum + } inlined?
366 [ { fixnum } declare 0 [ + ] reduce ]
367 { < <-integer-fixnum nth-unsafe } inlined?
371 [ { fixnum } declare 0 [ + ] reduce ]
372 \ +-integer-fixnum inlined?
377 { integer } declare [ ] map
383 { integer } declare { } set-nth-unsafe
389 { integer } declare 1 + { } set-nth-unsafe
395 { array } declare length
396 1 + dup 100 fixnum> [ 1 fixnum+ ] when
401 [ [ resize-array ] keep length ] \ length inlined?
405 [ dup 0 > [ sqrt ] when ] \ sqrt inlined?
409 [ { utf8 } declare decode-char ] \ decode-char inlined?
413 [ { ascii } declare decode-char ] \ decode-char inlined?
416 [ t ] [ [ { 1 2 } length ] { length length>> slot } inlined? ] unit-test
420 { integer } declare [ 0 >= ] map
421 ] { >= fixnum>= } inlined?
426 4 pick array-capacity?
427 [ set-slot ] [ \ array-capacity 2nip bad-slot-value ] if
428 ] cleaned-up-tree drop
432 [ { merge } declare accum>> 0 >>length ] cleaned-up-tree drop
438 [ dupd dup -1 < [ 0 >= [ ] [ "X" throw ] if ] [ drop ] if ]
440 ] cleaned-up-tree drop
444 [ [ 2array ] [ 0 3array ] if first ]
445 { nth-unsafe < <= > >= } inlined?
449 [ [ [ "A" throw ] dip ] [ "B" throw ] if ]
453 ! Regression from benchmark.nsieve
454 : chicken-fingers ( i seq -- )
459 ] if ; inline recursive
461 : buffalo-wings ( i seq -- )
464 [ 1+ ] dip buffalo-wings
467 ] if ; inline recursive
470 [ 2 swap >fixnum buffalo-wings ]
471 { <-integer-fixnum +-integer-fixnum } inlined?
475 : buffalo-sauce ( -- value ) f ;
478 buffalo-sauce [ steak ] when ; inline recursive
486 ] if ; inline recursive
489 [ 2 swap >fixnum ribs ]
490 { <-integer-fixnum +-integer-fixnum } inlined?
494 [ hashtable new ] \ new inlined?
498 [ { array-capacity } declare 1 fixnum+ ] cleaned-up-tree
499 [ { [ #call? ] [ node-input-infos second literal>> 1 = ] } 1&& ] any?
503 [ { null } declare [ 1 ] [ 2 ] if ]
504 build-tree normalize propagate cleanup check-nodes
508 [ { array } declare 2 <groups> [ . . ] assoc-each ]
509 \ nth-unsafe inlined?
513 [ { fixnum fixnum } declare = ]
514 \ both-fixnums? inlined?
518 [ { integer integer } declare + drop ]
519 { + +-integer-integer } inlined?