From becb7c78b7cd99ccc82950950e8ad58da5cb2a07 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Mon, 12 Apr 2010 18:09:26 -0500 Subject: [PATCH] Move non-parsing words out of alien.syntax, and use a symbol instead of a string variable to store the current library in alien.parser --- basis/alien/fortran/fortran.factor | 6 +++--- basis/alien/libraries/libraries.factor | 5 +++++ basis/alien/parser/parser.factor | 13 +++++++++++-- basis/alien/syntax/syntax.factor | 26 +++++++------------------- 4 files changed, 26 insertions(+), 24 deletions(-) mode change 100644 => 100755 basis/alien/fortran/fortran.factor mode change 100644 => 100755 basis/alien/libraries/libraries.factor mode change 100644 => 100755 basis/alien/parser/parser.factor mode change 100644 => 100755 basis/alien/syntax/syntax.factor diff --git a/basis/alien/fortran/fortran.factor b/basis/alien/fortran/fortran.factor old mode 100644 new mode 100755 index 8c74aa102a..9f44dec80a --- a/basis/alien/fortran/fortran.factor +++ b/basis/alien/fortran/fortran.factor @@ -434,15 +434,15 @@ MACRO: fortran-invoke ( return library function parameters -- ) [ \ 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 ; diff --git a/basis/alien/libraries/libraries.factor b/basis/alien/libraries/libraries.factor old mode 100644 new mode 100755 index 5a042fd436..86249436aa --- a/basis/alien/libraries/libraries.factor +++ b/basis/alien/libraries/libraries.factor @@ -38,6 +38,11 @@ M: library dispose dll>> [ dispose ] when* ; : 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 diff --git a/basis/alien/parser/parser.factor b/basis/alien/parser/parser.factor old mode 100644 new mode 100755 index 0891caa04a..7b677c3581 --- a/basis/alien/parser/parser.factor +++ b/basis/alien/parser/parser.factor @@ -7,6 +7,8 @@ splitting words fry locals lexer namespaces summary math vocabs.parser words.constant ; IN: alien.parser +SYMBOL: current-library + : parse-c-type-name ( name -- word ) dup search [ ] [ no-word ] ?if ; @@ -117,7 +119,7 @@ PRIVATE> 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 ] ; @@ -131,7 +133,7 @@ PRIVATE> 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 @@ -142,3 +144,10 @@ 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 ; diff --git a/basis/alien/syntax/syntax.factor b/basis/alien/syntax/syntax.factor old mode 100644 new mode 100755 index 00148a82d4..bc7e590cff --- a/basis/alien/syntax/syntax.factor +++ b/basis/alien/syntax/syntax.factor @@ -1,10 +1,10 @@ ! 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! ; @@ -13,7 +13,7 @@ SYNTAX: ALIEN: 16 scan-base suffix! ; SYNTAX: BAD-ALIEN suffix! ; -SYNTAX: LIBRARY: scan "c-library" set ; +SYNTAX: LIBRARY: scan current-library set ; SYNTAX: FUNCTION: (FUNCTION:) define-declared ; @@ -33,20 +33,8 @@ SYNTAX: C-ENUM: 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 ;