From e04efe5f5acedd74d82298ac1b0269de52b5082f Mon Sep 17 00:00:00 2001 From: sheeple Date: Fri, 27 Mar 2009 10:41:24 -0500 Subject: [PATCH 1/6] use .a instead of .so on unix --- basis/compiler/tests/alien.factor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/basis/compiler/tests/alien.factor b/basis/compiler/tests/alien.factor index 7d65ea7103..c65fed55e2 100644 --- a/basis/compiler/tests/alien.factor +++ b/basis/compiler/tests/alien.factor @@ -13,7 +13,7 @@ IN: compiler.tests { { [ os winnt? ] [ "libfactor-ffi-test.dll" ] } { [ os macosx? ] [ "libfactor-ffi-test.dylib" ] } - { [ os unix? ] [ "libfactor-ffi-test.so" ] } + { [ os unix? ] [ "libfactor-ffi-test.a" ] } } cond append-path ; "f-cdecl" libfactor-ffi-tests-path "cdecl" add-library From 1cf5c519ccb836a8e386626246d6d2e94b626040 Mon Sep 17 00:00:00 2001 From: sheeple Date: Fri, 27 Mar 2009 14:39:45 -0500 Subject: [PATCH 2/6] fix ffi tests on 32bit --- basis/compiler/tests/alien.factor | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/basis/compiler/tests/alien.factor b/basis/compiler/tests/alien.factor index c65fed55e2..8d876891f2 100644 --- a/basis/compiler/tests/alien.factor +++ b/basis/compiler/tests/alien.factor @@ -21,8 +21,6 @@ IN: compiler.tests "f-stdcall" libfactor-ffi-tests-path "stdcall" add-library >> -LIBRARY: f-cdecl - FUNCTION: void ffi_test_0 ; [ ] [ ffi_test_0 ] unit-test @@ -124,8 +122,6 @@ unit-test "int" { "int" "int" "int" "int" } "stdcall" alien-indirect gc ; -LIBRARY: f-stdcall - [ f ] [ "f-stdcall" load-library f = ] unit-test [ "stdcall" ] [ "f-stdcall" library abi>> ] unit-test @@ -166,7 +162,7 @@ FUNCTION: void ffi_test_20 double x1, double x2, double x3, : ffi_test_31 ( a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a -- result y ) "int" - "f-stdcall" "ffi_test_31" + "f-cdecl" "ffi_test_31" { "int" "int" "int" "int" "int" "int" "int" "int" "int" "int" "int" "int" "int" "int" "int" "int" "int" "int" "int" "int" "int" "int" "int" "int" "int" "int" "int" "int" "int" "int" "int" "int" "int" "int" "int" "int" "int" "int" "int" "int" "int" "int" } alien-invoke gc 3 ; @@ -174,7 +170,7 @@ FUNCTION: void ffi_test_20 double x1, double x2, double x3, : ffi_test_31_point_5 ( a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a -- result ) "float" - "f-stdcall" "ffi_test_31_point_5" + "cdecl" "ffi_test_31_point_5" { "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" } alien-invoke ; From 45ed9b3b801173a85b76f691f025a5a1bf1395a9 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Fri, 27 Mar 2009 15:39:13 -0500 Subject: [PATCH 3/6] use -fPIC on all platforms for ffi lib --- Makefile | 1 + vm/Config.linux.x86.64 | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 3f385ec496..ddfe916742 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,7 @@ IMAGE = factor.image BUNDLE = Factor.app LIBPATH = -L/usr/X11R6/lib CFLAGS = -Wall +FFI_TEST_CFLAGS = -fPIC ifdef DEBUG CFLAGS += -g diff --git a/vm/Config.linux.x86.64 b/vm/Config.linux.x86.64 index a02fcb4d6d..bfd1222496 100644 --- a/vm/Config.linux.x86.64 +++ b/vm/Config.linux.x86.64 @@ -1,4 +1,3 @@ include vm/Config.linux include vm/Config.x86.64 LIBPATH = -L/usr/X11R6/lib64 -L/usr/X11R6/lib -FFI_TEST_CFLAGS = -fPIC From 6f743b280de79c55706b6614b157993f51b7ba76 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Fri, 27 Mar 2009 17:58:31 -0500 Subject: [PATCH 4/6] hopefully last fix for alien.factor --- basis/compiler/tests/alien.factor | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/basis/compiler/tests/alien.factor b/basis/compiler/tests/alien.factor index 8d876891f2..6802b43de6 100644 --- a/basis/compiler/tests/alien.factor +++ b/basis/compiler/tests/alien.factor @@ -21,6 +21,8 @@ IN: compiler.tests "f-stdcall" libfactor-ffi-tests-path "stdcall" add-library >> +LIBRARY: f-cdecl + FUNCTION: void ffi_test_0 ; [ ] [ ffi_test_0 ] unit-test @@ -170,7 +172,7 @@ FUNCTION: void ffi_test_20 double x1, double x2, double x3, : ffi_test_31_point_5 ( a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a -- result ) "float" - "cdecl" "ffi_test_31_point_5" + "f-cdecl" "ffi_test_31_point_5" { "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" "float" } alien-invoke ; From c7925940958ae58337a959f99369fb8a822efe00 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Fri, 27 Mar 2009 18:55:43 -0500 Subject: [PATCH 5/6] use CONSTANT: in roman --- basis/roman/roman.factor | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/basis/roman/roman.factor b/basis/roman/roman.factor index 71343b723d..4991d5b243 100644 --- a/basis/roman/roman.factor +++ b/basis/roman/roman.factor @@ -8,11 +8,11 @@ IN: roman Date: Fri, 27 Mar 2009 19:55:34 -0500 Subject: [PATCH 6/6] redo the roman ops with smart combinators --- basis/roman/roman-docs.factor | 12 ++++----- basis/roman/roman-tests.factor | 6 +++++ basis/roman/roman.factor | 48 ++++++++++++++++------------------ 3 files changed, 34 insertions(+), 32 deletions(-) diff --git a/basis/roman/roman-docs.factor b/basis/roman/roman-docs.factor index 4a8197f064..bef0ab90fc 100644 --- a/basis/roman/roman-docs.factor +++ b/basis/roman/roman-docs.factor @@ -1,6 +1,6 @@ ! Copyright (C) 2008 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. -USING: help.markup help.syntax kernel math ; +USING: help.markup help.syntax kernel math strings ; IN: roman HELP: >roman @@ -39,7 +39,7 @@ HELP: roman> { >roman >ROMAN roman> } related-words HELP: roman+ -{ $values { "str1" "a string" } { "str2" "a string" } { "str3" "a string" } } +{ $values { "string" string } { "string" string } { "string" string } } { $description "Adds two Roman numerals." } { $examples { $example "USING: io roman ;" @@ -49,7 +49,7 @@ HELP: roman+ } ; HELP: roman- -{ $values { "str1" "a string" } { "str2" "a string" } { "str3" "a string" } } +{ $values { "string" string } { "string" string } { "string" string } } { $description "Subtracts two Roman numerals." } { $examples { $example "USING: io roman ;" @@ -61,7 +61,7 @@ HELP: roman- { roman+ roman- } related-words HELP: roman* -{ $values { "str1" "a string" } { "str2" "a string" } { "str3" "a string" } } +{ $values { "string" string } { "string" string } { "string" string } } { $description "Multiplies two Roman numerals." } { $examples { $example "USING: io roman ;" @@ -71,7 +71,7 @@ HELP: roman* } ; HELP: roman/i -{ $values { "str1" "a string" } { "str2" "a string" } { "str3" "a string" } } +{ $values { "string" string } { "string" string } { "string" string } } { $description "Computes the integer division of two Roman numerals." } { $examples { $example "USING: io roman ;" @@ -81,7 +81,7 @@ HELP: roman/i } ; HELP: roman/mod -{ $values { "str1" "a string" } { "str2" "a string" } { "str3" "a string" } { "str4" "a string" } } +{ $values { "string" string } { "string" string } { "string" string } { "string" string } } { $description "Computes the quotient and remainder of two Roman numerals." } { $examples { $example "USING: kernel io roman ;" diff --git a/basis/roman/roman-tests.factor b/basis/roman/roman-tests.factor index 82084e0b1f..a510514e23 100644 --- a/basis/roman/roman-tests.factor +++ b/basis/roman/roman-tests.factor @@ -38,3 +38,9 @@ USING: arrays kernel math roman roman.private sequences tools.test ; [ "iii" "iii" roman- ] must-fail [ 30 ] [ ROMAN: xxx ] unit-test + +[ roman+ ] must-infer +[ roman- ] must-infer +[ roman* ] must-infer +[ roman/i ] must-infer +[ roman/mod ] must-infer diff --git a/basis/roman/roman.factor b/basis/roman/roman.factor index 4991d5b243..f191323992 100644 --- a/basis/roman/roman.factor +++ b/basis/roman/roman.factor @@ -1,9 +1,10 @@ ! Copyright (C) 2007 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. -USING: arrays assocs kernel math math.order math.vectors -namespaces make quotations sequences splitting.monotonic -sequences.private strings unicode.case lexer parser -grouping ; +USING: accessors arrays assocs fry generalizations grouping +kernel lexer macros make math math.order math.vectors +namespaces parser quotations sequences sequences.private +splitting.monotonic stack-checker strings unicode.case +words effects ; IN: roman : >roman ( n -- str ) - dup roman-range-check - [ (>roman) ] "" make ; + dup roman-range-check [ (>roman) ] "" make ; : >ROMAN ( n -- str ) >roman >upper ; : roman> ( str -- n ) - >lower [ roman<= ] monotonic-split - [ (roman>) ] sigma ; + >lower [ roman<= ] monotonic-split [ (roman>) ] sigma ; ( str1 str2 -- m n ) - [ roman> ] bi@ ; - -: binary-roman-op ( str1 str2 quot -- str3 ) - [ 2roman> ] dip call >roman ; inline +MACRO: binary-roman-op ( quot -- quot' ) + dup infer [ in>> swap ] [ out>> ] bi + '[ [ roman> ] _ napply @ [ >roman ] _ napply ] ; PRIVATE> -: roman+ ( str1 str2 -- str3 ) - [ + ] binary-roman-op ; +<< +SYNTAX: ROMAN-OP: + scan-word [ name>> "roman" prepend create-in ] keep + 1quotation '[ _ binary-roman-op ] + dup infer [ in>> ] [ out>> ] bi + [ "string" ] bi@ define-declared ; +>> -: roman- ( str1 str2 -- str3 ) - [ - ] binary-roman-op ; - -: roman* ( str1 str2 -- str3 ) - [ * ] binary-roman-op ; - -: roman/i ( str1 str2 -- str3 ) - [ /i ] binary-roman-op ; - -: roman/mod ( str1 str2 -- str3 str4 ) - [ /mod ] binary-roman-op [ >roman ] dip ; +ROMAN-OP: + +ROMAN-OP: - +ROMAN-OP: * +ROMAN-OP: /i +ROMAN-OP: /mod SYNTAX: ROMAN: scan roman> parsed ;