1 USING: tools.test kernel.private kernel arrays sequences
2 math.private math generic words quotations alien alien.c-types
3 strings sbufs sequences.private slots.private combinators
4 definitions system layouts vectors math.partial-dispatch
5 math.order math.functions accessors hashtables classes assocs
6 io.encodings.utf8 io.encodings.ascii io.encodings fry slots
7 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 ;
19 IN: compiler.tree.cleanup.tests
21 [ t ] [ [ [ 1 ] [ 2 ] if ] cleaned-up-tree [ #if? ] contains-node? ] unit-test
23 [ f ] [ [ f [ 1 ] [ 2 ] if ] cleaned-up-tree [ #if? ] contains-node? ] unit-test
25 [ f ] [ [ { array } declare [ 1 ] [ 2 ] if ] cleaned-up-tree [ #if? ] contains-node? ] unit-test
27 [ t ] [ [ { sequence } declare [ 1 ] [ 2 ] if ] cleaned-up-tree [ #if? ] contains-node? ] unit-test
29 : recursive-test ( a -- b ) dup [ not recursive-test ] when ; inline recursive
31 [ t ] [ [ recursive-test ] cleaned-up-tree [ #recursive? ] contains-node? ] unit-test
33 [ f ] [ [ f recursive-test ] cleaned-up-tree [ #recursive? ] contains-node? ] unit-test
35 [ t ] [ [ t recursive-test ] cleaned-up-tree [ #recursive? ] contains-node? ] unit-test
38 [ { integer } declare >fixnum ]
42 GENERIC: mynot ( x -- y )
44 M: f mynot drop t ; inline
46 M: object mynot drop f ; inline
48 GENERIC: detect-f ( x -- y )
50 M: f detect-f ; inline
53 [ dup [ mynot ] [ ] if detect-f ] \ detect-f inlined?
56 GENERIC: xyz ( n -- n )
58 M: integer xyz ; inline
60 M: object xyz ; inline
63 [ { integer } declare xyz ] \ xyz inlined?
67 [ dup fixnum? [ xyz ] [ drop "hi" ] if ]
71 : (fx-repeat) ( i n quot: ( i -- i ) -- )
75 [ swap [ call 1 fixnum+fast ] dip ] keep (fx-repeat)
76 ] if ; inline recursive
78 : fx-repeat ( n quot -- )
79 0 -rot (fx-repeat) ; inline
81 ! The + should be optimized into fixnum+, if it was not, then
82 ! the type of the loop index was not inferred correctly
84 [ [ dup 2 + drop ] fx-repeat ] \ + inlined?
87 : (i-repeat) ( i n quot: ( i -- i ) -- )
88 2over dup xyz drop >= [
91 [ swap [ call 1 + ] dip ] keep (i-repeat)
92 ] if ; inline recursive
94 : i-repeat ( n quot -- ) [ { integer } declare ] dip 0 -rot (i-repeat) ; inline
97 [ [ dup xyz drop ] i-repeat ] \ xyz inlined?
101 [ { fixnum } declare dup 100 >= [ 1 + ] unless ] \ fixnum+ inlined?
105 [ { fixnum fixnum } declare dupd < [ 1 + 1 + ] when ]
110 [ { fixnum fixnum } declare dupd < [ 1 + 1 + ] when ]
115 [ { fixnum } declare [ ] times ] \ >= inlined?
119 [ { fixnum } declare [ ] times ] \ + inlined?
123 [ { fixnum } declare [ ] times ] \ fixnum+ inlined?
127 [ { integer fixnum } declare dupd < [ 1 + ] when ]
132 [ { integer fixnum } declare dupd < [ 1 + ] when ]
133 \ +-integer-fixnum inlined?
139 [ 1array dup quotation? [ >quotation ] unless ] times
140 ] \ quotation? inlined?
145 1000000000000000000000000000000000 [ ] times
150 1000000000000000000000000000000000 [ ] times
151 ] \ +-integer-fixnum inlined?
155 [ { bignum } declare [ ] times ]
156 \ +-integer-fixnum inlined?
160 [ { array-capacity } declare 0 < ] \ < inlined?
164 [ { array-capacity } declare 0 < ] \ fixnum< inlined?
168 [ { array-capacity } declare 1 fixnum- ] \ fixnum- inlined?
171 GENERIC: annotate-entry-test-1 ( x -- )
173 M: fixnum annotate-entry-test-1 drop ;
175 : (annotate-entry-test-2) ( from to -- )
179 [ dup annotate-entry-test-1 1 + ] dip (annotate-entry-test-2)
180 ] if ; inline recursive
182 : annotate-entry-test-2 ( from to -- obj ) 0 -rot (annotate-entry-test-2) ; inline
185 [ { bignum } declare annotate-entry-test-2 ]
186 \ annotate-entry-test-1 inlined?
190 [ { float } declare 10 [ 2.3 * ] times >float ]
194 GENERIC: detect-float ( a -- b )
196 M: float detect-float ;
199 [ { real float } declare + detect-float ]
200 \ detect-float inlined?
204 [ { float real } declare + detect-float ]
205 \ detect-float inlined?
209 [ { fixnum fixnum } declare 7 bitand neg shift ]
210 \ fixnum-shift-fast inlined?
214 [ { fixnum fixnum } declare 7 bitand neg shift ]
215 { shift fixnum-shift } inlined?
219 [ { fixnum fixnum } declare 1 swap 7 bitand shift ]
220 { shift fixnum-shift } inlined?
224 [ { fixnum fixnum } declare 1 swap 7 bitand shift ]
225 { fixnum-shift-fast } inlined?
229 [ 1 swap 7 bitand shift ]
230 { shift fixnum-shift } inlined?
235 [ { fixnum fixnum } declare 1 swap 31 bitand shift ]
240 [ { fixnum fixnum } declare 1 swap 31 bitand shift ]
241 \ fixnum-shift inlined?
246 [ B{ 1 0 } *short 0 number= ]
251 [ B{ 1 0 } *short 0 { number number } declare number= ]
256 [ B{ 1 0 } *short 0 = ]
261 [ B{ 1 0 } *short dup number? [ 0 number= ] [ drop f ] if ]
266 [ HEX: ff bitand 0 HEX: ff between? ]
271 [ HEX: ff swap HEX: ff bitand >= ]
276 [ { vector } declare nth-unsafe ] \ nth-unsafe inlined?
292 dup 0 > [ 1 - rec ] when ; inline recursive
295 [ { fixnum } declare rec 1 + ]
300 dup 2 < [ drop 1 ] [ dup 1 - fib swap 2 - fib + ] if ; inline recursive
303 [ 27.0 fib ] { < - + } inlined?
307 [ 27.0 fib ] { +-integer-integer } inlined?
311 [ 27 fib ] { < - + } inlined?
315 [ 27 >bignum fib ] { < - + } inlined?
319 [ 27/2 fib ] { < - } inlined?
323 [ { fixnum } declare 10 [ -1 shift ] times ] \ shift inlined?
327 [ { integer } declare 10 [ -1 shift ] times ] \ shift inlined?
331 [ { fixnum } declare 1048575 fixnum-bitand 524288 fixnum- ]
332 \ fixnum-bitand inlined?
336 [ { fixnum } declare [ drop ] each-integer ]
337 { < <-integer-fixnum +-integer-fixnum + } inlined?
341 [ { fixnum } declare length [ drop ] each-integer ]
342 { < <-integer-fixnum +-integer-fixnum + } inlined?
346 [ { fixnum } declare [ drop ] each ]
347 { < <-integer-fixnum +-integer-fixnum + } inlined?
351 [ { fixnum } declare 0 [ + ] reduce ]
352 { < <-integer-fixnum nth-unsafe } inlined?
356 [ { fixnum } declare 0 [ + ] reduce ]
357 \ +-integer-fixnum inlined?
362 { integer } declare [ ] map
368 { integer } declare { } set-nth-unsafe
374 { integer } declare 1 + { } set-nth-unsafe
380 { array } declare length
381 1 + dup 100 fixnum> [ 1 fixnum+ ] when
386 [ [ resize-array ] keep length ] \ length inlined?
390 [ dup 0 > [ sqrt ] when ] \ sqrt inlined?
394 [ { utf8 } declare decode-char ] \ decode-char inlined?
398 [ { ascii } declare decode-char ] \ decode-char inlined?
401 [ t ] [ [ { 1 2 } length ] { length length>> slot } inlined? ] unit-test
405 { integer } declare [ 0 >= ] map
406 ] { >= fixnum>= } inlined?
411 4 pick array-capacity?
412 [ set-slot ] [ \ array-capacity 2nip bad-slot-value ] if
413 ] cleaned-up-tree drop
417 [ { merge } declare accum>> 0 >>length ] cleaned-up-tree drop
423 [ dupd dup -1 < [ 0 >= [ ] [ "X" throw ] if ] [ drop ] if ]
425 ] cleaned-up-tree drop
429 [ [ 2array ] [ 0 3array ] if first ]
430 { nth-unsafe < <= > >= } inlined?
434 [ [ [ "A" throw ] dip ] [ "B" throw ] if ]
438 ! Regression from benchmark.nsieve
439 : chicken-fingers ( i seq -- )
444 ] if ; inline recursive
446 : buffalo-wings ( i seq -- )
449 [ 1 + ] dip buffalo-wings
452 ] if ; inline recursive
455 [ 2 swap >fixnum buffalo-wings ]
456 { <-integer-fixnum +-integer-fixnum } inlined?
460 : buffalo-sauce ( -- value ) f ;
463 buffalo-sauce [ steak ] when ; inline recursive
471 ] if ; inline recursive
474 [ 2 swap >fixnum ribs ]
475 { <-integer-fixnum +-integer-fixnum } inlined?
479 [ hashtable new ] \ new inlined?
483 [ { array-capacity } declare 1 fixnum+ ] cleaned-up-tree
484 [ { [ #call? ] [ node-input-infos second literal>> 1 = ] } 1&& ] any?
488 [ { null } declare [ 1 ] [ 2 ] if ]
489 build-tree normalize propagate cleanup check-nodes
493 [ { array } declare 2 <groups> [ . . ] assoc-each ]
494 \ nth-unsafe inlined?
498 [ { fixnum fixnum } declare = ]
499 \ both-fixnums? inlined?
503 [ { integer integer } declare + drop ]
504 { + +-integer-integer } inlined?
524 ] cleaned-up-tree nodes>quot