From 88f1192c5e0e80dd1a45900bc8c9b0db2040b653 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Sun, 20 Mar 2016 22:44:08 -0400 Subject: [PATCH] 64-bit compatibility for int value types --- include/cyclone/runtime.h | 2 +- include/cyclone/types.h | 4 ++-- runtime.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/cyclone/runtime.h b/include/cyclone/runtime.h index 9a6654e0..ed85c563 100644 --- a/include/cyclone/runtime.h +++ b/include/cyclone/runtime.h @@ -14,7 +14,7 @@ object l = Cyc_length2(data, args); \ if (num_args > obj_obj2int(l)) { \ char buf[128]; \ - snprintf(buf, 127, "Expected %d arguments but received %d.", num_args, obj_obj2int(l)); \ + snprintf(buf, 127, "Expected %d arguments but received %ld.", num_args, obj_obj2int(l)); \ Cyc_rt_raise_msg(data, buf); \ } \ } diff --git a/include/cyclone/types.h b/include/cyclone/types.h index 3bbf106a..16783f20 100644 --- a/include/cyclone/types.h +++ b/include/cyclone/types.h @@ -211,8 +211,8 @@ typedef long tag_type; // TODO: does this break negative numbers (IE, overwrite sign bit in 2's comp?)? may need a more sophisticated scheme to handle 31-bit numbers. also, ideally want to use 63 bits on a 64-bit system #define obj_is_int(x) ((unsigned long)(x) & (unsigned long)1) -#define obj_obj2int(x) ((int)(x)>>1) -#define obj_int2obj(c) ((void *)((((int)c)<<1) | 1)) +#define obj_obj2int(x) ((long)(x)>>1) +#define obj_int2obj(c) ((void *)((((long)c)<<1) | 1)) #define obj_is_char(x) (((unsigned long)(x) & (unsigned long)3) == 2) #define obj_obj2char(x) (char)((long)(x)>>2) diff --git a/runtime.c b/runtime.c index 729bee96..26f3a7da 100644 --- a/runtime.c +++ b/runtime.c @@ -533,7 +533,7 @@ object Cyc_display(object x, FILE *port) int i = 0; if (nullp(x)) {fprintf(port, "()"); return quote_void;} if (obj_is_char(x)) {fprintf(port, "%c", obj_obj2char(x)); return quote_void;} - if (obj_is_int(x)) { fprintf(port, "%d", obj_obj2int(x)); return quote_void; } + if (obj_is_int(x)) { fprintf(port, "%ld", obj_obj2int(x)); return quote_void; } switch (type_of(x)) {case macro_tag: fprintf(port, "",(void *)((closure) x)->fn); @@ -1018,7 +1018,7 @@ object Cyc_number2string(void *data, object cont, object n) { char buffer[1024]; Cyc_check_num(data, n); if (obj_is_int(n)) { - snprintf(buffer, 1024, "%d", obj_obj2int(n)); + snprintf(buffer, 1024, "%ld", obj_obj2int(n)); }else if (type_of(n) == integer_tag) { snprintf(buffer, 1024, "%d", ((integer_type *)n)->value); } else if (type_of(n) == double_tag) {