| 
									
										
										
										
											2010-02-11 08:50:59 -05:00
										 |  |  | ! Copyright (C) 2008, 2010 Slava Pestov. | 
					
						
							| 
									
										
										
										
											2008-07-25 03:07:45 -04:00
										 |  |  | ! See http://factorcode.org/license.txt for BSD license. | 
					
						
							|  |  |  | USING: fry assocs arrays byte-arrays strings accessors sequences | 
					
						
							|  |  |  | kernel slots classes.algebra classes.tuple classes.tuple.private | 
					
						
							| 
									
										
										
										
											2010-02-11 08:50:59 -05:00
										 |  |  | combinators.short-circuit words math math.private combinators | 
					
						
							|  |  |  | sequences.private namespaces slots.private classes | 
					
						
							|  |  |  | compiler.tree.propagation.info ;
 | 
					
						
							| 
									
										
										
										
											2008-07-25 03:07:45 -04:00
										 |  |  | IN: compiler.tree.propagation.slots | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ! Propagation of immutable slots and array lengths | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-30 04:38:10 -04:00
										 |  |  | : sequence-constructor? ( word -- ? )
 | 
					
						
							| 
									
										
										
										
											2009-10-28 16:02:00 -04:00
										 |  |  |     { <array> <byte-array> (byte-array) <string> } member-eq? ;
 | 
					
						
							| 
									
										
										
										
											2008-07-25 03:07:45 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : constructor-output-class ( word -- class )
 | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         { <array> array } | 
					
						
							|  |  |  |         { <byte-array> byte-array } | 
					
						
							| 
									
										
										
										
											2008-12-09 19:17:04 -05:00
										 |  |  |         { (byte-array) byte-array } | 
					
						
							| 
									
										
										
										
											2008-07-25 03:07:45 -04:00
										 |  |  |         { <string> string } | 
					
						
							|  |  |  |     } at ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-30 04:38:10 -04:00
										 |  |  | : propagate-sequence-constructor ( #call word -- infos )
 | 
					
						
							| 
									
										
										
										
											2010-03-09 15:58:44 -05:00
										 |  |  |     [ in-d>> first value-info ] | 
					
						
							|  |  |  |     [ constructor-output-class ] bi*
 | 
					
						
							| 
									
										
										
										
											2010-03-09 21:15:49 -05:00
										 |  |  |     <sequence-info> 1array ;
 | 
					
						
							| 
									
										
										
										
											2008-07-25 03:07:45 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-26 20:01:43 -04:00
										 |  |  | : fold-<tuple-boa> ( values class -- info )
 | 
					
						
							| 
									
										
										
										
											2008-09-03 04:46:56 -04:00
										 |  |  |     [ [ literal>> ] map ] dip prefix >tuple | 
					
						
							| 
									
										
										
										
											2008-07-26 20:01:43 -04:00
										 |  |  |     <literal-info> ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-01 10:36:53 -04:00
										 |  |  | : read-only-slots ( values class -- slots )
 | 
					
						
							|  |  |  |     all-slots | 
					
						
							|  |  |  |     [ read-only>> [ value-info ] [ drop f ] if ] 2map
 | 
					
						
							|  |  |  |     f prefix ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-26 22:44:56 -04:00
										 |  |  | : fold-<tuple-boa>? ( values class -- ? )
 | 
					
						
							|  |  |  |     [ rest-slice [ dup [ literal?>> ] when ] all? ] | 
					
						
							|  |  |  |     [ identity-tuple class<= not ] | 
					
						
							|  |  |  |     bi* and ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : (propagate-<tuple-boa>) ( values class -- info )
 | 
					
						
							|  |  |  |     [ read-only-slots ] keep 2dup fold-<tuple-boa>? | 
					
						
							|  |  |  |     [ [ rest-slice ] dip fold-<tuple-boa> ] [ <tuple-info> ] if ;
 | 
					
						
							| 
									
										
										
										
											2008-07-25 03:07:45 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-30 01:27:35 -04:00
										 |  |  | : propagate-<tuple-boa> ( #call -- infos )
 | 
					
						
							| 
									
										
										
										
											2008-07-30 18:36:24 -04:00
										 |  |  |     in-d>> unclip-last
 | 
					
						
							| 
									
										
										
										
											2010-03-26 22:44:56 -04:00
										 |  |  |     value-info literal>> first (propagate-<tuple-boa>) 1array ;
 | 
					
						
							| 
									
										
										
										
											2008-07-25 03:07:45 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-30 04:38:10 -04:00
										 |  |  | : read-only-slot? ( n class -- ? )
 | 
					
						
							|  |  |  |     all-slots [ offset>> = ] with find nip
 | 
					
						
							|  |  |  |     dup [ read-only>> ] when ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : literal-info-slot ( slot object -- info/f )
 | 
					
						
							| 
									
										
										
										
											2010-02-11 08:50:59 -05:00
										 |  |  |     #! literal-info-slot makes an unsafe call to 'slot'. | 
					
						
							|  |  |  |     #! Check that the layout is up to date to avoid accessing the | 
					
						
							|  |  |  |     #! wrong slot during a compilation unit where reshaping took | 
					
						
							|  |  |  |     #! place. This could happen otherwise because the "slots" word | 
					
						
							|  |  |  |     #! property would reflect the new layout, but instances in the | 
					
						
							|  |  |  |     #! heap would use the old layout since instances are updated | 
					
						
							|  |  |  |     #! immediately after compilation. | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2011-10-24 07:47:42 -04:00
										 |  |  |         [ class-of read-only-slot? ] | 
					
						
							| 
									
										
										
										
											2010-02-11 08:50:59 -05:00
										 |  |  |         [ nip layout-up-to-date? ] | 
					
						
							|  |  |  |         [ swap slot <literal-info> ] | 
					
						
							|  |  |  |     } 2&& ;
 | 
					
						
							| 
									
										
										
										
											2008-07-30 04:38:10 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : length-accessor? ( slot info -- ? )
 | 
					
						
							|  |  |  |     [ 1 = ] [ length>> ] bi* and ;
 | 
					
						
							| 
									
										
										
										
											2008-07-26 20:01:43 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-25 03:07:45 -04:00
										 |  |  | : value-info-slot ( slot info -- info' )
 | 
					
						
							| 
									
										
										
										
											2008-07-26 20:01:43 -04:00
										 |  |  |     { | 
					
						
							|  |  |  |         { [ over 0 = ] [ 2drop fixnum <class-info> ] } | 
					
						
							| 
									
										
										
										
											2008-07-30 04:38:10 -04:00
										 |  |  |         { [ dup literal?>> ] [ literal>> literal-info-slot ] } | 
					
						
							| 
									
										
										
										
											2009-08-13 20:21:44 -04:00
										 |  |  |         [ [ 1 - ] [ slots>> ] bi* ?nth ] | 
					
						
							| 
									
										
										
										
											2008-07-30 16:37:40 -04:00
										 |  |  |     } cond [ object-info ] unless* ;
 |