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 ;
29 [ [ create-in ] dip define-constant ] each-index ;
32 void CREATE-C-TYPE typedef ;
34 ERROR: no-such-symbol name library ;
36 : address-of ( name library -- value )
37 2dup load-library dlsym [ 2nip ] [ no-such-symbol ] if* ;
40 scan "c-library" get '[ _ _ address-of ] append! ;
42 : global-quot ( type word -- quot )
43 name>> "c-library" get '[ _ _ address-of 0 ]
44 swap c-type-getter-boxer append ;
46 : define-global ( type word -- )
47 [ nip ] [ global-quot ] 2bi (( -- value )) define-declared ;
49 SYNTAX: C-GLOBAL: scan-c-type CREATE-WORD define-global ;