From d027b85a64d24e5cab4e9963de0575a0e6bb4b12 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Sat, 10 Oct 2015 02:22:14 -0400 Subject: [PATCH] Setting stage to change how strings are stored --- include/cyclone/types.h | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/include/cyclone/types.h b/include/cyclone/types.h index 5b3b65b7..eb12103d 100644 --- a/include/cyclone/types.h +++ b/include/cyclone/types.h @@ -189,23 +189,24 @@ typedef struct {gc_header_type hdr; tag_type tag; int len; char *str;} string_ty //// TODO: new way to allocate strings, but this requires changes to //// all functions that allocate strings, the GC, cgen, and maybe more. //// Because these strings are (at least for now) allocaed on the stack. -//#define make_string(cs, len, s) string_type cs; \ -//{ cs.tag = string_tag; cs.len = len; \ -// cs.str = alloca(sizeof(char) * (len + 1)); \ -// strcpy(cs.str, s);} +#define make_string(cs, len, s) string_type cs; \ +{ cs.tag = string_tag; cs.len = len; \ + cs.str = alloca(sizeof(char) * (len + 1)); \ + strcpy(cs.str, s);} // TODO: all of the dhalloc below needs to go away... -#define make_string(cv,s) string_type cv; cv.tag = string_tag; \ -{ int len = strlen(s); cv.str = dhallocp; \ - if ((dhallocp + len + 1) >= dhbottom + global_heap_size) { \ - printf("Fatal error: data heap overflow\n"); exit(1); } \ - memcpy(dhallocp, s, len + 1); dhallocp += len + 1; } -#define make_stringn(cv,s,len) string_type cv; cv.tag = string_tag; \ -{ cv.str = dhallocp; \ - if ((dhallocp + len + 1) >= dhbottom + global_heap_size) { \ - printf("Fatal error: data heap overflow\n"); exit(1); } \ - memcpy(dhallocp, s, len); dhallocp += len; \ - *dhallocp = '\0'; dhallocp += 1;} +//#define make_string(cv,s) string_type cv; cv.tag = string_tag; \ +//{ int len = strlen(s); cv.str = dhallocp; \ +// if ((dhallocp + len + 1) >= dhbottom + global_heap_size) { \ +// printf("Fatal error: data heap overflow\n"); exit(1); } \ +// memcpy(dhallocp, s, len + 1); dhallocp += len + 1; } +//#define make_stringn(cv,s,len) string_type cv; cv.tag = string_tag; \ +//{ cv.str = dhallocp; \ +// if ((dhallocp + len + 1) >= dhbottom + global_heap_size) { \ +// printf("Fatal error: data heap overflow\n"); exit(1); } \ +// memcpy(dhallocp, s, len); dhallocp += len; \ +// *dhallocp = '\0'; dhallocp += 1;} +#define string_len(x) (((string_type *) x)->len) #define string_str(x) (((string_type *) x)->str) /* I/O types */