| 
									
										
										
										
											2009-05-02 14:45:38 -04:00
										 |  |  | ! Copyright (C) 2008, 2009 Slava Pestov. | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | ! See http://factorcode.org/license.txt for BSD license. | 
					
						
							| 
									
										
										
										
											2014-11-16 23:31:32 -05:00
										 |  |  | USING: accessors alien.accessors alien.c-types alien.strings | 
					
						
							|  |  |  | arrays compiler.units cpu.architecture fry io.encodings.binary | 
					
						
							|  |  |  | io.encodings.utf8 kernel math sequences words ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | IN: alien.arrays | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-15 18:38:49 -04:00
										 |  |  | INSTANCE: array value-type | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-24 17:31:10 -04:00
										 |  |  | M: array lookup-c-type ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-29 05:59:29 -05:00
										 |  |  | M: array c-type-class drop object ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-10 17:17:33 -04:00
										 |  |  | M: array c-type-boxed-class drop object ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-27 22:49:25 -04:00
										 |  |  | : array-length ( seq -- n )
 | 
					
						
							|  |  |  |     [ dup word? [ def>> call( -- object ) ] when ] [ * ] map-reduce ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | M: array heap-size unclip [ array-length ] [ heap-size ] bi* * ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-31 08:45:33 -04:00
										 |  |  | M: array c-type-align first c-type-align ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-10 20:34:14 -05:00
										 |  |  | M: array c-type-align-first first c-type-align-first ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-09 21:36:52 -04:00
										 |  |  | M: array base-type drop void* base-type ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-02 14:45:38 -04:00
										 |  |  | PREDICATE: string-type < pair | 
					
						
							| 
									
										
										
										
											2010-02-23 14:42:02 -05:00
										 |  |  |     first2 [ c-string = ] [ word? ] bi* and ;
 | 
					
						
							| 
									
										
										
										
											2009-05-02 14:45:38 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-24 17:31:10 -04:00
										 |  |  | M: string-type lookup-c-type ;
 | 
					
						
							| 
									
										
										
										
											2009-05-02 14:45:38 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-10 17:17:33 -04:00
										 |  |  | M: string-type c-type-class drop object ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | M: string-type c-type-boxed-class drop object ;
 | 
					
						
							| 
									
										
										
										
											2009-05-02 14:45:38 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-09 21:36:52 -04:00
										 |  |  | M: string-type heap-size drop void* heap-size ;
 | 
					
						
							| 
									
										
										
										
											2009-05-02 14:45:38 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-09 21:36:52 -04:00
										 |  |  | M: string-type c-type-align drop void* c-type-align ;
 | 
					
						
							| 
									
										
										
										
											2009-05-02 14:45:38 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-09 21:36:52 -04:00
										 |  |  | M: string-type c-type-align-first drop void* c-type-align-first ;
 | 
					
						
							| 
									
										
										
										
											2009-05-02 14:45:38 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-09 21:36:52 -04:00
										 |  |  | M: string-type base-type drop void* base-type ;
 | 
					
						
							| 
									
										
										
										
											2009-05-02 14:45:38 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-09 21:36:52 -04:00
										 |  |  | M: string-type c-type-rep drop int-rep ;
 | 
					
						
							| 
									
										
										
										
											2009-05-02 14:45:38 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | M: string-type c-type-boxer-quot | 
					
						
							| 
									
										
										
										
											2010-02-21 22:23:47 -05:00
										 |  |  |     second dup binary =
 | 
					
						
							|  |  |  |     [ drop void* c-type-boxer-quot ] | 
					
						
							|  |  |  |     [ '[ _ alien>string ] ] if ;
 | 
					
						
							| 
									
										
										
										
											2009-05-02 14:45:38 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | M: string-type c-type-unboxer-quot | 
					
						
							| 
									
										
										
										
											2010-02-21 22:23:47 -05:00
										 |  |  |     second dup binary =
 | 
					
						
							|  |  |  |     [ drop void* c-type-unboxer-quot ] | 
					
						
							|  |  |  |     [ '[ _ string>alien ] ] if ;
 | 
					
						
							| 
									
										
										
										
											2009-05-02 14:45:38 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | M: string-type c-type-getter | 
					
						
							|  |  |  |     drop [ alien-cell ] ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-16 17:32:05 -04:00
										 |  |  | M: string-type c-type-copier | 
					
						
							|  |  |  |     drop [ ] ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-02 14:45:38 -04:00
										 |  |  | M: string-type c-type-setter | 
					
						
							|  |  |  |     drop [ set-alien-cell ] ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-15 00:40:29 -04:00
										 |  |  | [ { c-string utf8 } c-string typedef ] with-compilation-unit |