summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-05-06 08:26:46 -0700
committerKaz Kylheku <kaz@kylheku.com>2017-05-06 08:26:46 -0700
commit71f5557c94eedb766a5140776c5f377c6d222caa (patch)
tree028b09017ebb8c0b066c926947d7295eaba1a7d7
parente25f2c548e36eb162a64b04a4de62a803f1fe132 (diff)
downloadtxr-71f5557c94eedb766a5140776c5f377c6d222caa.tar.gz
txr-71f5557c94eedb766a5140776c5f377c6d222caa.tar.bz2
txr-71f5557c94eedb766a5140776c5f377c6d222caa.zip
ffi: ffi-size function.
This will support a sizeof macro. * ffi.c (ffi_size): New function. (ffi_init): Register ffi-size intrinsic. * ffi.h (ffi_size): Declared.
-rw-r--r--ffi.c7
-rw-r--r--ffi.h1
2 files changed, 8 insertions, 0 deletions
diff --git a/ffi.c b/ffi.c
index ffeb3987..d99e5beb 100644
--- a/ffi.c
+++ b/ffi.c
@@ -1849,6 +1849,12 @@ val ffi_typedef(val name, val type)
return sethash(ffi_typedef_hash, name, type);
}
+val ffi_size(val type)
+{
+ struct txr_ffi_type *tft = ffi_type_struct_checked(type);
+ return num(tft->size);
+}
+
val ffi_put_into(val dstbuf, val obj, val type)
{
val self = lit("ffi-put-into");
@@ -1954,6 +1960,7 @@ void ffi_init(void)
reg_fun(intern(lit("ffi-make-closure"), user_package), func_n2(ffi_make_closure));
reg_fun(intern(lit("cptr"), user_package), func_n1o(cptr_make, 0));
reg_fun(intern(lit("ffi-typedef"), user_package), func_n2(ffi_typedef));
+ reg_fun(intern(lit("ffi-size"), user_package), func_n1(ffi_size));
reg_fun(intern(lit("ffi-put-into"), user_package), func_n3(ffi_put_into));
reg_fun(intern(lit("ffi-put"), user_package), func_n2(ffi_put));
reg_fun(intern(lit("ffi-in"), user_package), func_n3(ffi_in));
diff --git a/ffi.h b/ffi.h
index bd8b61fb..fa559f54 100644
--- a/ffi.h
+++ b/ffi.h
@@ -57,6 +57,7 @@ val ffi_make_closure(val fun, val call_desc);
mem_t *ffi_closure_get_fptr(val closure);
val ffi_call_wrap(val ffi_call_desc, val fptr, val args);
val ffi_typedef(val name, val type);
+val ffi_size(val type);
val ffi_put_into(val dstbuf, val obj, val type);
val ffi_put(val obj, val type);
val ffi_in(val srcbuf, val obj, val type);