alien.inline: prepend vocab name to c-library name

db4
Jeremy Hughes 2009-07-07 20:51:31 +12:00
parent e046605473
commit c478fa9f1b
3 changed files with 18 additions and 13 deletions

View File

@ -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 -- )

View File

@ -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 >>

View File

@ -5,7 +5,7 @@ alien.libraries alien.parser arrays assocs combinators effects
fry generalizations grouping io.files io.files.info io.files.temp
kernel lexer locals math math.order math.ranges multiline
namespaces quotations sequences source-files splitting strings
system vocabs.loader vocabs.parser words ;
system vocabs.loader words ;
IN: alien.inline
SYMBOL: c-library
@ -21,12 +21,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 ;
@ -67,7 +63,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