2010-01-02 07:03:30 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								! Copyright (C) 2008, 2010 Slava Pestov.
							 | 
						
					
						
							
								
									
										
										
										
											2008-08-12 03:41:18 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								! See http://factorcode.org/license.txt for BSD license.
							 | 
						
					
						
							
								
									
										
										
										
											2015-07-31 23:41:46 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								USING: accessors alien alien.c-types alien.libraries
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								alien.private arrays assocs combinators effects fry kernel math
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								namespaces quotations sequences stack-checker.backend
							 | 
						
					
						
							
								
									
										
										
										
											2010-07-28 00:49:26 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								stack-checker.dependencies stack-checker.state
							 | 
						
					
						
							
								
									
										
										
										
											2015-07-31 23:41:46 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								stack-checker.visitor strings words ;
							 | 
						
					
						
							
								
									
										
										
										
											2010-07-30 15:49:45 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								FROM: kernel.private => declare ;
							 | 
						
					
						
							
								
									
										
										
										
											2008-08-12 03:41:18 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								IN: stack-checker.alien
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-08 05:03:20 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								TUPLE: alien-node-params
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    return parameters
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    { abi abi initial: cdecl } varargs? ;
							 | 
						
					
						
							
								
									
										
										
										
											2008-08-12 03:41:18 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-04 12:21:54 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								TUPLE: alien-invoke-params < alien-node-params
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    library
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    { function string } ;
							 | 
						
					
						
							
								
									
										
										
										
											2008-08-12 03:41:18 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								TUPLE: alien-indirect-params < alien-node-params ;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-04 12:21:54 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								TUPLE: alien-assembly-params < alien-node-params
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    { quot callable } ;
							 | 
						
					
						
							
								
									
										
										
										
											2010-01-06 23:39:22 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-04 12:21:54 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								TUPLE: alien-callback-params < alien-node-params
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    xt ;
							 | 
						
					
						
							
								
									
										
										
										
											2008-08-12 03:41:18 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2010-02-22 03:32:41 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: param-prep-quot ( params -- quot )
							 | 
						
					
						
							
								
									
										
										
										
											2011-10-24 17:31:10 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    parameters>> [ lookup-c-type c-type-unboxer-quot ] map deep-spread>quot ;
							 | 
						
					
						
							
								
									
										
										
										
											2008-08-12 03:41:18 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-06 13:00:23 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: stack-shape ( params -- in out )
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-04 12:21:54 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    [
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-06 13:00:23 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        [ parameters>> length ] [ alien-indirect-params? 1 0 ? ] bi +
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ] [ return>> void? 0 1 ? ] bi ;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: inputs/outputs ( params -- in-d out-d )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    stack-shape [ consume-d ] [ produce-d ] bi* ;
							 | 
						
					
						
							
								
									
										
										
										
											2008-08-12 03:41:18 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2010-02-22 03:32:41 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: return-prep-quot ( params -- quot )
							 | 
						
					
						
							
								
									
										
										
										
											2011-10-24 17:31:10 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    return>> [ [ ] ] [ lookup-c-type c-type-boxer-quot ] if-void ;
							 | 
						
					
						
							
								
									
										
										
										
											2008-08-12 03:41:18 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2010-02-22 03:32:41 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: infer-return ( params -- )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    return-prep-quot infer-quot-here ;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-09 19:18:52 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: pop-abi ( params -- params )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    pop-literal >>abi ;
							 | 
						
					
						
							
								
									
										
										
										
											2010-02-22 03:32:41 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: pop-function ( params -- params )
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-04 10:43:50 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    pop-literal >>function ;
							 | 
						
					
						
							
								
									
										
										
										
											2010-02-22 03:32:41 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-09 19:18:52 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: pop-library ( params -- params )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    pop-literal >>library ;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2010-02-22 03:32:41 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: pop-params ( params -- params )
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-04 10:43:50 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    pop-literal [ [ add-depends-on-c-type ] each ] [ >>parameters ] bi ;
							 | 
						
					
						
							
								
									
										
										
										
											2010-02-22 03:32:41 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: pop-quot ( params -- params )
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-04 10:43:50 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    pop-literal >>quot ;
							 | 
						
					
						
							
								
									
										
										
										
											2010-02-22 03:32:41 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-09 19:18:52 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: pop-return ( params -- params )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    pop-literal [ add-depends-on-c-type ] [ >>return ] bi ;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: pop-varargs? ( params -- params )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    pop-literal >>varargs? ;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-08-12 03:41:18 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: infer-alien-invoke ( -- )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    alien-invoke-params new
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ! Compile-time parameters
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-09 19:18:52 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    pop-varargs?
							 | 
						
					
						
							
								
									
										
										
										
											2010-02-22 03:32:41 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    pop-params
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    pop-function
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    pop-library
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    pop-return
							 | 
						
					
						
							
								
									
										
										
										
											2008-08-12 03:41:18 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ! Set ABI
							 | 
						
					
						
							
								
									
										
										
										
											2010-02-22 07:28:56 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    dup library>> library-abi >>abi
							 | 
						
					
						
							
								
									
										
										
										
											2010-02-22 03:32:41 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ! Quotation which coerces parameters to required types
							 | 
						
					
						
							
								
									
										
										
										
											2010-05-09 23:25:46 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    dup param-prep-quot infer-quot-here
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-04 12:21:54 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ! Consume inputs and outputs and add node to IR
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-06 13:00:23 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    dup dup inputs/outputs #alien-invoke,
							 | 
						
					
						
							
								
									
										
										
										
											2008-08-12 03:41:18 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ! Quotation which coerces return value to required type
							 | 
						
					
						
							
								
									
										
										
										
											2010-02-22 03:32:41 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    infer-return ;
							 | 
						
					
						
							
								
									
										
										
										
											2008-08-12 03:41:18 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: infer-alien-indirect ( -- )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    alien-indirect-params new
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ! Compile-time parameters
							 | 
						
					
						
							
								
									
										
										
										
											2010-02-22 03:32:41 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    pop-abi
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    pop-params
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    pop-return
							 | 
						
					
						
							
								
									
										
										
										
											2010-05-09 23:25:46 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ! Coerce parameters to required types
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    dup param-prep-quot '[ _ [ >c-ptr ] bi* ] infer-quot-here
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-04 12:21:54 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ! Consume inputs and outputs and add node to IR
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-06 13:00:23 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    dup dup inputs/outputs #alien-indirect,
							 | 
						
					
						
							
								
									
										
										
										
											2008-08-12 03:41:18 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ! Quotation which coerces return value to required type
							 | 
						
					
						
							
								
									
										
										
										
											2010-02-22 03:32:41 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    infer-return ;
							 | 
						
					
						
							
								
									
										
										
										
											2008-08-12 03:41:18 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2010-01-06 23:39:22 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: infer-alien-assembly ( -- )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    alien-assembly-params new
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ! Compile-time parameters
							 | 
						
					
						
							
								
									
										
										
										
											2010-02-22 03:32:41 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    pop-quot
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    pop-abi
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    pop-params
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    pop-return
							 | 
						
					
						
							
								
									
										
										
										
											2010-01-06 23:39:22 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ! Quotation which coerces parameters to required types
							 | 
						
					
						
							
								
									
										
										
										
											2010-05-09 23:25:46 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    dup param-prep-quot infer-quot-here
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-04 12:21:54 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ! Consume inputs and outputs and add node to IR
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-06 13:00:23 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    dup dup inputs/outputs #alien-assembly,
							 | 
						
					
						
							
								
									
										
										
										
											2010-01-06 23:39:22 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ! Quotation which coerces return value to required type
							 | 
						
					
						
							
								
									
										
										
										
											2010-02-22 03:32:41 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    infer-return ;
							 | 
						
					
						
							
								
									
										
										
										
											2010-01-06 23:39:22 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2010-05-12 02:09:11 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: callback-xt ( word -- alien )
							 | 
						
					
						
							
								
									
										
										
										
											2014-10-22 06:23:29 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    callbacks get [ dup "stack-cleanup" word-prop <callback> ] cache ;
							 | 
						
					
						
							
								
									
										
										
										
											2008-08-12 03:41:18 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: callback-bottom ( params -- )
							 | 
						
					
						
							
								
									
										
										
										
											2010-07-28 00:49:26 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    "( callback )" <uninterned-word> >>xt
							 | 
						
					
						
							
								
									
										
										
										
											2010-09-06 00:27:39 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    xt>> '[ _ callback-xt { alien } declare ] infer-quot-here ;
							 | 
						
					
						
							
								
									
										
										
										
											2008-08-12 03:41:18 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2010-05-16 03:43:02 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: callback-return-quot ( ctype -- quot )
							 | 
						
					
						
							
								
									
										
										
										
											2011-10-24 17:31:10 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    return>> [ [ ] ] [ lookup-c-type c-type-unboxer-quot ] if-void ;
							 | 
						
					
						
							
								
									
										
										
										
											2010-05-16 03:43:02 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2010-07-30 15:49:45 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: callback-parameter-quot ( params -- quot )
							 | 
						
					
						
							
								
									
										
										
										
											2011-10-24 17:31:10 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    parameters>> [ lookup-c-type ] map
							 | 
						
					
						
							
								
									
										
										
										
											2010-07-30 15:49:45 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    [ [ c-type-class ] map '[ _ declare ] ]
							 | 
						
					
						
							
								
									
										
										
										
											2011-10-02 23:25:39 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    [ [ c-type-boxer-quot ] map deep-spread>quot ]
							 | 
						
					
						
							
								
									
										
										
										
											2010-07-30 15:49:45 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    bi append ;
							 | 
						
					
						
							
								
									
										
										
										
											2010-05-16 03:43:02 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2010-07-28 00:49:26 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								GENERIC: wrap-callback-quot ( params quot -- quot' )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2011-04-10 22:00:43 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								SYMBOL: wait-for-callback-hook
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								wait-for-callback-hook [ [ drop ] ] initialize
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2010-07-28 00:49:26 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								M: callable wrap-callback-quot
							 | 
						
					
						
							
								
									
										
										
										
											2010-07-30 15:49:45 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    swap [ callback-parameter-quot ] [ callback-return-quot ] bi surround
							 | 
						
					
						
							
								
									
										
										
										
											2011-04-10 22:00:43 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    wait-for-callback-hook get
							 | 
						
					
						
							
								
									
										
										
										
											2015-07-31 23:41:46 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    '[ _ _ do-callback ] >quotation ;
							 | 
						
					
						
							
								
									
										
										
										
											2010-07-28 00:49:26 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: callback-effect ( params -- effect )
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-06 13:00:23 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    stack-shape [ "x" <array> ] bi@ <effect> ;
							 | 
						
					
						
							
								
									
										
										
										
											2010-07-28 00:49:26 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: infer-callback-quot ( params quot -- child )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    [
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        init-inference
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        nest-visitor
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        infer-quot-here
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        end-infer
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        callback-effect check-effect
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        stack-visitor get
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ] with-scope ;
							 | 
						
					
						
							
								
									
										
										
										
											2010-05-16 03:43:02 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-08-12 03:41:18 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: infer-alien-callback ( -- )
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-04 10:43:50 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    pop-literal [
							 | 
						
					
						
							
								
									
										
										
										
											2010-07-28 00:49:26 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        alien-callback-params new
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        pop-abi
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        pop-params
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        pop-return
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        dup callback-bottom
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        dup
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        dup
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ] dip wrap-callback-quot infer-callback-quot
							 | 
						
					
						
							
								
									
										
										
										
											2008-08-12 03:41:18 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    #alien-callback, ;
							 |