alien.c-syntax alien.compile: symbols instead of strings
parent
94f519b12c
commit
bb379a11ca
|
@ -5,19 +5,24 @@ vocabs.loader vocabs.parser words ;
|
||||||
IN: alien.c-syntax
|
IN: alien.c-syntax
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
SYMBOL: c-library
|
||||||
|
SYMBOL: library-is-c++
|
||||||
|
SYMBOL: compiler-args
|
||||||
|
SYMBOL: c-strings
|
||||||
|
|
||||||
: (C-LIBRARY:) ( -- )
|
: (C-LIBRARY:) ( -- )
|
||||||
scan "c-library" set
|
scan c-library set
|
||||||
V{ } clone "c-library-vector" set
|
V{ } clone c-strings set
|
||||||
V{ } clone "c-compiler-args" set ;
|
V{ } clone compiler-args set ;
|
||||||
|
|
||||||
: (C-LINK:) ( -- )
|
: (C-LINK:) ( -- )
|
||||||
"-l" scan append "c-compiler-args" get push ;
|
"-l" scan append compiler-args get push ;
|
||||||
|
|
||||||
: (C-FRAMEWORK:) ( -- )
|
: (C-FRAMEWORK:) ( -- )
|
||||||
"-framework" scan "c-compiler-args" get '[ _ push ] bi@ ;
|
"-framework" scan compiler-args get '[ _ push ] bi@ ;
|
||||||
|
|
||||||
: return-library-function-params ( -- return library function params )
|
: return-library-function-params ( -- return library function params )
|
||||||
scan "c-library" get scan ")" parse-tokens
|
scan c-library get scan ")" parse-tokens
|
||||||
[ "(" subseq? not ] filter [
|
[ "(" subseq? not ] filter [
|
||||||
[ dup CHAR: - = [ drop CHAR: space ] when ] map
|
[ dup CHAR: - = [ drop CHAR: space ] when ] map
|
||||||
] 3dip ;
|
] 3dip ;
|
||||||
|
@ -29,10 +34,10 @@ IN: alien.c-syntax
|
||||||
: (C-FUNCTION:) ( return library function params -- str )
|
: (C-FUNCTION:) ( return library function params -- str )
|
||||||
[ nip ] dip
|
[ nip ] dip
|
||||||
" " join "(" prepend ")" append 3array " " join
|
" " join "(" prepend ")" append 3array " " join
|
||||||
"library-is-c++" get [ "extern \"C\" " prepend ] when ;
|
library-is-c++ get [ "extern \"C\" " prepend ] when ;
|
||||||
|
|
||||||
: library-path ( -- str )
|
: library-path ( -- str )
|
||||||
"lib" "c-library" get library-suffix
|
"lib" c-library get library-suffix
|
||||||
3array concat temp-file ;
|
3array concat temp-file ;
|
||||||
|
|
||||||
: compile-library? ( -- ? )
|
: compile-library? ( -- ? )
|
||||||
|
@ -42,19 +47,19 @@ IN: alien.c-syntax
|
||||||
] [ drop t ] if ;
|
] [ drop t ] if ;
|
||||||
|
|
||||||
: compile-library ( -- )
|
: compile-library ( -- )
|
||||||
"library-is-c++" get [ "C++" ] [ "C" ] if
|
library-is-c++ get [ C++ ] [ C ] if
|
||||||
"c-compiler-args" get
|
compiler-args get
|
||||||
"c-library-vector" get "\n" join
|
c-strings get "\n" join
|
||||||
"c-library" get compile-to-library ;
|
c-library get compile-to-library ;
|
||||||
|
|
||||||
: (;C-LIBRARY) ( -- )
|
: (;C-LIBRARY) ( -- )
|
||||||
compile-library? [ compile-library ] when
|
compile-library? [ compile-library ] when
|
||||||
"c-library" get library-path "cdecl" add-library ;
|
c-library get library-path "cdecl" add-library ;
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
SYNTAX: C-LIBRARY: (C-LIBRARY:) ;
|
SYNTAX: C-LIBRARY: (C-LIBRARY:) ;
|
||||||
|
|
||||||
SYNTAX: COMPILE-AS-C++ t "library-is-c++" set ;
|
SYNTAX: COMPILE-AS-C++ t library-is-c++ set ;
|
||||||
|
|
||||||
SYNTAX: C-LINK: (C-LINK:) ;
|
SYNTAX: C-LINK: (C-LINK:) ;
|
||||||
|
|
||||||
|
@ -64,13 +69,13 @@ SYNTAX: C-LINK/FRAMEWORK:
|
||||||
os macosx? [ (C-FRAMEWORK:) ] [ (C-LINK:) ] if ;
|
os macosx? [ (C-FRAMEWORK:) ] [ (C-LINK:) ] if ;
|
||||||
|
|
||||||
SYNTAX: C-INCLUDE:
|
SYNTAX: C-INCLUDE:
|
||||||
"#include " scan append "c-library-vector" get push ;
|
"#include " scan append c-strings get push ;
|
||||||
|
|
||||||
SYNTAX: C-FUNCTION:
|
SYNTAX: C-FUNCTION:
|
||||||
return-library-function-params
|
return-library-function-params
|
||||||
[ factor-function ]
|
[ factor-function ]
|
||||||
4 nkeep (C-FUNCTION:)
|
4 nkeep (C-FUNCTION:)
|
||||||
" {\n" append parse-here append "\n}\n" append
|
" {\n" append parse-here append "\n}\n" append
|
||||||
"c-library-vector" get push ;
|
c-strings get push ;
|
||||||
|
|
||||||
SYNTAX: ;C-LIBRARY (;C-LIBRARY) ;
|
SYNTAX: ;C-LIBRARY (;C-LIBRARY) ;
|
||||||
|
|
|
@ -3,6 +3,9 @@ io.encodings.ascii io.files io.files.temp io.launcher kernel
|
||||||
locals sequences system ;
|
locals sequences system ;
|
||||||
IN: alien.compile
|
IN: alien.compile
|
||||||
|
|
||||||
|
SYMBOL: C
|
||||||
|
SYMBOL: C++
|
||||||
|
|
||||||
: library-suffix ( -- str )
|
: library-suffix ( -- str )
|
||||||
os {
|
os {
|
||||||
{ [ dup macosx? ] [ drop ".dylib" ] }
|
{ [ dup macosx? ] [ drop ".dylib" ] }
|
||||||
|
|
Loading…
Reference in New Issue