| 
									
										
										
										
											2008-08-08 14:14:36 -04:00
										 |  |  | IN: compiler.tree.tuple-unboxing.tests | 
					
						
							| 
									
										
										
										
											2008-08-10 00:00:27 -04:00
										 |  |  | USING: tools.test compiler.tree.tuple-unboxing compiler.tree | 
					
						
							| 
									
										
										
										
											2008-09-12 06:17:27 -04:00
										 |  |  | compiler.tree.builder compiler.tree.recursive | 
					
						
							|  |  |  | compiler.tree.normalization compiler.tree.propagation | 
					
						
							|  |  |  | compiler.tree.cleanup compiler.tree.escape-analysis | 
					
						
							|  |  |  | compiler.tree.tuple-unboxing compiler.tree.checker | 
					
						
							|  |  |  | compiler.tree.def-use kernel accessors sequences math | 
					
						
							|  |  |  | math.private sorting math.order binary-search sequences.private | 
					
						
							|  |  |  | slots.private ;
 | 
					
						
							| 
									
										
										
										
											2008-08-08 14:14:36 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | \ unbox-tuples must-infer | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : test-unboxing ( quot -- )
 | 
					
						
							|  |  |  |     build-tree | 
					
						
							| 
									
										
										
										
											2008-09-12 06:17:27 -04:00
										 |  |  |     analyze-recursive | 
					
						
							| 
									
										
										
										
											2008-08-08 14:14:36 -04:00
										 |  |  |     normalize | 
					
						
							|  |  |  |     propagate | 
					
						
							|  |  |  |     cleanup
 | 
					
						
							|  |  |  |     escape-analysis | 
					
						
							|  |  |  |     unbox-tuples | 
					
						
							| 
									
										
										
										
											2008-08-10 00:00:27 -04:00
										 |  |  |     check-nodes ;
 | 
					
						
							| 
									
										
										
										
											2008-08-08 14:14:36 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | TUPLE: cons { car read-only } { cdr read-only } ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TUPLE: empty-tuple ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2008-08-08 17:04:33 -04:00
										 |  |  |     [ 1 2 cons boa [ car>> ] [ cdr>> ] bi ] | 
					
						
							| 
									
										
										
										
											2008-08-08 14:14:36 -04:00
										 |  |  |     [ empty-tuple boa drop ] | 
					
						
							|  |  |  |     [ cons boa [ car>> ] [ cdr>> ] bi ] | 
					
						
							|  |  |  |     [ [ 1 cons boa ] [ 2 cons boa ] if car>> ] | 
					
						
							|  |  |  |     [ dup cons boa 10 [ nip dup cons boa ] each-integer car>> ] | 
					
						
							| 
									
										
										
										
											2008-08-10 00:00:27 -04:00
										 |  |  |     [ 2 cons boa { [ ] [ ] } dispatch ] | 
					
						
							|  |  |  |     [ dup [ drop f ] [ "A" throw ] if ] | 
					
						
							| 
									
										
										
										
											2008-09-03 04:46:56 -04:00
										 |  |  |     [ [ ] [ ] curry curry dup 2 slot swap 3 slot dup 2 slot swap 3 slot drop ] | 
					
						
							| 
									
										
										
										
											2008-08-10 00:00:27 -04:00
										 |  |  |     [ [ ] [ ] curry curry call ] | 
					
						
							|  |  |  |     [ <complex> <complex> dup 1 slot drop 2 slot drop ] | 
					
						
							|  |  |  |     [ 1 cons boa over [ "A" throw ] when car>> ] | 
					
						
							| 
									
										
										
										
											2008-08-08 17:04:33 -04:00
										 |  |  |     [ [ <=> ] sort ] | 
					
						
							|  |  |  |     [ [ <=> ] with search ] | 
					
						
							| 
									
										
										
										
											2008-08-08 14:14:36 -04:00
										 |  |  | } [ [ ] swap [ test-unboxing ] curry unit-test ] each
 | 
					
						
							| 
									
										
										
										
											2008-08-18 16:47:49 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | ! A more complicated example | 
					
						
							|  |  |  | : impeach-node ( quot: ( node -- ) -- )
 | 
					
						
							|  |  |  |     dup slip impeach-node ; inline recursive
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : bleach-node ( quot: ( node -- ) -- )
 | 
					
						
							|  |  |  |     [ bleach-node ] curry [ ] compose impeach-node ; inline recursive
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ ] [ [ [ ] bleach-node ] test-unboxing ] unit-test | 
					
						
							| 
									
										
										
										
											2008-08-31 10:03:03 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | TUPLE: box { i read-only } ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : box-test ( m -- n )
 | 
					
						
							|  |  |  |     dup box-test i>> swap box-test drop box boa ; inline recursive
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ ] [ [ T{ box f 34 } box-test i>> ] test-unboxing ] unit-test |