1 ! Copyright (C) 2005, 2010 Slava Pestov, Alex Chapman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays alien alien.c-types
4 alien.arrays alien.strings kernel math namespaces parser
5 sequences words quotations math.parser splitting grouping
6 effects assocs combinators lexer strings.parser alien.parser
7 fry vocabs.parser words.constant alien.libraries ;
10 SYNTAX: DLL" lexer get skip-blank parse-string dlopen suffix! ;
12 SYNTAX: ALIEN: 16 scan-base <alien> suffix! ;
14 SYNTAX: BAD-ALIEN <bad-alien> suffix! ;
16 SYNTAX: LIBRARY: scan "c-library" set ;
19 (FUNCTION:) define-declared ;
22 (CALLBACK:) define-inline ;
25 scan-c-type CREATE-C-TYPE dup save-location typedef ;
30 [ (CREATE-C-TYPE) dup save-location int swap typedef ] if
31 0 parse-enum-members ;
34 void CREATE-C-TYPE typedef ;
36 ERROR: no-such-symbol name library ;
38 : address-of ( name library -- value )
39 2dup load-library dlsym [ 2nip ] [ no-such-symbol ] if* ;
42 scan "c-library" get '[ _ _ address-of ] append! ;
44 : global-quot ( type word -- quot )
45 name>> "c-library" get '[ _ _ address-of 0 ]
46 swap c-type-getter-boxer append ;
48 : define-global ( type word -- )
49 [ nip ] [ global-quot ] 2bi (( -- value )) define-declared ;
51 SYNTAX: C-GLOBAL: scan-c-type CREATE-WORD define-global ;
54 scan-c-type <pointer> suffix! ;