1 ! Copyright (C) 2008, 2009 Slava Pestov, Doug Coleman.
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 : normalize-c-arg ( type name -- type' name' )
11 [ CHAR: * = ] trim-head
12 [ length - CHAR: * <array> append ] keep
15 : parse-arglist ( parameters return -- types effect )
17 2 group [ first2 normalize-c-arg 2array ] map
18 unzip [ "," ?tail drop ] map
20 [ [ { } ] [ 1array ] if-void ]
23 : function-quot ( return library function types -- quot )
24 '[ _ _ _ _ alien-invoke ] ;
26 :: make-function ( return! library function! parameters -- word quot effect )
27 return function normalize-c-arg function! return!
28 function create-in dup reset-generic
29 return library function
30 parameters return parse-arglist [ function-quot ] dip ;
32 : (FUNCTION:) ( -- word quot effect )
33 scan "c-library" get scan ";" parse-tokens
34 [ "()" subseq? not ] filter
37 : define-function ( return library function parameters -- )
38 make-function define-declared ;