From fca8ba3d0a5a4ae226865c597224cebf0de098d0 Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Thu, 1 Apr 2010 02:22:42 -0700 Subject: [PATCH] add fastcall functions to ffi tests --- basis/compiler/tests/alien.factor | 22 ++++++++++++++++++++++ vm/ffi_test.c | 24 ++++++++++++++++++++++++ vm/ffi_test.h | 12 ++++++++++++ 3 files changed, 58 insertions(+) diff --git a/basis/compiler/tests/alien.factor b/basis/compiler/tests/alien.factor index 71efe8a929..08ff47ee5a 100755 --- a/basis/compiler/tests/alien.factor +++ b/basis/compiler/tests/alien.factor @@ -22,6 +22,8 @@ IN: compiler.tests.alien "f-cdecl" libfactor-ffi-tests-path cdecl add-library "f-stdcall" libfactor-ffi-tests-path stdcall add-library + +"f-fastcall" libfactor-ffi-tests-path fastcall add-library >> LIBRARY: f-cdecl @@ -603,3 +605,23 @@ FUNCTION: void this_does_not_exist ( ) ; : assembly-test-1 ( -- ) void { } cdecl [ ] alien-assembly ; [ ] [ assembly-test-1 ] unit-test + +LIBRARY: f-fastcall + +FUNCTION: int ffi_test_49 ( int x ) ; +FUNCTION: int ffi_test_50 ( int x, int y ) ; +FUNCTION: int ffi_test_51 ( int x, int y, int z ) ; +FUNCTION: int ffi_test_52 ( int x, float y, int z ) ; +FUNCTION: int ffi_test_53 ( int x, float y, int z, int w ) ; +FUNCTION: int ffi_test_54 ( test-struct-11 x, int y ) ; +FUNCTION: int ffi_test_55 ( int x, int y, int z ) ; +FUNCTION: int ffi_test_56 ( int x, int y, int z ) ; + +[ 4 ] [ 3 ffi_test_49 ] unit-test +[ 8 ] [ 3 4 ffi_test_50 ] unit-test +[ 13 ] [ 3 4 5 ffi_test_51 ] unit-test +[ 13 ] [ 3 4.0 5 ffi_test_52 ] unit-test +[ 19 ] [ 3 4.0 5 6 ffi_test_53 ] unit-test +[ 13 ] [ 3 4 test-struct-11 5 ffi_test_54 ] unit-test +[ 19 ] [ 3 4 test-struct-11 5 6 ffi_test_55 ] unit-test +[ 26 ] [ 3 4 test-struct-11 5 6 7 ffi_test_56 ] unit-test diff --git a/vm/ffi_test.c b/vm/ffi_test.c index 11f7498f30..6ad9a26b27 100755 --- a/vm/ffi_test.c +++ b/vm/ffi_test.c @@ -329,3 +329,27 @@ short ffi_test_48(struct bool_field_test x) } #endif + +FACTOR_FASTCALL(int) ffi_test_49(int x) { return x + 1; } +FACTOR_FASTCALL(int) ffi_test_50(int x, int y) { return x + y + 1; } +FACTOR_FASTCALL(int) ffi_test_51(int x, int y, int z) { return x + y + z + 1; } +FACTOR_FASTCALL(int) ffi_test_52(int x, float y, int z) { return x + y + z + 1; } +FACTOR_FASTCALL(int) ffi_test_53(int x, float y, int z, int w) +{ + return x + y + z + w + 1; +} + +FACTOR_FASTCALL(int) ffi_test_54(test_struct_11 x, int y) +{ + return x.x + x.y + y + 1; +} + +FACTOR_FASTCALL(int) ffi_test_55(test_struct_11 x, int y, int z) +{ + return x.x + x.y + y + z + 1; +} + +FACTOR_FASTCALL(int) ffi_test_56(test_struct_11 x, int y, int z, int w) +{ + return x.x + x.y + y + z + w + 1; +} diff --git a/vm/ffi_test.h b/vm/ffi_test.h index c61c95d6df..0ee593a26e 100755 --- a/vm/ffi_test.h +++ b/vm/ffi_test.h @@ -1,9 +1,12 @@ #if defined(_MSC_VER) #define FACTOR_STDCALL(return_type) return_type __stdcall + #define FACTOR_FASTCALL(return_type) return_type __fastcall #elif defined(i386) || defined(__i386) || defined(__i386__) #define FACTOR_STDCALL(return_type) __attribute__((stdcall)) return_type + #define FACTOR_FASTCALL(return_type) __attribute__((fastcall)) return_type #else #define FACTOR_STDCALL(return_type) return_type + #define FACTOR_FASTCALL(return_type) return_type #endif #if defined(__APPLE__) @@ -119,3 +122,12 @@ struct bool_field_test { FACTOR_EXPORT short ffi_test_48(struct bool_field_test x); #endif + +FACTOR_EXPORT FACTOR_FASTCALL(int) ffi_test_49(int x); +FACTOR_EXPORT FACTOR_FASTCALL(int) ffi_test_50(int x, int y); +FACTOR_EXPORT FACTOR_FASTCALL(int) ffi_test_51(int x, int y, int z); +FACTOR_EXPORT FACTOR_FASTCALL(int) ffi_test_52(int x, float y, int z); +FACTOR_EXPORT FACTOR_FASTCALL(int) ffi_test_53(int x, float y, int z, int w); +FACTOR_EXPORT FACTOR_FASTCALL(int) ffi_test_54(test_struct_11 x, int y); +FACTOR_EXPORT FACTOR_FASTCALL(int) ffi_test_55(test_struct_11 x, int y, int z); +FACTOR_EXPORT FACTOR_FASTCALL(int) ffi_test_56(test_struct_11 x, int y, int z, int w);