From 96c3893cb6268d90864c9ad9beb700435f257c1f Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Fri, 14 Oct 2016 04:26:14 -0400 Subject: [PATCH] WIP, added notes --- include/cyclone/runtime.h | 4 ++-- include/cyclone/types.h | 6 ++++++ runtime.c | 36 ++++++++++++++++++++++++++---------- 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/include/cyclone/runtime.h b/include/cyclone/runtime.h index b93ac289..0d322c22 100644 --- a/include/cyclone/runtime.h +++ b/include/cyclone/runtime.h @@ -262,8 +262,8 @@ object Cyc_sum(void *data, object cont, int argc, object n, ...); object Cyc_sub(void *data, object cont, int argc, object n, ...); object Cyc_mul(void *data, object cont, int argc, object n, ...); object Cyc_div(void *data, object cont, int argc, object n, ...); -object Cyc_fast_sum(void *data, object cont, int argc, object x, object y); -object Cyc_fast_sub(void *data, object cont, int argc, object x, object y); +object Cyc_fast_sum(void *data, object ptr, object x, object y); +//object Cyc_fast_sub(void *data, object ptr, object x, object y); object Cyc_bit_unset(void *data, object n1, object n2); object Cyc_bit_set(void *data, object n1, object n2); object Cyc_num_op_va_list(void *data, int argc, diff --git a/include/cyclone/types.h b/include/cyclone/types.h index d5fd1535..397123f6 100644 --- a/include/cyclone/types.h +++ b/include/cyclone/types.h @@ -365,6 +365,12 @@ typedef struct { n.tag = double_tag; \ n.value = v; +#define assign_double(pobj,v) \ + ((double_type *)pobj)->hdr.mark = gc_color_red; \ + ((double_type *)pobj)->hdr.grayed = 0; \ + ((double_type *)pobj)->tag = double_tag; \ + double_value(pobj) = v; + #define integer_value(x) (((integer_type *) x)->value) #define double_value(x) (((double_type *) x)->value) diff --git a/runtime.c b/runtime.c index 8d93c9ee..4dad5e34 100644 --- a/runtime.c +++ b/runtime.c @@ -1152,6 +1152,11 @@ declare_num_cmp(Cyc_num_lt, Cyc_num_lt_op, dispatch_num_lt, <); declare_num_cmp(Cyc_num_gte, Cyc_num_gte_op, dispatch_num_gte, >=); declare_num_cmp(Cyc_num_lte, Cyc_num_lte_op, dispatch_num_lte, <=); +//TODO: +//object Cyc_fast_num_eq(void *data, object cont, int argc, object x, object y) { +// return NULL; +//} + object Cyc_is_boolean(object o) { if ((o != NULL) && @@ -2289,25 +2294,36 @@ void FUNC_APPLY(void *data, int argc, object clo, object cont, object n, ...) { return_closcall1(data, cont, result); \ } -object Cyc_fast_sum(void *data, object cont, int argc, object x, object y) { +/* +TODO: need compiler to allocate a common type on the stack, and pass +a pointer to it as ptr. This would allow us to have a function that can +be inlined. + +TODO: with above, will want compiler to replace suitable instances of + +with something else to be compiled to this, such as Cyc:+. +I think it is good enough to replace all calls to + with only 2 params. +might be able to condense calls with more than 2 params down to multiple +calls to Cyc:+, but lets do that afterwards +*/ +object Cyc_fast_sum(void *data, object ptr, object x, object y) { // x is int (assume value types for integers) if (obj_is_int(x)){ if (obj_is_int(y)){ int z = obj_obj2int(x) + obj_obj2int(y); - _return_closcall1(data, cont, obj_int2obj(z)); + return obj_int2obj(z); } else if (is_object_type(y) && type_of(y) == double_tag) { - make_double(d, (double)(obj_obj2int(x)) + double_value(y)); - _return_closcall1(data, cont, &d); + assign_double(ptr, (double)(obj_obj2int(x)) + double_value(y)); + return ptr; } } // x is double if (is_object_type(x) && type_of(x) == double_tag) { if (obj_is_int(y)){ - make_double(d, (double)(obj_obj2int(y)) + double_value(x)); - _return_closcall1(data, cont, &d); + assign_double(ptr, (double)(obj_obj2int(y)) + double_value(x)); + return ptr; } else if (is_object_type(y) && type_of(y) == double_tag) { - make_double(d, double_value(x) + double_value(y)); - _return_closcall1(data, cont, &d); + assign_double(ptr, double_value(x) + double_value(y)); + return ptr; } } // still here, raise an error @@ -2319,7 +2335,7 @@ object Cyc_fast_sum(void *data, object cont, int argc, object x, object y) { return NULL; } -object Cyc_fast_sub(void *data, object cont, int argc, object x, object y) { +/*object Cyc_fast_sub(void *data, object ptr, object x, object y) { // x is int (assume value types for integers) if (obj_is_int(x)){ if (obj_is_int(y)){ @@ -2347,7 +2363,7 @@ object Cyc_fast_sub(void *data, object cont, int argc, object x, object y) { make_pair(c0, &s, &c1); Cyc_rt_raise(data, &c0); return NULL; -} +}*/ object Cyc_div_op(void *data, common_type * x, object y) {