| 
									
										
										
										
											2008-07-20 05:24:37 -04:00
										 |  |  | USING: accessors namespaces assocs kernel sequences math | 
					
						
							|  |  |  | tools.test words sets combinators.short-circuit | 
					
						
							| 
									
										
										
										
											2008-07-24 00:50:21 -04:00
										 |  |  | stack-checker.state compiler.tree compiler.tree.builder | 
					
						
							| 
									
										
										
										
											2008-09-12 06:17:27 -04:00
										 |  |  | compiler.tree.recursive compiler.tree.normalization | 
					
						
							|  |  |  | compiler.tree.propagation compiler.tree.cleanup | 
					
						
							|  |  |  | compiler.tree.def-use arrays kernel.private sorting math.order | 
					
						
							|  |  |  | binary-search compiler.tree.checker ;
 | 
					
						
							| 
									
										
										
										
											2008-07-20 05:24:37 -04:00
										 |  |  | IN: compiler.tree.def-use.tests | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ t ] [ | 
					
						
							| 
									
										
										
										
											2008-07-24 00:50:21 -04:00
										 |  |  |     [ 1 2 3 ] build-tree compute-def-use drop
 | 
					
						
							| 
									
										
										
										
											2008-07-20 05:24:37 -04:00
										 |  |  |     def-use get { | 
					
						
							|  |  |  |         [ assoc-size 3 = ] | 
					
						
							|  |  |  |         [ values [ uses>> [ #return? ] all? ] all? ] | 
					
						
							|  |  |  |     } 1&& | 
					
						
							|  |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-10 00:00:27 -04:00
										 |  |  | : test-def-use ( quot -- )
 | 
					
						
							|  |  |  |     build-tree | 
					
						
							| 
									
										
										
										
											2008-09-12 06:17:27 -04:00
										 |  |  |     analyze-recursive | 
					
						
							| 
									
										
										
										
											2008-08-10 00:00:27 -04:00
										 |  |  |     normalize | 
					
						
							|  |  |  |     propagate | 
					
						
							| 
									
										
										
										
											2015-06-06 02:18:43 -04:00
										 |  |  |     cleanup-tree | 
					
						
							| 
									
										
										
										
											2008-08-10 00:00:27 -04:00
										 |  |  |     compute-def-use | 
					
						
							|  |  |  |     check-nodes ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 23:07:59 -04:00
										 |  |  | : too-deep ( a b -- c )
 | 
					
						
							|  |  |  |     dup [ drop ] [ 2dup too-deep too-deep drop ] if ; inline recursive
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-12 06:17:27 -04:00
										 |  |  | [ ] [ | 
					
						
							|  |  |  |     [ too-deep ] | 
					
						
							|  |  |  |     build-tree | 
					
						
							|  |  |  |     analyze-recursive | 
					
						
							|  |  |  |     normalize | 
					
						
							|  |  |  |     compute-def-use | 
					
						
							|  |  |  |     check-nodes | 
					
						
							|  |  |  | ] unit-test | 
					
						
							| 
									
										
										
										
											2008-08-22 23:07:59 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-10 00:00:27 -04:00
										 |  |  | ! compute-def-use checks for SSA violations, so we use that to | 
					
						
							|  |  |  | ! ensure we generate some common patterns correctly. | 
					
						
							| 
									
										
										
										
											2008-07-20 05:24:37 -04:00
										 |  |  | { | 
					
						
							|  |  |  |     [ [ drop ] each-integer ] | 
					
						
							|  |  |  |     [ [ 2drop ] curry each-integer ] | 
					
						
							|  |  |  |     [ [ 1 ] [ 2 ] if drop ] | 
					
						
							|  |  |  |     [ [ 1 ] [ dup ] if ] | 
					
						
							|  |  |  |     [ [ 1 ] [ dup ] if drop ] | 
					
						
							|  |  |  |     [ { array } declare swap ] | 
					
						
							|  |  |  |     [ [ ] curry call ] | 
					
						
							|  |  |  |     [ [ 1 ] [ 2 ] compose call + ] | 
					
						
							|  |  |  |     [ [ 1 ] 2 [ + ] curry compose call + ] | 
					
						
							|  |  |  |     [ [ 1 ] [ call 2 ] curry call + ] | 
					
						
							|  |  |  |     [ [ 1 ] [ 2 ] compose swap [ 1 ] [ 2 ] if + * ] | 
					
						
							| 
									
										
										
										
											2008-08-10 00:00:27 -04:00
										 |  |  |     [ dup slice? [ dup array? [ ] [ ] if ] [ ] if ] | 
					
						
							|  |  |  |     [ dup [ drop f ] [ "A" throw ] if ] | 
					
						
							|  |  |  |     [ [ <=> ] sort ] | 
					
						
							|  |  |  |     [ [ <=> ] with search ] | 
					
						
							| 
									
										
										
										
											2008-07-20 05:24:37 -04:00
										 |  |  | } [ | 
					
						
							| 
									
										
										
										
											2008-08-10 00:00:27 -04:00
										 |  |  |     [ ] swap [ test-def-use ] curry unit-test | 
					
						
							| 
									
										
										
										
											2008-07-20 05:24:37 -04:00
										 |  |  | ] each
 |