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 : scan-c-type ( -- c-type )
10 [ drop \ } parse-until >array ]
13 : normalize-c-arg ( type name -- type' name' )
16 [ CHAR: * = ] trim-head
17 [ length - CHAR: * <array> append ] keep
19 [ parse-c-type ] dip ;
21 : parse-arglist ( parameters return -- types effect )
23 2 group [ first2 normalize-c-arg 2array ] map
24 unzip [ "," ?tail drop ] map
26 [ [ { } ] [ 1array ] if-void ]
29 : function-quot ( return library function types -- quot )
30 '[ _ _ _ _ alien-invoke ] ;
32 :: make-function ( return! library function! parameters -- word quot effect )
33 return function normalize-c-arg function! return!
34 function create-in dup reset-generic
35 return library function
36 parameters return parse-arglist [ function-quot ] dip ;
38 : (FUNCTION:) ( -- word quot effect )
39 scan "c-library" get scan ";" parse-tokens
40 [ "()" subseq? not ] filter
43 : define-function ( return library function parameters -- )
44 make-function define-declared ;