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 ;
20 IN: compiler.tree.cleanup.tests
22 [ t ] [ [ [ 1 ] [ 2 ] if ] cleaned-up-tree [ #if? ] contains-node? ] unit-test
24 [ f ] [ [ f [ 1 ] [ 2 ] if ] cleaned-up-tree [ #if? ] contains-node? ] unit-test
26 [ f ] [ [ { array } declare [ 1 ] [ 2 ] if ] cleaned-up-tree [ #if? ] contains-node? ] unit-test
28 [ t ] [ [ { sequence } declare [ 1 ] [ 2 ] if ] cleaned-up-tree [ #if? ] contains-node? ] unit-test
30 : recursive-test ( a -- b ) dup [ not recursive-test ] when ; inline recursive
32 [ t ] [ [ recursive-test ] cleaned-up-tree [ #recursive? ] contains-node? ] unit-test
34 [ f ] [ [ f recursive-test ] cleaned-up-tree [ #recursive? ] contains-node? ] unit-test
36 [ t ] [ [ t recursive-test ] cleaned-up-tree [ #recursive? ] contains-node? ] unit-test
39 [ { integer } declare >fixnum ]
43 GENERIC: mynot ( x -- y )
45 M: f mynot drop t ; inline
47 M: object mynot drop f ; inline
49 GENERIC: detect-f ( x -- y )
51 M: f detect-f ; inline
54 [ dup [ mynot ] [ ] if detect-f ] \ detect-f inlined?
57 GENERIC: xyz ( n -- n )
59 M: integer xyz ; inline
61 M: object xyz ; inline
64 [ { integer } declare xyz ] \ xyz inlined?
68 [ dup fixnum? [ xyz ] [ drop "hi" ] if ]
72 : (fx-repeat) ( i n quot: ( i -- i ) -- )
76 [ swap [ call 1 fixnum+fast ] dip ] keep (fx-repeat)
77 ] if ; inline recursive
79 : fx-repeat ( n quot -- )
80 0 -rot (fx-repeat) ; inline
82 ! The + should be optimized into fixnum+, if it was not, then
83 ! the type of the loop index was not inferred correctly
85 [ [ dup 2 + drop ] fx-repeat ] \ + inlined?
88 : (i-repeat) ( i n quot: ( i -- i ) -- )
89 2over dup xyz drop >= [
92 [ swap [ call 1 + ] dip ] keep (i-repeat)
93 ] if ; inline recursive
95 : i-repeat ( n quot -- ) [ { integer } declare ] dip 0 -rot (i-repeat) ; inline
98 [ [ dup xyz drop ] i-repeat ] \ xyz inlined?
102 [ { fixnum } declare dup 100 >= [ 1 + ] unless ] \ fixnum+ inlined?
106 [ { fixnum fixnum } declare dupd < [ 1 + 1 + ] when ]
111 [ { fixnum fixnum } declare dupd < [ 1 + 1 + ] when ]
116 [ { fixnum } declare [ ] times ] \ >= inlined?
120 [ { fixnum } declare [ ] times ] \ + inlined?
124 [ { fixnum } declare [ ] times ] \ fixnum+ inlined?
128 [ { integer fixnum } declare dupd < [ 1 + ] when ]
133 [ { integer fixnum } declare dupd < [ 1 + ] when ]
134 \ +-integer-fixnum inlined?
140 [ 1array dup quotation? [ >quotation ] unless ] times
141 ] \ quotation? inlined?
146 1000000000000000000000000000000000 [ ] times
151 1000000000000000000000000000000000 [ ] times
152 ] \ +-integer-fixnum inlined?
156 [ { bignum } declare [ ] times ]
157 \ +-integer-fixnum inlined?
161 [ { array-capacity } declare 0 < ] \ < inlined?
165 [ { array-capacity } declare 0 < ] \ fixnum< inlined?
169 [ { array-capacity } declare 1 fixnum- ] \ fixnum- inlined?
172 GENERIC: annotate-entry-test-1 ( x -- )
174 M: fixnum annotate-entry-test-1 drop ;
176 : (annotate-entry-test-2) ( from to -- )
180 [ dup annotate-entry-test-1 1 + ] dip (annotate-entry-test-2)
181 ] if ; inline recursive
183 : annotate-entry-test-2 ( from to -- obj ) 0 -rot (annotate-entry-test-2) ; inline
186 [ { bignum } declare annotate-entry-test-2 ]
187 \ annotate-entry-test-1 inlined?
191 [ { float } declare 10 [ 2.3 * ] times >float ]
195 GENERIC: detect-float ( a -- b )
197 M: float detect-float ;
200 [ { real float } declare + detect-float ]
201 \ detect-float inlined?
205 [ { float real } declare + detect-float ]
206 \ detect-float inlined?
210 [ { fixnum fixnum } declare 7 bitand neg shift ]
211 \ fixnum-shift-fast inlined?
215 [ { fixnum fixnum } declare 7 bitand neg shift ]
216 { shift fixnum-shift } inlined?
220 [ { fixnum fixnum } declare 1 swap 7 bitand shift ]
221 { shift fixnum-shift } inlined?
225 [ { fixnum fixnum } declare 1 swap 7 bitand shift ]
226 { fixnum-shift-fast } inlined?
230 [ 1 swap 7 bitand shift ]
231 { shift fixnum-shift } inlined?
236 [ { fixnum fixnum } declare 1 swap 31 bitand shift ]
241 [ { fixnum fixnum } declare 1 swap 31 bitand shift ]
242 \ fixnum-shift inlined?
247 [ B{ 1 0 } *short 0 number= ]
252 [ B{ 1 0 } *short 0 { number number } declare number= ]
257 [ B{ 1 0 } *short 0 = ]
262 [ B{ 1 0 } *short dup number? [ 0 number= ] [ drop f ] if ]
267 [ HEX: ff bitand 0 HEX: ff between? ]
272 [ HEX: ff swap HEX: ff bitand >= ]
277 [ { vector } declare nth-unsafe ] \ nth-unsafe inlined?
293 dup 0 > [ 1 - rec ] when ; inline recursive
296 [ { fixnum } declare rec 1 + ]
301 dup 2 < [ drop 1 ] [ dup 1 - fib swap 2 - fib + ] if ; inline recursive
304 [ 27.0 fib ] { < - + } inlined?
308 [ 27.0 fib ] { +-integer-integer } inlined?
312 [ 27 fib ] { < - + } inlined?
316 [ 27 >bignum fib ] { < - + } inlined?
320 [ 27/2 fib ] { < - } inlined?
324 [ { fixnum } declare 10 [ -1 shift ] times ] \ shift inlined?
328 [ { integer } declare 10 [ -1 shift ] times ] \ shift inlined?
332 [ { fixnum } declare 1048575 fixnum-bitand 524288 fixnum- ]
333 \ fixnum-bitand inlined?
337 [ { fixnum } declare [ drop ] each-integer ]
338 { < <-integer-fixnum +-integer-fixnum + } inlined?
342 [ { fixnum } declare length [ drop ] each-integer ]
343 { < <-integer-fixnum +-integer-fixnum + } inlined?
347 [ { fixnum } declare [ drop ] each ]
348 { < <-integer-fixnum +-integer-fixnum + } inlined?
352 [ { fixnum } declare 0 [ + ] reduce ]
353 { < <-integer-fixnum nth-unsafe } inlined?
357 [ { fixnum } declare 0 [ + ] reduce ]
358 \ +-integer-fixnum inlined?
363 { integer } declare [ ] map
369 { integer } declare { } set-nth-unsafe
375 { integer } declare 1 + { } set-nth-unsafe
381 { array } declare length
382 1 + dup 100 fixnum> [ 1 fixnum+ ] when
387 [ [ resize-array ] keep length ] \ length inlined?
391 [ dup 0 > [ sqrt ] when ] \ sqrt inlined?
395 [ { utf8 } declare decode-char ] \ decode-char inlined?
399 [ { ascii } declare decode-char ] \ decode-char inlined?
402 [ t ] [ [ { 1 2 } length ] { length length>> slot } inlined? ] unit-test
406 { integer } declare [ 0 >= ] map
407 ] { >= fixnum>= } inlined?
412 4 pick array-capacity?
413 [ set-slot ] [ \ array-capacity 2nip bad-slot-value ] if
414 ] cleaned-up-tree drop
418 [ { merge } declare accum>> 0 >>length ] cleaned-up-tree drop
424 [ dupd dup -1 < [ 0 >= [ ] [ "X" throw ] if ] [ drop ] if ]
426 ] cleaned-up-tree drop
430 [ [ 2array ] [ 0 3array ] if first ]
431 { nth-unsafe < <= > >= } inlined?
435 [ [ [ "A" throw ] dip ] [ "B" throw ] if ]
439 ! Regression from benchmark.nsieve
440 : chicken-fingers ( i seq -- )
445 ] if ; inline recursive
447 : buffalo-wings ( i seq -- )
450 [ 1 + ] dip buffalo-wings
453 ] if ; inline recursive
456 [ 2 swap >fixnum buffalo-wings ]
457 { <-integer-fixnum +-integer-fixnum } inlined?
461 : buffalo-sauce ( -- value ) f ;
464 buffalo-sauce [ steak ] when ; inline recursive
472 ] if ; inline recursive
475 [ 2 swap >fixnum ribs ]
476 { <-integer-fixnum +-integer-fixnum } inlined?
480 [ hashtable new ] \ new inlined?
484 [ { array-capacity } declare 1 fixnum+ ] cleaned-up-tree
485 [ { [ #call? ] [ node-input-infos second literal>> 1 = ] } 1&& ] any?
489 [ { null } declare [ 1 ] [ 2 ] if ]
490 build-tree normalize propagate cleanup check-nodes
494 [ { array } declare 2 <groups> [ . . ] assoc-each ]
495 \ nth-unsafe inlined?
499 [ { fixnum fixnum } declare = ]
500 \ both-fixnums? inlined?
504 [ { integer integer } declare + drop ]
505 { + +-integer-integer } inlined?
525 ] cleaned-up-tree nodes>quot