Value type struct inputs, for PowerPC
parent
21167c19a7
commit
c30f2f30f4
|
@ -36,6 +36,7 @@ sequences strings words ;
|
||||||
bootstrap-cell "align" set
|
bootstrap-cell "align" set
|
||||||
[ swap <displaced-alien> ] "getter" set
|
[ swap <displaced-alien> ] "getter" set
|
||||||
"width" get [ %unbox-struct ] curry "unboxer" set
|
"width" get [ %unbox-struct ] curry "unboxer" set
|
||||||
|
"width" get [ %box-struct ] curry "boxer" set
|
||||||
"struct" on
|
"struct" on
|
||||||
] "struct-name" get define-c-type
|
] "struct-name" get define-c-type
|
||||||
"struct-name" get in get init-c-type ;
|
"struct-name" get in get init-c-type ;
|
||||||
|
|
|
@ -36,14 +36,18 @@ M: %unbox generate-node ( vop -- )
|
||||||
! Store the return value on the C stack
|
! Store the return value on the C stack
|
||||||
0 input 1 input [ return-reg ] keep freg>stack ;
|
0 input 1 input [ return-reg ] keep freg>stack ;
|
||||||
|
|
||||||
M: %unbox-struct generate-node ( vop -- )
|
: struct-ptr/size ( func -- )
|
||||||
drop
|
|
||||||
! Load destination address
|
! Load destination address
|
||||||
3 1 0 input stack@ ADDI
|
3 1 0 input stack@ ADDI
|
||||||
! Load struct size
|
! Load struct size
|
||||||
2 input 4 LI
|
2 input 4 LI
|
||||||
! Copy the struct to the stack
|
f compile-c-call ;
|
||||||
"unbox_value_struct" f compile-c-call ;
|
|
||||||
|
M: %unbox-struct generate-node ( vop -- )
|
||||||
|
drop "unbox_value_struct" struct-ptr/size ;
|
||||||
|
|
||||||
|
M: %box-struct generate-node ( vop -- )
|
||||||
|
drop "box_value_struct" struct-ptr/size ;
|
||||||
|
|
||||||
: (%move) 0 input 1 input 2 input [ fastcall-regs nth ] keep ;
|
: (%move) 0 input 1 input 2 input [ fastcall-regs nth ] keep ;
|
||||||
|
|
||||||
|
|
|
@ -375,6 +375,11 @@ TUPLE: %box ;
|
||||||
C: %box make-vop ;
|
C: %box make-vop ;
|
||||||
: %box ( n reg-class func -- vop ) 3-in-vop <%box> ;
|
: %box ( n reg-class func -- vop ) 3-in-vop <%box> ;
|
||||||
|
|
||||||
|
TUPLE: %box-struct ;
|
||||||
|
C: %box-struct make-vop ;
|
||||||
|
: %box-struct ( n reg-class size -- vop )
|
||||||
|
3-in-vop <%box-struct> ;
|
||||||
|
|
||||||
TUPLE: %alien-invoke ;
|
TUPLE: %alien-invoke ;
|
||||||
C: %alien-invoke make-vop ;
|
C: %alien-invoke make-vop ;
|
||||||
: %alien-invoke ( func lib -- vop ) 2-in-vop <%alien-invoke> ;
|
: %alien-invoke ( func lib -- vop ) 2-in-vop <%alien-invoke> ;
|
||||||
|
|
|
@ -109,3 +109,20 @@ FUNCTION: void callback_test_4 void* callback int a1 int a2 int a3 int a4 int a5
|
||||||
"stack" get
|
"stack" get
|
||||||
] with-scope
|
] with-scope
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
|
BEGIN-STRUCT: foo
|
||||||
|
FIELD: int x
|
||||||
|
FIELD: int y
|
||||||
|
END-STRUCT
|
||||||
|
|
||||||
|
: make-foo ( x y -- foo )
|
||||||
|
"foo" <c-object> [ set-foo-y ] keep [ set-foo-x ] keep ;
|
||||||
|
|
||||||
|
: callback-10
|
||||||
|
"int"
|
||||||
|
{ "foo" }
|
||||||
|
[ dup foo-x swap foo-y / ] alien-callback ; compiled
|
||||||
|
|
||||||
|
FUNCTION: int callback_test_8 void* callback foo x ;
|
||||||
|
|
||||||
|
[ 5 ] [ callback-10 10 2 make-foo callback_test_8 ] unit-test
|
||||||
|
|
|
@ -151,3 +151,13 @@ void unbox_value_struct(void *dest, CELL size)
|
||||||
{
|
{
|
||||||
memcpy(dest,unbox_alien(),size);
|
memcpy(dest,unbox_alien(),size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* for FFI callbacks receiving structs by value */
|
||||||
|
void box_value_struct(void *src, CELL size)
|
||||||
|
{
|
||||||
|
F_ARRAY *array;
|
||||||
|
maybe_gc(0);
|
||||||
|
array = byte_array(size);
|
||||||
|
memcpy(array + 1,src,size);
|
||||||
|
dpush(tag_object(array));
|
||||||
|
}
|
||||||
|
|
|
@ -53,3 +53,4 @@ void primitive_alien_double(void);
|
||||||
void primitive_set_alien_double(void);
|
void primitive_set_alien_double(void);
|
||||||
|
|
||||||
DLLEXPORT void unbox_value_struct(void *dest, CELL size);
|
DLLEXPORT void unbox_value_struct(void *dest, CELL size);
|
||||||
|
DLLEXPORT void box_value_struct(void *src, CELL size);
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
#include "factor.h"
|
#include "factor.h"
|
||||||
|
|
||||||
/* the array is full of undefined data, and must be correctly filled before the
|
/* the array is full of undefined data, and must be correctly filled before the
|
||||||
next GC. */
|
next GC. size is in cells */
|
||||||
F_ARRAY* allot_array(CELL type, F_FIXNUM capacity)
|
F_ARRAY *allot_array(CELL type, F_FIXNUM capacity)
|
||||||
{
|
{
|
||||||
F_ARRAY *array;
|
F_ARRAY *array;
|
||||||
|
|
||||||
|
@ -24,6 +24,13 @@ F_ARRAY* array(CELL type, F_FIXNUM capacity, CELL fill)
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* size is in bytes this time */
|
||||||
|
F_ARRAY *byte_array(F_FIXNUM size)
|
||||||
|
{
|
||||||
|
F_FIXNUM byte_size = (size + sizeof(CELL) - 1) / sizeof(CELL);
|
||||||
|
return array(BYTE_ARRAY_TYPE,byte_size,0);
|
||||||
|
}
|
||||||
|
|
||||||
/* push a new array on the stack */
|
/* push a new array on the stack */
|
||||||
void primitive_array(void)
|
void primitive_array(void)
|
||||||
{
|
{
|
||||||
|
@ -47,9 +54,8 @@ void primitive_tuple(void)
|
||||||
void primitive_byte_array(void)
|
void primitive_byte_array(void)
|
||||||
{
|
{
|
||||||
F_FIXNUM size = to_fixnum(dpop());
|
F_FIXNUM size = to_fixnum(dpop());
|
||||||
maybe_gc(array_size(size));
|
maybe_gc(0);
|
||||||
F_FIXNUM byte_size = (size + sizeof(CELL) - 1) / sizeof(CELL);
|
dpush(tag_object(byte_array(size)));
|
||||||
dpush(tag_object(array(BYTE_ARRAY_TYPE,byte_size,0)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
F_ARRAY* resize_array(F_ARRAY* array, F_FIXNUM capacity, CELL fill)
|
F_ARRAY* resize_array(F_ARRAY* array, F_FIXNUM capacity, CELL fill)
|
||||||
|
|
|
@ -25,8 +25,9 @@ INLINE CELL array_size(CELL size)
|
||||||
return align8(sizeof(F_ARRAY) + size * CELLS);
|
return align8(sizeof(F_ARRAY) + size * CELLS);
|
||||||
}
|
}
|
||||||
|
|
||||||
F_ARRAY* allot_array(CELL type, F_FIXNUM capacity);
|
F_ARRAY *allot_array(CELL type, F_FIXNUM capacity);
|
||||||
F_ARRAY* array(CELL type, F_FIXNUM capacity, CELL fill);
|
F_ARRAY *array(CELL type, F_FIXNUM capacity, CELL fill);
|
||||||
|
F_ARRAY *byte_array(F_FIXNUM size);
|
||||||
|
|
||||||
void primitive_array(void);
|
void primitive_array(void);
|
||||||
void primitive_tuple(void);
|
void primitive_tuple(void);
|
||||||
|
|
|
@ -150,3 +150,12 @@ double callback_test_7(double (*callback)(void))
|
||||||
printf("callback_test_7 exit\n");
|
printf("callback_test_7 exit\n");
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int callback_test_8(int (*callback)(struct foo x), struct foo x)
|
||||||
|
{
|
||||||
|
int x;
|
||||||
|
printf("callback_test_8 entry\n");
|
||||||
|
x = callback(x);
|
||||||
|
printf("callback_test_8 exit\n");
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
|
@ -21,3 +21,4 @@ DLLEXPORT void callback_test_4(void (*callback)(int a1, int a2, int a3, int a4,
|
||||||
DLLEXPORT int callback_test_5(int (*callback)(void));
|
DLLEXPORT int callback_test_5(int (*callback)(void));
|
||||||
DLLEXPORT float callback_test_6(float (*callback)(void));
|
DLLEXPORT float callback_test_6(float (*callback)(void));
|
||||||
DLLEXPORT double callback_test_7(double (*callback)(void));
|
DLLEXPORT double callback_test_7(double (*callback)(void));
|
||||||
|
DLLEXPORT int callback_test_8(int (*callback)(struct foo x), struct foo x);
|
||||||
|
|
Loading…
Reference in New Issue