From e140d80d717eed9ab0a839ae37a7c5481fecadc6 Mon Sep 17 00:00:00 2001 From: Jeremy Hughes Date: Wed, 8 Jul 2009 09:43:19 +1200 Subject: [PATCH 1/3] alien.inline: prepend vocab name to c-library name Conflicts: basis/alien/inline/inline.factor --- basis/alien/inline/compiler/compiler.factor | 12 +++++++++--- basis/alien/inline/inline-tests.factor | 9 ++++++--- basis/alien/inline/inline.factor | 9 ++------- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/basis/alien/inline/compiler/compiler.factor b/basis/alien/inline/compiler/compiler.factor index 2f5fd29aff..d9f87a9f3b 100644 --- a/basis/alien/inline/compiler/compiler.factor +++ b/basis/alien/inline/compiler/compiler.factor @@ -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 -- ) diff --git a/basis/alien/inline/inline-tests.factor b/basis/alien/inline/inline-tests.factor index acd2d615cd..60e6b3b594 100644 --- a/basis/alien/inline/inline-tests.factor +++ b/basis/alien/inline/inline-tests.factor @@ -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 >> diff --git a/basis/alien/inline/inline.factor b/basis/alien/inline/inline.factor index 365b56ca28..5ddd95a4cd 100644 --- a/basis/alien/inline/inline.factor +++ b/basis/alien/inline/inline.factor @@ -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 From b421a360c078f95b15af9528a4a6ae1e31e9ab98 Mon Sep 17 00:00:00 2001 From: Jeremy Hughes Date: Wed, 8 Jul 2009 09:45:08 +1200 Subject: [PATCH 2/3] alien.inline: added DELETE-C-LIBRARY: word, mainly for tests Conflicts: basis/alien/inline/inline.factor --- basis/alien/inline/inline-tests.factor | 13 +++++-------- basis/alien/inline/inline.factor | 13 +++++++++---- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/basis/alien/inline/inline-tests.factor b/basis/alien/inline/inline-tests.factor index 60e6b3b594..837f27ceb7 100644 --- a/basis/alien/inline/inline-tests.factor +++ b/basis/alien/inline/inline-tests.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2009 Jeremy Hughes. ! See http://factorcode.org/license.txt for BSD license. -USING: tools.test alien.inline alien.inline.private io.files -io.directories kernel ; +USING: alien.inline alien.inline.private io.directories io.files +kernel namespaces tools.test ; IN: alien.inline.tests C-LIBRARY: const @@ -15,8 +15,7 @@ C-FUNCTION: const-int add ( int a, int b ) { 2 1 } [ add ] must-infer-as [ 5 ] [ 2 3 add ] unit-test -<< c-library get library-path dup exists? -[ delete-file ] [ drop ] if >> +DELETE-C-LIBRARY: const C-LIBRARY: cpplib @@ -35,8 +34,7 @@ C-FUNCTION: const-char* hello ( ) { 0 1 } [ hello ] must-infer-as [ "hello world" ] [ hello ] unit-test -<< c-library get library-path dup exists? -[ delete-file ] [ drop ] if >> +DELETE-C-LIBRARY: cpplib C-LIBRARY: compile-error @@ -47,5 +45,4 @@ C-FUNCTION: char* breakme ( ) << [ compile-c-library ] must-fail >> -<< c-library get library-path dup exists? -[ delete-file ] [ drop ] if >> +DELETE-C-LIBRARY: compile-error diff --git a/basis/alien/inline/inline.factor b/basis/alien/inline/inline.factor index 5ddd95a4cd..c658c6ed3a 100644 --- a/basis/alien/inline/inline.factor +++ b/basis/alien/inline/inline.factor @@ -2,10 +2,10 @@ ! See http://factorcode.org/license.txt for BSD license. USING: accessors alien.inline.compiler alien.inline.types alien.libraries alien.parser arrays assocs effects fry -generalizations grouping io.files io.files.info io.files.temp -kernel lexer math math.order math.ranges multiline namespaces -sequences source-files splitting strings system vocabs.loader -vocabs.parser words ; +generalizations grouping io.directories io.files +io.files.info io.files.temp kernel lexer math math.order +math.ranges multiline namespaces sequences source-files +splitting strings system vocabs.loader vocabs.parser words ; IN: alien.inline : define-c-include ( str -- ) "#include " prepend c-strings get push ; +: delete-inline-library ( str -- ) + library-path dup exists? [ delete-file ] [ drop ] if ; + SYNTAX: C-LIBRARY: scan define-c-library ; SYNTAX: COMPILE-AS-C++ t library-is-c++ set ; @@ -100,3 +103,5 @@ SYNTAX: C-FUNCTION: function-types-effect define-c-function ; SYNTAX: ;C-LIBRARY compile-c-library ; + +SYNTAX: DELETE-C-LIBRARY: scan delete-inline-library ; From 1c42ebd89e2182482109e219fe8926d293a49003 Mon Sep 17 00:00:00 2001 From: Jeremy Hughes Date: Wed, 8 Jul 2009 09:29:41 +1200 Subject: [PATCH 3/3] alien.inline: allow compiling from non-file vocabs --- basis/alien/inline/inline.factor | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/basis/alien/inline/inline.factor b/basis/alien/inline/inline.factor index c658c6ed3a..07f4693446 100644 --- a/basis/alien/inline/inline.factor +++ b/basis/alien/inline/inline.factor @@ -43,8 +43,10 @@ SYMBOL: c-strings : compile-library? ( -- ? ) c-library get library-path dup exists? [ - file get path>> - [ file-info modified>> ] bi@ <=> +lt+ = + file get [ + path>> + [ file-info modified>> ] bi@ <=> +lt+ = + ] [ drop t ] if* ] [ drop t ] if ; : compile-library ( -- )