From 074dee78861d3a032ede29f0168bc14df6914884 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Mon, 3 Apr 2017 13:37:27 +0000 Subject: [PATCH] Exploring how define-c could inline functions --- include/cyclone/runtime.h | 15 +++++++++++++++ scheme/inexact.sld | 8 +++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/include/cyclone/runtime.h b/include/cyclone/runtime.h index 272ff922..8a497b64 100644 --- a/include/cyclone/runtime.h +++ b/include/cyclone/runtime.h @@ -275,6 +275,21 @@ object Cyc_io_read_line(void *data, object cont, object port); */ /**@{*/ +#define unboxed_inexact_double_op(data, ptr, OP, z) \ + double unboxed; \ + Cyc_check_num(data, z); \ + if (obj_is_int(z)) { \ + unboxed = OP(obj_obj2int(z)); \ + } else if (type_of(z) == integer_tag) { \ + unboxed = OP(((integer_type *)z)->value); \ + } else if (type_of(z) == bignum_tag) { \ + unboxed = OP(mp_get_double(&bignum_value(z))); \ + } else { \ + unboxed = OP(((double_type *)z)->value); \ + } \ + assign_double(ptr, unboxed); \ + return ptr; + #define return_inexact_double_op(data, cont, OP, z) \ make_double(d, 0.0); \ Cyc_check_num(data, z); \ diff --git a/scheme/inexact.sld b/scheme/inexact.sld index 1fbf1717..f31055ad 100644 --- a/scheme/inexact.sld +++ b/scheme/inexact.sld @@ -72,9 +72,11 @@ ; TODO: experimenting with how an inline definition might look. ; need something that can both work within the same module and ; also when imported into another module. -; inline: -; "(void *data, object ptr, object z)" -; " return_inexact_double_op(data, k, log, z);" + ;; Inline arguments: + "(void *data, object ptr, object z)" + ;; must always return an object + ;; Inline body: + " unboxed_inexact_double_op(data, ptr, log, z);" ) (define-c sin "(void *data, int argc, closure _, object k, object z)"