| 
									
										
										
										
											2008-04-03 22:19:20 -04:00
										 |  |  | ! Copyright (C) 2004, 2008 Slava Pestov. | 
					
						
							|  |  |  | ! See http://factorcode.org/license.txt for BSD license. | 
					
						
							| 
									
										
										
										
											2008-07-05 01:59:39 -04:00
										 |  |  | USING: accessors classes classes.algebra words kernel | 
					
						
							|  |  |  | kernel.private namespaces sequences math math.private | 
					
						
							|  |  |  | combinators assocs ;
 | 
					
						
							| 
									
										
										
										
											2008-04-03 22:19:20 -04:00
										 |  |  | IN: classes.builtin | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | SYMBOL: builtins | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PREDICATE: builtin-class < class | 
					
						
							|  |  |  |     "metaclass" word-prop builtin-class eq? ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : type>class ( n -- class ) builtins get-global nth ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-29 03:12:44 -04:00
										 |  |  | : class>type ( class -- n ) "type" word-prop ; foldable
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-03 22:19:20 -04:00
										 |  |  | : bootstrap-type>class ( n -- class ) builtins get nth ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | M: hi-tag class hi-tag type>class ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | M: object class tag type>class ;
 | 
					
						
							| 
									
										
										
										
											2008-05-02 03:51:38 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | M: builtin-class rank-class drop 0 ;
 | 
					
						
							| 
									
										
										
										
											2008-06-29 03:12:44 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : builtin-instance? ( object n -- ? )
 | 
					
						
							|  |  |  |     #! 7 == tag-mask get | 
					
						
							|  |  |  |     #! 3 == hi-tag tag-number | 
					
						
							| 
									
										
										
										
											2008-06-30 02:44:58 -04:00
										 |  |  |     dup 7 fixnum<= [ swap tag eq? ] [ | 
					
						
							| 
									
										
										
										
											2008-06-29 03:12:44 -04:00
										 |  |  |         swap dup tag 3 eq?
 | 
					
						
							|  |  |  |         [ hi-tag eq? ] [ 2drop f ] if
 | 
					
						
							|  |  |  |     ] if ; inline
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | M: builtin-class instance? | 
					
						
							|  |  |  |     class>type builtin-instance? ;
 | 
					
						
							| 
									
										
										
										
											2008-07-05 01:59:39 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | M: builtin-class (flatten-class) dup set ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | M: builtin-class (classes-intersect?) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         { [ 2dup eq? ] [ 2drop t ] } | 
					
						
							|  |  |  |         { [ over builtin-class? ] [ 2drop f ] } | 
					
						
							|  |  |  |         [ swap classes-intersect? ] | 
					
						
							|  |  |  |     } cond ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | M: anonymous-intersection (flatten-class) | 
					
						
							| 
									
										
										
										
											2008-07-05 05:42:58 -04:00
										 |  |  |     participants>> [ flatten-builtin-class ] map
 | 
					
						
							| 
									
										
										
										
											2008-09-06 18:10:32 -04:00
										 |  |  |     [ | 
					
						
							|  |  |  |         builtins get sift [ (flatten-class) ] each
 | 
					
						
							| 
									
										
										
										
											2008-07-05 01:59:39 -04:00
										 |  |  |     ] [ | 
					
						
							|  |  |  |         unclip [ assoc-intersect ] reduce [ swap set ] assoc-each
 | 
					
						
							| 
									
										
										
										
											2008-09-06 18:10:32 -04:00
										 |  |  |     ] if-empty ;
 | 
					
						
							| 
									
										
										
										
											2008-07-05 01:59:39 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | M: anonymous-complement (flatten-class) | 
					
						
							|  |  |  |     drop builtins get sift [ (flatten-class) ] each ;
 |