1 ! Copyright (C) 2008, 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: alien alien.c-types arrays assocs effects grouping kernel
4 parser sequences splitting words fry locals lexer namespaces
8 ERROR: invalid-c-name name ;
10 M: invalid-c-name summary
11 drop "The C pointer asterisk must be part of the type string." ;
13 : check-c-name ( string -- string )
14 dup [ CHAR: * = ] any? [ invalid-c-name ] when ;
16 : parse-arglist ( parameters return -- types effect )
17 [ 2 group unzip [ "," ?tail drop check-c-name ] map ]
18 [ [ { } ] [ 1array ] if-void ]
21 : function-quot ( return library function types -- quot )
22 '[ _ _ _ _ alien-invoke ] ;
24 :: make-function ( return library function parameters -- word quot effect )
25 function check-c-name create-in dup reset-generic
26 return library function
27 parameters return parse-arglist [ function-quot ] dip ;
29 : (FUNCTION:) ( -- word quot effect )
30 scan "c-library" get scan ";" parse-tokens
31 [ "()" subseq? not ] filter
34 : define-function ( return library function parameters -- )
35 make-function define-declared ;