From 5bc26c072ae7e67d7b53b8fe0e53ce006f8a1766 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Tue, 18 Apr 2017 23:20:51 +0000 Subject: [PATCH] Added the return_copy macro --- include/cyclone/types.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/include/cyclone/types.h b/include/cyclone/types.h index 9f0f02a0..1262cb7b 100644 --- a/include/cyclone/types.h +++ b/include/cyclone/types.h @@ -1040,6 +1040,34 @@ typedef union { bignum_type bignum_t; } common_type; +#define return_copy(ptr, obj) \ +{ \ + tag_type t; \ + if (is_value_type(obj)) \ + return obj; \ + t = type_of(obj); \ + if (t == boolean_tag || /* Pre-allocated */ \ + t == symbol_tag || /* Allocated in their own area */ \ + t == bignum_tag) { /* Always heap allocated */ \ + return obj; \ + } else if (t == pair_tag) { \ + ((common_type *)ptr)->pair_t.hdr.mark = gc_color_red; \ + ((common_type *)ptr)->pair_t.hdr.grayed = 0; \ + ((common_type *)ptr)->pair_t.tag = pair_tag; \ + ((common_type *)ptr)->pair_t.pair_car = car(obj); \ + ((common_type *)ptr)->pair_t.pair_cdr = cdr(obj); \ + return ptr; \ + } else if (t == double_tag) { \ + ((common_type *)ptr)->double_t.hdr.mark = gc_color_red; \ + ((common_type *)ptr)->double_t.hdr.grayed = 0; \ + ((common_type *)ptr)->double_t.tag = double_tag; \ + ((common_type *)ptr)->double_t.value = double_value(obj); \ + return ptr; \ + } else { \ + return obj; \ + } \ +} + /**@}*/ /**@}*/