From 408bbbdcf820863b16e22ad1c85bb750fde76f59 Mon Sep 17 00:00:00 2001 From: Jeremy Hughes Date: Fri, 3 Jul 2009 15:32:00 +1200 Subject: [PATCH] alien.inline renamed words for runtime use --- basis/alien/inline/inline.factor | 73 ++++++++++++++------------- basis/alien/inline/tests/tests.factor | 2 +- 2 files changed, 40 insertions(+), 35 deletions(-) diff --git a/basis/alien/inline/inline.factor b/basis/alien/inline/inline.factor index 5e235fe74e..8e58071427 100644 --- a/basis/alien/inline/inline.factor +++ b/basis/alien/inline/inline.factor @@ -12,28 +12,17 @@ SYMBOL: library-is-c++ SYMBOL: compiler-args SYMBOL: c-strings -: (C-LIBRARY:) ( -- ) - scan c-library set - V{ } clone c-strings set - V{ } clone compiler-args set ; - -: (C-LINK:) ( -- ) - "-l" scan append compiler-args get push ; - -: (C-FRAMEWORK:) ( -- ) - "-framework" scan compiler-args get '[ _ push ] bi@ ; - : return-library-function-params ( -- return library function params ) scan c-library get scan ")" parse-tokens [ "(" subseq? not ] filter [ [ dup CHAR: - = [ drop CHAR: space ] when ] map ] 3dip ; -: factor-function ( return library functions params -- ) +: factor-function ( return library function params -- ) [ dup "const " head? [ 6 tail ] when ] 3dip make-function define-declared ; -: (C-FUNCTION:) ( return library function params -- str ) +: c-function-string ( return library function params -- str ) [ nip ] dip " " join "(" prepend ")" append 3array " " join library-is-c++ get [ "extern \"C\" " prepend ] when ; @@ -53,31 +42,47 @@ SYMBOL: c-strings compiler-args get c-strings get "\n" join c-library get compile-to-library ; - -: (;C-LIBRARY) ( -- ) - compile-library? [ compile-library ] when - c-library get library-path "cdecl" add-library ; PRIVATE> -SYNTAX: C-LIBRARY: (C-LIBRARY:) ; +: define-c-library ( name -- ) + c-library set + V{ } clone c-strings set + V{ } clone compiler-args set ; -SYNTAX: COMPILE-AS-C++ t library-is-c++ set ; +: compile-c-library ( -- ) + compile-library? [ compile-library ] when + c-library get library-path "cdecl" add-library ; -SYNTAX: C-LINK: (C-LINK:) ; - -SYNTAX: C-FRAMEWORK: (C-FRAMEWORK:) ; - -SYNTAX: C-LINK/FRAMEWORK: - os macosx? [ (C-FRAMEWORK:) ] [ (C-LINK:) ] if ; - -SYNTAX: C-INCLUDE: - "#include " scan append c-strings get push ; - -SYNTAX: C-FUNCTION: - return-library-function-params - [ factor-function ] - 4 nkeep (C-FUNCTION:) +: define-c-function ( return library function params -- ) + [ factor-function ] 4 nkeep c-function-string " {\n" append parse-here append "\n}\n" append c-strings get push ; -SYNTAX: ;C-LIBRARY (;C-LIBRARY) ; +: define-c-link ( str -- ) + "-l" prepend compiler-args get push ; + +: define-c-framework ( str -- ) + "-framework" swap compiler-args get '[ _ push ] bi@ ; + +: define-c-link/framework ( str -- ) + os macosx? [ define-c-framework ] [ define-c-link ] if ; + +: define-c-include ( str -- ) + "#include " prepend c-strings get push ; + +SYNTAX: C-LIBRARY: scan define-c-library ; + +SYNTAX: COMPILE-AS-C++ t library-is-c++ set ; + +SYNTAX: C-LINK: scan define-c-link ; + +SYNTAX: C-FRAMEWORK: scan define-c-framework ; + +SYNTAX: C-LINK/FRAMEWORK: scan define-c-link/framework ; + +SYNTAX: C-INCLUDE: scan define-c-include ; + +SYNTAX: C-FUNCTION: + return-library-function-params define-c-function ; + +SYNTAX: ;C-LIBRARY compile-c-library ; diff --git a/basis/alien/inline/tests/tests.factor b/basis/alien/inline/tests/tests.factor index cfa98cacfc..acd2d615cd 100644 --- a/basis/alien/inline/tests/tests.factor +++ b/basis/alien/inline/tests/tests.factor @@ -43,6 +43,6 @@ C-FUNCTION: char* breakme ( ) return not a string; ; -<< [ (;C-LIBRARY) ] must-fail >> +<< [ compile-c-library ] must-fail >> << library-path dup exists? [ delete-file ] [ drop ] if >>