]> gitweb.factorcode.org Git - factor.git/blob - basis/compiler/tree/propagation/call-effect/call-effect-tests.factor
Fix conflicts
[factor.git] / basis / compiler / tree / propagation / call-effect / call-effect-tests.factor
1 ! Copyright (C) 2009 Slava Pestov, Daniel Ehrenberg.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: compiler.tree.propagation.call-effect tools.test fry math effects kernel
4 compiler.tree.builder compiler.tree.optimizer compiler.tree.debugger sequences ;
5 IN: compiler.tree.propagation.call-effect.tests
6
7 [ t ] [ \ + (( a b -- c )) execute-effect-unsafe? ] unit-test
8 [ t ] [ \ + (( a b c -- d e )) execute-effect-unsafe? ] unit-test
9 [ f ] [ \ + (( a b c -- d )) execute-effect-unsafe? ] unit-test
10 [ f ] [ \ call (( x -- )) execute-effect-unsafe? ] unit-test
11
12 [ t ] [ [ + ] cached-effect (( a b -- c )) effect= ] unit-test
13 [ t ] [ 5 [ + ] curry cached-effect (( a -- c )) effect= ] unit-test
14 [ t ] [ 5 [ ] curry cached-effect (( -- c )) effect= ] unit-test
15 [ t ] [ [ dup ] [ drop ] compose cached-effect (( a -- b )) effect= ] unit-test
16 [ t ] [ [ drop ] [ dup ] compose cached-effect (( a b -- c d )) effect= ] unit-test
17 [ t ] [ [ 2drop ] [ dup ] compose cached-effect (( a b c -- d e )) effect= ] unit-test
18 [ t ] [ [ 1 2 3 ] [ 2drop ] compose cached-effect (( -- a )) effect= ] unit-test
19 [ t ] [ [ 1 2 ] [ 3drop ] compose cached-effect (( a -- )) effect= ] unit-test
20
21 : optimized-quot ( quot -- quot' )
22     build-tree optimize-tree nodes>quot ;
23
24 : compiled-call2 ( a quot: ( a -- b ) -- b )
25     call( a -- b ) ;
26
27 : compiled-execute2 ( a b word: ( a b -- c ) -- c )
28     execute( a b -- c ) ;
29
30 [ [ 3 ] ] [ [ 1 2 \ + execute( a b -- c ) ] optimized-quot ] unit-test
31 [ [ 3 ] ] [ [ 1 2 [ + ] call( a b -- c ) ] optimized-quot ] unit-test
32 [ [ 3 ] ] [ [ 1 2 '[ _ + ] call( a -- b ) ] optimized-quot ] unit-test
33 [ [ 3 ] ] [ [ 1 2 '[ _ ] [ + ] compose call( a -- b ) ] optimized-quot ] unit-test
34
35 [ 1 2 { [ + ] } first compiled-call2 ] must-fail
36 [ 3 ] [ 1 2 { + } first compiled-execute2 ] unit-test
37 [ 3 ] [ 1 2 '[ _ + ] compiled-call2 ] unit-test
38 [ 3 ] [ 1 2 '[ _ ] [ + ] compose compiled-call2 ] unit-test
39 [ 3 ] [ 1 2 \ + compiled-execute2 ] unit-test
40
41 [ 3 ] [ 1 2 { [ + ] } first call( a b -- c ) ] unit-test
42 [ 3 ] [ 1 2 { + } first execute( a b -- c ) ] unit-test
43 [ 3 ] [ 1 2 '[ _ + ] call( a -- b ) ] unit-test
44 [ 3 ] [ 1 2 '[ _ ] [ + ] compose call( a -- b ) ] unit-test
45
46 [ t ] [ [ 2 '[ _ ] [ + ] compose ] final-info first infer-value (( object -- object )) effect= ] unit-test
47 [ t ] [ [ 2 '[ _ ] 1 '[ _ + ] compose ] final-info first infer-value (( -- object )) effect= ] unit-test
48 [ t ] [ [ 2 '[ _ + ] ] final-info first infer-value (( object -- object )) effect= ] unit-test
49 [ f ] [ [ [ [ ] [ 1 ] if ] ] final-info first infer-value ] unit-test
50 [ t ] [ [ [ 1 ] '[ @ ] ] final-info first infer-value (( -- object )) effect= ] unit-test
51 [ f ] [ [ dup drop ] final-info first infer-value ] unit-test
52
53 ! This should not hang
54 [ ] [ [ [ dup call( quot -- ) ] dup call( quot -- ) ] final-info drop ] unit-test
55 [ ] [ [ [ dup curry call( quot -- ) ] dup curry call( quot -- ) ] final-info drop ] unit-test
56
57 ! This should get inlined, because the parameter to the curry is literal even though
58 ! [ boa ] by itself doesn't infer
59 TUPLE: a-tuple x ;
60
61 [ V{ a-tuple } ] [ [ a-tuple '[ _ boa ] call( x -- tuple ) ] final-classes ] unit-test