diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2017-05-23 21:58:10 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2017-05-23 21:58:10 -0700 |
commit | 27ba3ad5321efe1393d3736703b7fec2c56e6eb9 (patch) | |
tree | a142e8c7fc956234866de31af62fa0313bff1e27 /ffi.c | |
parent | e7a642bed8ce7343a07d694a4cd5ca3cf097259d (diff) | |
download | txr-27ba3ad5321efe1393d3736703b7fec2c56e6eb9.tar.gz txr-27ba3ad5321efe1393d3736703b7fec2c56e6eb9.tar.bz2 txr-27ba3ad5321efe1393d3736703b7fec2c56e6eb9.zip |
ffi: val type.
* ffi.c (val_s): New symbol variable.
(ffi_val_put, ffi_val_get): New functions.
(ffi_init_types): Register val type.
(ffi_init): Initialize val_s.
* ffi.h (val_s): Declared.
* txr.1: Documented.
Diffstat (limited to 'ffi.c')
-rw-r--r-- | ffi.c | 20 |
1 files changed, 19 insertions, 1 deletions
@@ -74,6 +74,8 @@ val long_s, ulong_s; val double_s; val void_s; +val val_s; + val array_s, zarray_s, carray_s; val struct_s; @@ -82,6 +84,7 @@ val str_d_s, wstr_s, wstr_d_s, bstr_s, bstr_d_s; val buf_d_s; + val ptr_in_s, ptr_out_s, ptr_in_d_s, ptr_out_d_s, ptr_out_s_s, ptr_s; val closure_s; @@ -555,6 +558,16 @@ static val ffi_double_get(struct txr_ffi_type *tft, mem_t *src, val self) return flo(n); } +static void ffi_val_put(struct txr_ffi_type *tft, val v, mem_t *dst, val self) +{ + *coerce(val *, dst) = v; +} + +static val ffi_val_get(struct txr_ffi_type *tft, mem_t *src, val self) +{ + return *coerce(val *, src); +} + #if SIZEOF_WCHAR_T == SIZEOF_SHORT #define ffi_type_wchar ffi_type_ushort #elif SIZEOF_WCHAR_T == SIZEOF_INT @@ -1894,7 +1907,11 @@ static void ffi_init_types(void) alignof (double), &ffi_type_double, ffi_double_put, ffi_double_get)); - + ffi_typedef(val_s, make_ffi_type_builtin(val_s, t, + sizeof (val), + alignof (val), + &ffi_type_pointer, + ffi_val_put, ffi_val_get)); { val type = make_ffi_type_builtin(cptr_s, cptr_s, sizeof (mem_t *), alignof (mem_t *), @@ -2804,6 +2821,7 @@ void ffi_init(void) long_s = intern(lit("long"), user_package); ulong_s = intern(lit("ulong"), user_package); double_s = intern(lit("double"), user_package); + val_s = intern(lit("val"), user_package); void_s = intern(lit("void"), user_package); array_s = intern(lit("array"), user_package); zarray_s = intern(lit("zarray"), user_package); |