Refactor FUNCTION: to make it more extensible
							parent
							
								
									0a22476cd3
								
							
						
					
					
						commit
						c3e7db3852
					
				| 
						 | 
					@ -1,7 +1,7 @@
 | 
				
			||||||
! Copyright (C) 2008 Slava Pestov.
 | 
					! Copyright (C) 2008, 2009 Slava Pestov.
 | 
				
			||||||
! See http://factorcode.org/license.txt for BSD license.
 | 
					! See http://factorcode.org/license.txt for BSD license.
 | 
				
			||||||
USING: alien alien.c-types arrays assocs effects grouping kernel
 | 
					USING: alien alien.c-types arrays assocs effects grouping kernel
 | 
				
			||||||
parser sequences splitting words fry locals ;
 | 
					parser sequences splitting words fry locals lexer namespaces ;
 | 
				
			||||||
IN: alien.parser
 | 
					IN: alien.parser
 | 
				
			||||||
 | 
					
 | 
				
			||||||
: parse-arglist ( parameters return -- types effect )
 | 
					: parse-arglist ( parameters return -- types effect )
 | 
				
			||||||
| 
						 | 
					@ -12,8 +12,15 @@ IN: alien.parser
 | 
				
			||||||
: function-quot ( return library function types -- quot )
 | 
					: function-quot ( return library function types -- quot )
 | 
				
			||||||
    '[ _ _ _ _ alien-invoke ] ;
 | 
					    '[ _ _ _ _ alien-invoke ] ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
:: define-function ( return library function parameters -- )
 | 
					:: make-function ( return library function parameters -- word quot effect )
 | 
				
			||||||
    function create-in dup reset-generic
 | 
					    function create-in dup reset-generic
 | 
				
			||||||
    return library function
 | 
					    return library function
 | 
				
			||||||
    parameters return parse-arglist [ function-quot ] dip
 | 
					    parameters return parse-arglist [ function-quot ] dip ;
 | 
				
			||||||
    define-declared ;
 | 
					
 | 
				
			||||||
 | 
					: (FUNCTION:) ( -- word quot effect )
 | 
				
			||||||
 | 
					    scan "c-library" get scan ";" parse-tokens
 | 
				
			||||||
 | 
					    [ "()" subseq? not ] filter
 | 
				
			||||||
 | 
					    make-function ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					: define-function ( return library function parameters -- )
 | 
				
			||||||
 | 
					    make-function define-declared ;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -16,9 +16,7 @@ SYNTAX: BAD-ALIEN <bad-alien> parsed ;
 | 
				
			||||||
SYNTAX: LIBRARY: scan "c-library" set ;
 | 
					SYNTAX: LIBRARY: scan "c-library" set ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SYNTAX: FUNCTION:
 | 
					SYNTAX: FUNCTION:
 | 
				
			||||||
    scan "c-library" get scan ";" parse-tokens
 | 
					    (FUNCTION:) define-declared ;
 | 
				
			||||||
    [ "()" subseq? not ] filter
 | 
					 | 
				
			||||||
    define-function ;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
SYNTAX: TYPEDEF:
 | 
					SYNTAX: TYPEDEF:
 | 
				
			||||||
    scan scan typedef ;
 | 
					    scan scan typedef ;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue