[ \ fortran-invoke 5 [ ] nsequence ] dip define-declared ;
SYNTAX: SUBROUTINE:
- f "c-library" get scan ";" parse-tokens
+ f current-library get scan ";" parse-tokens
[ "()" subseq? not ] filter define-fortran-function ;
SYNTAX: FUNCTION:
- scan "c-library" get scan ";" parse-tokens
+ scan current-library get scan ";" parse-tokens
[ "()" subseq? not ] filter define-fortran-function ;
SYNTAX: LIBRARY:
scan
- [ "c-library" set ]
+ [ current-library set ]
[ set-fortran-abi ] bi ;
: library-abi ( library -- abi )
library [ abi>> ] [ cdecl ] if* ;
+ERROR: no-such-symbol name library ;
+
+: address-of ( name library -- value )
+ 2dup load-library dlsym [ 2nip ] [ no-such-symbol ] if* ;
+
SYMBOL: deploy-libraries
deploy-libraries [ V{ } clone ] initialize
vocabs.parser words.constant ;
IN: alien.parser
+SYMBOL: current-library
+
: parse-c-type-name ( name -- word )
dup search [ ] [ no-word ] ?if ;
names return function-effect ;
: (FUNCTION:) ( -- word quot effect )
- scan-function-name "c-library" get ";" scan-c-args make-function ;
+ scan-function-name current-library get ";" scan-c-args make-function ;
: callback-quot ( return types abi -- quot )
'[ [ _ _ _ ] dip alien-callback ] ;
type-word return types lib library-abi callback-quot (( quot -- alien )) ;
: (CALLBACK:) ( -- word quot effect )
- "c-library" get
+ current-library get
scan-function-name ";" scan-c-args make-callback-type ;
PREDICATE: alien-function-word < word
PREDICATE: alien-callback-type-word < typedef-word
"callback-effect" word-prop ;
+
+: global-quot ( type word -- quot )
+ name>> current-library get '[ _ _ address-of 0 ]
+ swap c-type-getter-boxer append ;
+
+: define-global ( type word -- )
+ [ nip ] [ global-quot ] 2bi (( -- value )) define-declared ;
! Copyright (C) 2005, 2010 Slava Pestov, Alex Chapman.
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors arrays alien alien.c-types
-alien.arrays alien.strings kernel math namespaces parser
-sequences words quotations math.parser splitting grouping
-effects assocs combinators lexer strings.parser alien.parser
-fry vocabs.parser words.constant alien.libraries ;
+USING: accessors arrays alien alien.c-types alien.arrays
+alien.strings kernel math namespaces parser sequences words
+quotations math.parser splitting grouping effects assocs
+combinators lexer strings.parser alien.parser fry vocabs.parser
+words.constant alien.libraries ;
IN: alien.syntax
SYNTAX: DLL" lexer get skip-blank parse-string dlopen suffix! ;
SYNTAX: BAD-ALIEN <bad-alien> suffix! ;
-SYNTAX: LIBRARY: scan "c-library" set ;
+SYNTAX: LIBRARY: scan current-library set ;
SYNTAX: FUNCTION:
(FUNCTION:) define-declared ;
SYNTAX: C-TYPE:
void CREATE-C-TYPE typedef ;
-ERROR: no-such-symbol name library ;
-
-: address-of ( name library -- value )
- 2dup load-library dlsym [ 2nip ] [ no-such-symbol ] if* ;
-
SYNTAX: &:
- scan "c-library" get '[ _ _ address-of ] append! ;
-
-: global-quot ( type word -- quot )
- name>> "c-library" get '[ _ _ address-of 0 ]
- swap c-type-getter-boxer append ;
-
-: define-global ( type word -- )
- [ nip ] [ global-quot ] 2bi (( -- value )) define-declared ;
+ scan current-library get '[ _ _ address-of ] append! ;
SYNTAX: C-GLOBAL: scan-c-type CREATE-WORD define-global ;