Basic callback unit tests pass
parent
90b10f1cfd
commit
d584e8c0bb
|
@ -53,8 +53,7 @@
|
||||||
- out of memory from overflow check
|
- out of memory from overflow check
|
||||||
- remove literal table
|
- remove literal table
|
||||||
- callbacks
|
- callbacks
|
||||||
- zero-arity
|
- return values
|
||||||
- return-only
|
|
||||||
- input values
|
- input values
|
||||||
- value type struct inputs
|
- value type struct inputs
|
||||||
- ffi unicode strings: null char security hole
|
- ffi unicode strings: null char security hole
|
||||||
|
|
|
@ -33,7 +33,7 @@ M: alien-callback-error summary ( error -- )
|
||||||
] "infer" set-word-prop
|
] "infer" set-word-prop
|
||||||
|
|
||||||
: box-parameters ( parameters -- )
|
: box-parameters ( parameters -- )
|
||||||
[ box-parameter , ] reverse-each-parameter ;
|
[ box-parameter , ] each-parameter ;
|
||||||
|
|
||||||
: registers>objects ( parameters -- )
|
: registers>objects ( parameters -- )
|
||||||
#! The corresponding unnest_stacks() call is made by the
|
#! The corresponding unnest_stacks() call is made by the
|
||||||
|
|
|
@ -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 a stack location, load it into freg #0.
|
||||||
! If the source is f, then we assume the value is already in
|
! If the source is f, then we assume the value is already in
|
||||||
! freg #0.
|
! 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 ;
|
2 input f compile-c-call ;
|
||||||
|
|
||||||
M: %cleanup generate-node ( vop -- ) drop ;
|
M: %cleanup generate-node ( vop -- ) drop ;
|
||||||
|
|
|
@ -57,11 +57,24 @@ FUNCTION: void callback_test_1 void* callback ; compiled
|
||||||
"void" { "int" "int" } [ / "x" set ] alien-callback ;
|
"void" { "int" "int" } [ / "x" set ] alien-callback ;
|
||||||
compiled
|
compiled
|
||||||
|
|
||||||
! FUNCTION: void callback_test_2 void* callback int x int y ;
|
FUNCTION: void callback_test_2 void* callback int x int y ;
|
||||||
! compiled
|
compiled
|
||||||
!
|
|
||||||
! [ 3/4 ] [
|
[ 3/4 ] [
|
||||||
! [
|
[
|
||||||
! "x" off callback-8 3 4 callback_test_2 "x" get
|
"x" off callback-8 3 4 callback_test_2 "x" get
|
||||||
! ] with-scope
|
] with-scope
|
||||||
! ] unit-test
|
] 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
|
||||||
|
|
|
@ -100,3 +100,13 @@ void callback_test_2(void (*callback)(int x, int y), int x, int y)
|
||||||
printf("callback_test_2 leaving\n");
|
printf("callback_test_2 leaving\n");
|
||||||
fflush(stdout);
|
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);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue