Merge branch 'inlinec' of git://github.com/jedahu/factor
commit
d03a8dff44
basis/alien/inline
|
@ -0,0 +1,77 @@
|
|||
! Copyright (C) 2009 Jeremy Hughes.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: help.markup help.syntax kernel strings words.symbol sequences ;
|
||||
IN: alien.inline.compiler
|
||||
|
||||
HELP: C
|
||||
{ $var-description "A symbol representing C source." } ;
|
||||
|
||||
HELP: C++
|
||||
{ $var-description "A symbol representing C++ source." } ;
|
||||
|
||||
HELP: compile-to-library
|
||||
{ $values
|
||||
{ "lang" symbol } { "args" sequence } { "contents" string } { "name" string }
|
||||
}
|
||||
{ $description "Compiles and links " { $snippet "contents" } " into a shared library called " { $snippet "libname.suffix" }
|
||||
"in " { $snippet "resource:alien-inline-libs" } ". " { $snippet "suffix" } " is OS specific. "
|
||||
{ $snippet "args" } " is a sequence of arguments for the linking stage." }
|
||||
{ $notes
|
||||
{ $list
|
||||
"C and C++ are the only supported languages."
|
||||
{ "Source and object files are placed in " { $snippet "resource:temp" } "." } }
|
||||
} ;
|
||||
|
||||
HELP: compiler
|
||||
{ $values
|
||||
{ "lang" symbol }
|
||||
{ "str" string }
|
||||
}
|
||||
{ $description "Returns a compiler name based on OS and source language." }
|
||||
{ $see-also compiler-descr } ;
|
||||
|
||||
HELP: compiler-descr
|
||||
{ $values
|
||||
{ "lang" symbol }
|
||||
{ "descr" "a process description" }
|
||||
}
|
||||
{ $description "Returns a compiler process description based on OS and source language." }
|
||||
{ $see-also compiler } ;
|
||||
|
||||
HELP: inline-library-file
|
||||
{ $values
|
||||
{ "name" string }
|
||||
{ "path" "a pathname string" }
|
||||
}
|
||||
{ $description "Appends " { $snippet "name" } " to the " { $link inline-libs-directory } "." } ;
|
||||
|
||||
HELP: inline-libs-directory
|
||||
{ $values
|
||||
{ "path" "a pathname string" }
|
||||
}
|
||||
{ $description "The directory where libraries created using " { $snippet "alien.inline" } " are stored." } ;
|
||||
|
||||
HELP: library-path
|
||||
{ $values
|
||||
{ "str" string }
|
||||
{ "path" "a pathname string" }
|
||||
}
|
||||
{ $description "Converts " { $snippet "name" } " into a full path to the corresponding inline library." } ;
|
||||
|
||||
HELP: library-suffix
|
||||
{ $values
|
||||
{ "str" string }
|
||||
}
|
||||
{ $description "The appropriate shared library suffix for the current OS." } ;
|
||||
|
||||
HELP: link-descr
|
||||
{ $values
|
||||
{ "descr" sequence }
|
||||
}
|
||||
{ $description "Returns part of a process description. OS dependent." } ;
|
||||
|
||||
ARTICLE: "alien.inline.compiler" "Inline C compiler"
|
||||
{ $vocab-link "alien.inline.compiler" }
|
||||
;
|
||||
|
||||
ABOUT: "alien.inline.compiler"
|
|
@ -22,14 +22,8 @@ SYMBOL: C++
|
|||
{ [ dup windows? ] [ drop ".dll" ] }
|
||||
} cond ;
|
||||
|
||||
: library-path ( str -- str' )
|
||||
'[ "lib" % _ % library-suffix % ] "" make temp-file ;
|
||||
|
||||
: src-suffix ( lang -- str )
|
||||
{
|
||||
{ C [ ".c" ] }
|
||||
{ C++ [ ".cpp" ] }
|
||||
} case ;
|
||||
: library-path ( str -- path )
|
||||
'[ "lib" % _ % library-suffix % ] "" make inline-library-file ;
|
||||
|
||||
HOOK: compiler os ( lang -- str )
|
||||
|
||||
|
@ -59,8 +53,16 @@ M: macosx link-descr
|
|||
{ "-g" "-prebind" "-dynamiclib" "-o" }
|
||||
cpu x86.64? [ { "-arch" "x86_64" } prepend ] when ;
|
||||
|
||||
: link-command ( in out lang -- descr )
|
||||
compiler-descr link-descr append prepend prepend ;
|
||||
<PRIVATE
|
||||
: src-suffix ( lang -- str )
|
||||
{
|
||||
{ C [ ".c" ] }
|
||||
{ C++ [ ".cpp" ] }
|
||||
} case ;
|
||||
|
||||
: link-command ( args in out lang -- descr )
|
||||
[ 2array ] dip compiler-descr link-descr
|
||||
append prepend prepend ;
|
||||
|
||||
:: compile-to-object ( lang contents name -- )
|
||||
name ".o" append temp-file
|
||||
|
@ -71,8 +73,9 @@ M: macosx link-descr
|
|||
|
||||
:: link-object ( lang args name -- )
|
||||
args name [ library-path ]
|
||||
[ ".o" append temp-file ] bi 2array
|
||||
[ ".o" append temp-file ] bi
|
||||
lang link-command try-process ;
|
||||
PRIVATE>
|
||||
|
||||
:: compile-to-library ( lang args contents name -- )
|
||||
lang contents name compile-to-object
|
||||
|
|
|
@ -12,11 +12,11 @@ IN: alien.inline
|
|||
<PRIVATE
|
||||
SYMBOL: c-library
|
||||
SYMBOL: library-is-c++
|
||||
SYMBOL: compiler-args
|
||||
SYMBOL: linker-args
|
||||
SYMBOL: c-strings
|
||||
|
||||
: cleanup-variables ( -- )
|
||||
{ c-library library-is-c++ compiler-args c-strings }
|
||||
{ c-library library-is-c++ linker-args c-strings }
|
||||
[ off ] each ;
|
||||
|
||||
: function-types-effect ( -- function types effect )
|
||||
|
@ -56,7 +56,7 @@ SYMBOL: c-strings
|
|||
|
||||
: compile-library ( -- )
|
||||
library-is-c++ get [ C++ ] [ C ] if
|
||||
compiler-args get
|
||||
linker-args get
|
||||
c-strings get "\n" join
|
||||
c-library get compile-to-library ;
|
||||
|
||||
|
@ -67,7 +67,7 @@ PRIVATE>
|
|||
: define-c-library ( name -- )
|
||||
c-library-name c-library set
|
||||
V{ } clone c-strings set
|
||||
V{ } clone compiler-args set ;
|
||||
V{ } clone linker-args set ;
|
||||
|
||||
: compile-c-library ( -- )
|
||||
compile-library? [ compile-library ] when
|
||||
|
@ -87,10 +87,10 @@ PRIVATE>
|
|||
] dip append-function-body c-strings get push ;
|
||||
|
||||
: c-link-to ( str -- )
|
||||
"-l" prepend compiler-args get push ;
|
||||
"-l" prepend linker-args get push ;
|
||||
|
||||
: c-use-framework ( str -- )
|
||||
"-framework" swap compiler-args get '[ _ push ] bi@ ;
|
||||
"-framework" swap linker-args get '[ _ push ] bi@ ;
|
||||
|
||||
: c-link-to/use-framework ( str -- )
|
||||
os macosx? [ c-use-framework ] [ c-link-to ] if ;
|
||||
|
|
Loading…
Reference in New Issue