| 
									
										
										
										
											2008-12-03 10:41:48 -05:00
										 |  |  | IN: struct-arrays.tests | 
					
						
							|  |  |  | USING: struct-arrays tools.test kernel math sequences | 
					
						
							| 
									
										
										
										
											2008-12-18 22:17:24 -05:00
										 |  |  | alien.syntax alien.c-types destructors libc accessors | 
					
						
							|  |  |  | destructors ;
 | 
					
						
							| 
									
										
										
										
											2008-12-03 10:41:48 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | C-STRUCT: test-struct | 
					
						
							|  |  |  | { "int" "x" } | 
					
						
							|  |  |  | { "int" "y" } ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : make-point ( x y -- struct )
 | 
					
						
							|  |  |  |     "test-struct" <c-object> | 
					
						
							|  |  |  |     [ set-test-struct-y ] keep
 | 
					
						
							|  |  |  |     [ set-test-struct-x ] keep ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ 5/4 ] [ | 
					
						
							|  |  |  |     2 "test-struct" <struct-array> | 
					
						
							|  |  |  |     1 2 make-point over set-first
 | 
					
						
							|  |  |  |     3 4 make-point over set-second
 | 
					
						
							|  |  |  |     0 [ [ test-struct-x ] [ test-struct-y ] bi / + ] reduce
 | 
					
						
							|  |  |  | ] unit-test | 
					
						
							| 
									
										
										
										
											2008-12-03 10:54:59 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | [ 5/4 ] [ | 
					
						
							|  |  |  |     [ | 
					
						
							|  |  |  |         2 "test-struct" malloc-struct-array | 
					
						
							| 
									
										
										
										
											2009-02-06 05:37:28 -05:00
										 |  |  |         dup &free drop
 | 
					
						
							| 
									
										
										
										
											2008-12-03 10:54:59 -05:00
										 |  |  |         1 2 make-point over set-first
 | 
					
						
							|  |  |  |         3 4 make-point over set-second
 | 
					
						
							|  |  |  |         0 [ [ test-struct-x ] [ test-struct-y ] bi / + ] reduce
 | 
					
						
							|  |  |  |     ] with-destructors | 
					
						
							|  |  |  | ] unit-test | 
					
						
							| 
									
										
										
										
											2008-12-18 22:17:24 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | [ ] [ ALIEN: 123 10 "test-struct" <direct-struct-array> drop ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ ] [ | 
					
						
							|  |  |  |     [ | 
					
						
							|  |  |  |         10 "test-struct" malloc-struct-array | 
					
						
							| 
									
										
										
										
											2009-02-06 05:37:28 -05:00
										 |  |  |         &free drop
 | 
					
						
							| 
									
										
										
										
											2008-12-18 22:17:24 -05:00
										 |  |  |     ] with-destructors | 
					
						
							|  |  |  | ] unit-test |