| 
									
										
										
										
											2009-07-14 02:12:45 -04:00
										 |  |  | ! Copyright (C) 2009 Slava Pestov, Daniel Ehrenberg. | 
					
						
							|  |  |  | ! See http://factorcode.org/license.txt for BSD license. | 
					
						
							|  |  |  | USING: compiler.tree.propagation.call-effect tools.test fry math effects kernel | 
					
						
							| 
									
										
										
										
											2009-11-12 17:09:07 -05:00
										 |  |  | compiler.tree.builder compiler.tree.optimizer compiler.tree.debugger sequences | 
					
						
							|  |  |  | eval combinators ;
 | 
					
						
							| 
									
										
										
										
											2009-07-14 02:12:45 -04:00
										 |  |  | IN: compiler.tree.propagation.call-effect.tests | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-18 16:18:42 -04:00
										 |  |  | [ t ] [ \ + ( a b -- c ) execute-effect-unsafe? ] unit-test | 
					
						
							|  |  |  | [ t ] [ \ + ( a b c -- d e ) execute-effect-unsafe? ] unit-test | 
					
						
							|  |  |  | [ f ] [ \ + ( a b c -- d ) execute-effect-unsafe? ] unit-test | 
					
						
							|  |  |  | [ f ] [ \ call ( x -- ) execute-effect-unsafe? ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ t ] [ [ + ] cached-effect ( a b -- c ) effect= ] unit-test | 
					
						
							|  |  |  | [ t ] [ 5 [ + ] curry cached-effect ( a -- c ) effect= ] unit-test | 
					
						
							|  |  |  | [ t ] [ 5 [ ] curry cached-effect ( -- c ) effect= ] unit-test | 
					
						
							|  |  |  | [ t ] [ [ dup ] [ drop ] compose cached-effect ( a -- b ) effect= ] unit-test | 
					
						
							|  |  |  | [ t ] [ [ drop ] [ dup ] compose cached-effect ( a b -- c d ) effect= ] unit-test | 
					
						
							|  |  |  | [ t ] [ [ 2drop ] [ dup ] compose cached-effect ( a b c -- d e ) effect= ] unit-test | 
					
						
							|  |  |  | [ t ] [ [ 1 2 3 ] [ 2drop ] compose cached-effect ( -- a ) effect= ] unit-test | 
					
						
							|  |  |  | [ t ] [ [ 1 2 ] [ 3drop ] compose cached-effect ( a -- ) effect= ] unit-test | 
					
						
							| 
									
										
										
										
											2009-07-14 02:12:45 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : optimized-quot ( quot -- quot' )
 | 
					
						
							|  |  |  |     build-tree optimize-tree nodes>quot ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : compiled-call2 ( a quot: ( a -- b ) -- b )
 | 
					
						
							|  |  |  |     call( a -- b ) ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : compiled-execute2 ( a b word: ( a b -- c ) -- c )
 | 
					
						
							|  |  |  |     execute( a b -- c ) ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ [ 3 ] ] [ [ 1 2 \ + execute( a b -- c ) ] optimized-quot ] unit-test | 
					
						
							|  |  |  | [ [ 3 ] ] [ [ 1 2 [ + ] call( a b -- c ) ] optimized-quot ] unit-test | 
					
						
							|  |  |  | [ [ 3 ] ] [ [ 1 2 '[ _ + ] call( a -- b ) ] optimized-quot ] unit-test | 
					
						
							|  |  |  | [ [ 3 ] ] [ [ 1 2 '[ _ ] [ + ] compose call( a -- b ) ] optimized-quot ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ 1 2 { [ + ] } first compiled-call2 ] must-fail | 
					
						
							|  |  |  | [ 3 ] [ 1 2 { + } first compiled-execute2 ] unit-test | 
					
						
							|  |  |  | [ 3 ] [ 1 2 '[ _ + ] compiled-call2 ] unit-test | 
					
						
							|  |  |  | [ 3 ] [ 1 2 '[ _ ] [ + ] compose compiled-call2 ] unit-test | 
					
						
							|  |  |  | [ 3 ] [ 1 2 \ + compiled-execute2 ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ 3 ] [ 1 2 { [ + ] } first call( a b -- c ) ] unit-test | 
					
						
							|  |  |  | [ 3 ] [ 1 2 { + } first execute( a b -- c ) ] unit-test | 
					
						
							|  |  |  | [ 3 ] [ 1 2 '[ _ + ] call( a -- b ) ] unit-test | 
					
						
							|  |  |  | [ 3 ] [ 1 2 '[ _ ] [ + ] compose call( a -- b ) ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-18 16:18:42 -04:00
										 |  |  | [ t ] [ [ 2 '[ _ ] [ + ] compose ] final-info first infer-value ( object -- object ) effect= ] unit-test | 
					
						
							|  |  |  | [ t ] [ [ 2 '[ _ ] 1 '[ _ + ] compose ] final-info first infer-value ( -- object ) effect= ] unit-test | 
					
						
							|  |  |  | [ t ] [ [ 2 '[ _ + ] ] final-info first infer-value ( object -- object ) effect= ] unit-test | 
					
						
							| 
									
										
										
										
											2009-07-14 02:12:45 -04:00
										 |  |  | [ f ] [ [ [ [ ] [ 1 ] if ] ] final-info first infer-value ] unit-test | 
					
						
							| 
									
										
										
										
											2011-10-18 16:18:42 -04:00
										 |  |  | [ t ] [ [ [ 1 ] '[ @ ] ] final-info first infer-value ( -- object ) effect= ] unit-test | 
					
						
							| 
									
										
										
										
											2009-07-14 02:12:45 -04:00
										 |  |  | [ f ] [ [ dup drop ] final-info first infer-value ] unit-test | 
					
						
							| 
									
										
										
										
											2009-08-02 00:34:14 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | ! This should not hang | 
					
						
							|  |  |  | [ ] [ [ [ dup call( quot -- ) ] dup call( quot -- ) ] final-info drop ] unit-test | 
					
						
							| 
									
										
										
										
											2009-09-07 18:45:03 -04:00
										 |  |  | [ ] [ [ [ dup curry call( quot -- ) ] dup curry call( quot -- ) ] final-info drop ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ! This should get inlined, because the parameter to the curry is literal even though | 
					
						
							|  |  |  | ! [ boa ] by itself doesn't infer | 
					
						
							|  |  |  | TUPLE: a-tuple x ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-12 17:09:07 -05:00
										 |  |  | [ V{ a-tuple } ] [ [ a-tuple '[ _ boa ] call( x -- tuple ) ] final-classes ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ! See if redefinitions are handled correctly | 
					
						
							|  |  |  | : call(-redefine-test ( a -- b ) 1 + ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : test-quotatation ( -- quot ) [ call(-redefine-test ] ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-18 16:18:42 -04:00
										 |  |  | [ t ] [ test-quotatation cached-effect ( a -- b ) effect<= ] unit-test | 
					
						
							| 
									
										
										
										
											2009-11-12 17:09:07 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | [ ] [ "IN: compiler.tree.propagation.call-effect.tests USE: math : call(-redefine-test ( a b -- c ) + ;" eval( -- ) ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-18 16:18:42 -04:00
										 |  |  | [ t ] [ test-quotatation cached-effect ( a b -- c ) effect<= ] unit-test | 
					
						
							| 
									
										
										
										
											2009-11-12 17:09:07 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : inline-cache-invalidation-test ( a b c -- c ) call( a b -- c ) ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ 4 ] [ 1 3 test-quotatation inline-cache-invalidation-test ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ ] [ "IN: compiler.tree.propagation.call-effect.tests USE: math : call(-redefine-test ( a -- c ) 1 + ;" eval( -- ) ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-18 16:18:42 -04:00
										 |  |  | [ 1 3 test-quotatation inline-cache-invalidation-test ] [ T{ wrong-values f [ call(-redefine-test ] ( a b -- c ) } = ] must-fail-with | 
					
						
							| 
									
										
										
										
											2010-01-29 03:53:14 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | ! See if redefining a tuple class bumps effect counter | 
					
						
							|  |  |  | TUPLE: my-tuple a b c ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : my-quot ( -- quot ) [ my-tuple boa ] ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : my-word ( a b c q -- result ) call( a b c -- result ) ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ T{ my-tuple f 1 2 3 } ] [ 1 2 3 my-quot my-word ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ ] [ "IN: compiler.tree.propagation.call-effect.tests TUPLE: my-tuple a b ;" eval( -- ) ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ 1 2 3 my-quot my-word ] [ wrong-values? ] must-fail-with |