From b03b76996615a3e984e57b13d523f3901ba4cde1 Mon Sep 17 00:00:00 2001 From: Jeremy Hughes <jedahu@gmail.com> Date: Sat, 11 Jul 2009 19:23:21 +1200 Subject: [PATCH 1/3] alien.inline: renamed compiler-args to linker-args --- basis/alien/inline/inline.factor | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/basis/alien/inline/inline.factor b/basis/alien/inline/inline.factor index 1df77d6600..1b1820779c 100644 --- a/basis/alien/inline/inline.factor +++ b/basis/alien/inline/inline.factor @@ -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 ; From eb72ba84f613ae5e5d3be6d018e33fdf3832558f Mon Sep 17 00:00:00 2001 From: Jeremy Hughes <jedahu@gmail.com> Date: Sat, 11 Jul 2009 19:23:49 +1200 Subject: [PATCH 2/3] alien.inline.compiler: fixed library-path and made other words private --- basis/alien/inline/compiler/compiler.factor | 25 ++++++++++++--------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/basis/alien/inline/compiler/compiler.factor b/basis/alien/inline/compiler/compiler.factor index d7d2d6fc43..4abc78ff67 100644 --- a/basis/alien/inline/compiler/compiler.factor +++ b/basis/alien/inline/compiler/compiler.factor @@ -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 From f2380aab7fc0f86fb0ee0f90ffd36d9ba71e76a3 Mon Sep 17 00:00:00 2001 From: Jeremy Hughes <jedahu@gmail.com> Date: Sat, 11 Jul 2009 19:24:09 +1200 Subject: [PATCH 3/3] alien.inline.compiler: documentation --- .../inline/compiler/compiler-docs.factor | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 basis/alien/inline/compiler/compiler-docs.factor diff --git a/basis/alien/inline/compiler/compiler-docs.factor b/basis/alien/inline/compiler/compiler-docs.factor new file mode 100644 index 0000000000..28e2538e1f --- /dev/null +++ b/basis/alien/inline/compiler/compiler-docs.factor @@ -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"