| 
									
										
										
										
											2008-09-10 23:11:03 -04:00
										 |  |  | ! Copyright (C) 2008 Slava Pestov. | 
					
						
							|  |  |  | ! See http://factorcode.org/license.txt for BSD license. | 
					
						
							|  |  |  | USING: accessors kernel namespaces make math sequences layouts | 
					
						
							| 
									
										
										
										
											2008-10-07 17:13:29 -04:00
										 |  |  | alien.c-types alien.structs cpu.architecture ;
 | 
					
						
							| 
									
										
										
										
											2008-09-10 23:11:03 -04:00
										 |  |  | IN: compiler.alien | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : large-struct? ( ctype -- ? )
 | 
					
						
							| 
									
										
										
										
											2008-10-07 17:13:29 -04:00
										 |  |  |     dup c-struct? [ struct-small-enough? not ] [ drop f ] if ;
 | 
					
						
							| 
									
										
										
										
											2008-09-10 23:11:03 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : alien-parameters ( params -- seq )
 | 
					
						
							|  |  |  |     dup parameters>> | 
					
						
							|  |  |  |     swap return>> large-struct? [ "void*" prefix ] when ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : alien-return ( params -- ctype )
 | 
					
						
							|  |  |  |     return>> dup large-struct? [ drop "void" ] when ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : c-type-stack-align ( type -- align )
 | 
					
						
							|  |  |  |     dup c-type-stack-align? [ c-type-align ] [ drop cell ] if ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : parameter-align ( n type -- n delta )
 | 
					
						
							| 
									
										
										
										
											2008-11-30 19:28:15 -05:00
										 |  |  |     [ c-type-stack-align align dup ] [ drop ] 2bi - ;
 | 
					
						
							| 
									
										
										
										
											2008-09-10 23:11:03 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : parameter-sizes ( types -- total offsets )
 | 
					
						
							|  |  |  |     #! Compute stack frame locations. | 
					
						
							|  |  |  |     [ | 
					
						
							|  |  |  |         0 [ | 
					
						
							|  |  |  |             [ parameter-align drop dup , ] keep stack-size +
 | 
					
						
							|  |  |  |         ] reduce cell align
 | 
					
						
							|  |  |  |     ] { } make ;
 |