From d584e8c0bb9901e5937265e438d8e14b1305177f Mon Sep 17 00:00:00 2001 From: slava Date: Tue, 14 Feb 2006 03:47:42 +0000 Subject: [PATCH] Basic callback unit tests pass --- TODO.FACTOR.txt | 3 +-- library/alien/alien-callback.factor | 2 +- library/compiler/ppc/alien.factor | 4 +++- library/test/compiler/callbacks.factor | 29 +++++++++++++++++++------- native/ffi_test.c | 10 +++++++++ 5 files changed, 36 insertions(+), 12 deletions(-) diff --git a/TODO.FACTOR.txt b/TODO.FACTOR.txt index 343ebe81bd..ab8cc05d3e 100644 --- a/TODO.FACTOR.txt +++ b/TODO.FACTOR.txt @@ -53,8 +53,7 @@ - out of memory from overflow check - remove literal table - callbacks - - zero-arity - - return-only + - return values - input values - value type struct inputs - ffi unicode strings: null char security hole diff --git a/library/alien/alien-callback.factor b/library/alien/alien-callback.factor index a83ef4c7a7..4cac284be4 100644 --- a/library/alien/alien-callback.factor +++ b/library/alien/alien-callback.factor @@ -33,7 +33,7 @@ M: alien-callback-error summary ( error -- ) ] "infer" set-word-prop : box-parameters ( parameters -- ) - [ box-parameter , ] reverse-each-parameter ; + [ box-parameter , ] each-parameter ; : registers>objects ( parameters -- ) #! The corresponding unnest_stacks() call is made by the diff --git a/library/compiler/ppc/alien.factor b/library/compiler/ppc/alien.factor index ec4511cf99..c6636feda5 100644 --- a/library/compiler/ppc/alien.factor +++ b/library/compiler/ppc/alien.factor @@ -53,7 +53,9 @@ M: %box generate-node ( vop -- ) ! If the source is a stack location, load it into freg #0. ! If the source is f, then we assume the value is already in ! freg #0. - 0 input [ 0 1 input stack>freg ] when* + 0 input [ + 1 input [ fastcall-regs first ] keep stack>freg + ] when* 2 input f compile-c-call ; M: %cleanup generate-node ( vop -- ) drop ; diff --git a/library/test/compiler/callbacks.factor b/library/test/compiler/callbacks.factor index 46a132b486..a94399a84e 100644 --- a/library/test/compiler/callbacks.factor +++ b/library/test/compiler/callbacks.factor @@ -57,11 +57,24 @@ FUNCTION: void callback_test_1 void* callback ; compiled "void" { "int" "int" } [ / "x" set ] alien-callback ; compiled -! FUNCTION: void callback_test_2 void* callback int x int y ; -! compiled -! -! [ 3/4 ] [ -! [ -! "x" off callback-8 3 4 callback_test_2 "x" get -! ] with-scope -! ] unit-test +FUNCTION: void callback_test_2 void* callback int x int y ; +compiled + +[ 3/4 ] [ + [ + "x" off callback-8 3 4 callback_test_2 "x" get + ] with-scope +] unit-test + +: callback-9 + "void" { "int" "double" "int" } + [ + * "x" set ] alien-callback ; compiled + +FUNCTION: void callback_test_3 void* callback int x double y int z ; +compiled + +[ 27.0 ] [ + [ + "x" off callback-9 3 4 5 callback_test_3 "x" get + ] with-scope +] unit-test diff --git a/native/ffi_test.c b/native/ffi_test.c index 36b547647e..ab0c92abc9 100644 --- a/native/ffi_test.c +++ b/native/ffi_test.c @@ -100,3 +100,13 @@ void callback_test_2(void (*callback)(int x, int y), int x, int y) printf("callback_test_2 leaving\n"); fflush(stdout); } + +void callback_test_3(void (*callback)(int x, double y, int z), + int x, double y, int z) +{ + printf("callback_test_3 entry\n"); + fflush(stdout); + callback(x,y,z); + printf("callback_test_3 leaving\n"); + fflush(stdout); +}