alien.inline: prepend vocab name to c-library name
Conflicts: basis/alien/inline/inline.factordb4
parent
a5653f3449
commit
e140d80d71
|
@ -2,7 +2,7 @@
|
|||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: accessors arrays combinators fry generalizations
|
||||
io.encodings.ascii io.files io.files.temp io.launcher kernel
|
||||
locals sequences system words ;
|
||||
locals make sequences system vocabs.parser words ;
|
||||
IN: alien.inline.compiler
|
||||
|
||||
SYMBOL: C
|
||||
|
@ -15,6 +15,12 @@ SYMBOL: C++
|
|||
{ [ dup windows? ] [ drop ".dll" ] }
|
||||
} cond ;
|
||||
|
||||
: library-path ( str -- str' )
|
||||
'[
|
||||
"lib-" % current-vocab name>> %
|
||||
"-" % _ % library-suffix %
|
||||
] "" make temp-file ;
|
||||
|
||||
: src-suffix ( lang -- str )
|
||||
{
|
||||
{ C [ ".c" ] }
|
||||
|
@ -52,8 +58,8 @@ M: macosx link-descr
|
|||
try-process ;
|
||||
|
||||
:: link-object ( lang args name -- )
|
||||
args name [ "lib" prepend library-suffix append ]
|
||||
[ ".o" append ] bi [ temp-file ] bi@ 2array
|
||||
args name [ library-path ]
|
||||
[ ".o" append temp-file ] bi 2array
|
||||
lang link-command try-process ;
|
||||
|
||||
:: compile-to-library ( lang args contents name -- )
|
||||
|
|
|
@ -15,7 +15,8 @@ C-FUNCTION: const-int add ( int a, int b )
|
|||
{ 2 1 } [ add ] must-infer-as
|
||||
[ 5 ] [ 2 3 add ] unit-test
|
||||
|
||||
<< library-path dup exists? [ delete-file ] [ drop ] if >>
|
||||
<< c-library get library-path dup exists?
|
||||
[ delete-file ] [ drop ] if >>
|
||||
|
||||
|
||||
C-LIBRARY: cpplib
|
||||
|
@ -34,7 +35,8 @@ C-FUNCTION: const-char* hello ( )
|
|||
{ 0 1 } [ hello ] must-infer-as
|
||||
[ "hello world" ] [ hello ] unit-test
|
||||
|
||||
<< library-path dup exists? [ delete-file ] [ drop ] if >>
|
||||
<< c-library get library-path dup exists?
|
||||
[ delete-file ] [ drop ] if >>
|
||||
|
||||
|
||||
C-LIBRARY: compile-error
|
||||
|
@ -45,4 +47,5 @@ C-FUNCTION: char* breakme ( )
|
|||
|
||||
<< [ compile-c-library ] must-fail >>
|
||||
|
||||
<< library-path dup exists? [ delete-file ] [ drop ] if >>
|
||||
<< c-library get library-path dup exists?
|
||||
[ delete-file ] [ drop ] if >>
|
||||
|
|
|
@ -41,13 +41,8 @@ SYMBOL: c-strings
|
|||
: append-function-body ( prototype-str -- str )
|
||||
" {\n" append parse-here append "\n}\n" append ;
|
||||
|
||||
|
||||
: library-path ( -- str )
|
||||
"lib" c-library get library-suffix
|
||||
3array concat temp-file ;
|
||||
|
||||
: compile-library? ( -- ? )
|
||||
library-path dup exists? [
|
||||
c-library get library-path dup exists? [
|
||||
file get path>>
|
||||
[ file-info modified>> ] bi@ <=> +lt+ =
|
||||
] [ drop t ] if ;
|
||||
|
@ -66,7 +61,7 @@ PRIVATE>
|
|||
|
||||
: compile-c-library ( -- )
|
||||
compile-library? [ compile-library ] when
|
||||
c-library get library-path "cdecl" add-library ;
|
||||
c-library get dup library-path "cdecl" add-library ;
|
||||
|
||||
: define-c-function ( function types effect -- )
|
||||
[ factor-function define-declared ] 3keep prototype-string
|
||||
|
|
Loading…
Reference in New Issue