2008-12-02 03:44:19 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								! Copyright (C) 2008 Joe Groff.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								! See http://factorcode.org/license.txt for BSD license.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								USING: kernel cocoa cocoa.types alien.c-types locals math
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								sequences vectors fry libc destructors
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								specialized-arrays.direct.alien ;
							 | 
						
					
						
							
								
									
										
										
										
											2008-07-13 13:42:35 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								IN: cocoa.enumeration
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-22 20:13:08 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								CONSTANT: NS-EACH-BUFFER-SIZE 16
							 | 
						
					
						
							
								
									
										
										
										
											2008-07-13 13:42:35 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-02 03:44:19 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: with-enumeration-buffers ( quot -- )
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-21 20:34:42 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    '[
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "NSFastEnumerationState" malloc-object &free
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        NS-EACH-BUFFER-SIZE "id" malloc-array &free
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        NS-EACH-BUFFER-SIZE
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        @
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-02 03:44:19 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ] with-destructors ; inline
							 | 
						
					
						
							
								
									
										
										
										
											2008-07-13 13:42:35 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-07-18 20:22:59 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								:: (NSFastEnumeration-each) ( object quot: ( elt -- ) state stackbuf count -- )
							 | 
						
					
						
							
								
									
										
										
										
											2008-07-13 13:42:35 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    object state stackbuf count -> countByEnumeratingWithState:objects:count:
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-02 03:44:19 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    dup 0 = [ drop ] [
							 | 
						
					
						
							
								
									
										
										
										
											2008-07-13 15:48:59 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        state NSFastEnumerationState-itemsPtr [ stackbuf ] unless*
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-02 03:44:19 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        swap <direct-void*-array> quot each
							 | 
						
					
						
							
								
									
										
										
										
											2008-07-13 15:48:59 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        object quot state stackbuf count (NSFastEnumeration-each)
							 | 
						
					
						
							
								
									
										
										
										
											2008-07-18 20:22:59 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ] if ; inline recursive
							 | 
						
					
						
							
								
									
										
										
										
											2008-07-13 13:42:35 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: NSFastEnumeration-each ( object quot -- )
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-02 03:44:19 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    [ (NSFastEnumeration-each) ] with-enumeration-buffers ; inline
							 | 
						
					
						
							
								
									
										
										
										
											2008-07-13 13:42:35 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: NSFastEnumeration-map ( object quot -- vector )
							 | 
						
					
						
							
								
									
										
										
										
											2008-07-13 15:48:59 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    NS-EACH-BUFFER-SIZE <vector>
							 | 
						
					
						
							
								
									
										
										
										
											2008-09-10 23:11:40 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    [ '[ @ _ push ] NSFastEnumeration-each ] keep ; inline
							 | 
						
					
						
							
								
									
										
										
										
											2008-07-13 13:42:35 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: NSFastEnumeration>vector ( object -- vector )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    [ ] NSFastEnumeration-map ;
							 |