From 108b19025eb002da528b9e8190ccafc7081f1c4b Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Thu, 11 Oct 2018 12:51:59 -0400 Subject: [PATCH] Added pc field for future host function support. --- gc.c | 5 ++++- include/cyclone/types.h | 9 ++++++++- scheme/cyclone/cgen.sld | 1 + 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/gc.c b/gc.c index b03229a6..5b4d4b8b 100644 --- a/gc.c +++ b/gc.c @@ -788,6 +788,7 @@ char *gc_copy_obj(object dest, char *obj, gc_thread_data * thd) mark(hp) = thd->gc_alloc_color; type_of(hp) = closureN_tag; hp->fn = ((closureN) obj)->fn; + hp->pc = ((closureN) obj)->pc; hp->num_args = ((closureN) obj)->num_args; hp->num_elements = ((closureN) obj)->num_elements; hp->elements = (object *) (((char *)hp) + sizeof(closureN_type)); @@ -896,6 +897,7 @@ char *gc_copy_obj(object dest, char *obj, gc_thread_data * thd) mark(hp) = thd->gc_alloc_color; type_of(hp) = macro_tag; hp->fn = ((macro) obj)->fn; + hp->pc = ((macro) obj)->pc; hp->num_args = ((macro) obj)->num_args; return (char *)hp; } @@ -904,6 +906,7 @@ char *gc_copy_obj(object dest, char *obj, gc_thread_data * thd) mark(hp) = thd->gc_alloc_color; type_of(hp) = closure1_tag; hp->fn = ((closure1) obj)->fn; + hp->pc = ((closure1) obj)->pc; hp->num_args = ((closure1) obj)->num_args; hp->element = ((closure1) obj)->element; return (char *)hp; @@ -2670,7 +2673,7 @@ void gc_thread_data_init(gc_thread_data * thd, int mut_num, char *stack_base, exit(1); } thd->pc = 0; - thd->args = calloc(MAX_C_ARGS, sizeof(object)); + thd->args = NULL; thd->stack_traces = calloc(MAX_STACK_TRACES, sizeof(char *)); thd->stack_trace_idx = 0; thd->stack_prev_frame = NULL; diff --git a/include/cyclone/types.h b/include/cyclone/types.h index 19a5e769..26d9b0f5 100644 --- a/include/cyclone/types.h +++ b/include/cyclone/types.h @@ -1214,6 +1214,7 @@ typedef struct { gc_header_type hdr; tag_type tag; function_type fn; + int pc; int num_args; } macro_type; @@ -1222,6 +1223,7 @@ typedef struct { gc_header_type hdr; tag_type tag; function_type fn; + int pc; int num_args; } closure0_type; /** @brief A closed-over function with one variable */ @@ -1229,6 +1231,7 @@ typedef struct { gc_header_type hdr; tag_type tag; function_type fn; + int pc; int num_args; object element; } closure1_type; @@ -1237,6 +1240,7 @@ typedef struct { gc_header_type hdr; tag_type tag; function_type fn; + int pc; int num_args; int num_elements; object *elements; @@ -1254,10 +1258,11 @@ typedef closure0_type *macro; c.hdr.grayed = 0; \ c.tag = macro_tag; \ c.fn = f; \ + c.pc = 0; \ c.num_args = -1; #define mclosure0(c, f) \ - static closure0_type c = { .hdr.mark = gc_color_red, .hdr.grayed = 0, .tag = closure0_tag, .fn = f, .num_args = -1 }; /* TODO: need a new macro that initializes num_args */ + static closure0_type c = { .hdr.mark = gc_color_red, .hdr.grayed = 0, .tag = closure0_tag, .fn = f, .pc = 0, .num_args = -1 }; /* TODO: need a new macro that initializes num_args */ /* #define mclosure0(c,f) \ @@ -1275,6 +1280,7 @@ typedef closure0_type *macro; c.hdr.grayed = 0; \ c.tag = closure0_tag; \ c.fn = f; \ + c.pc = 0; \ c.num_args = na; #define mclosure1(c,f,a) \ @@ -1283,6 +1289,7 @@ typedef closure0_type *macro; c.hdr.grayed = 0; \ c.tag = closure1_tag; \ c.fn = f; \ + c.pc = 0; \ c.num_args = -1; \ c.element = a; diff --git a/scheme/cyclone/cgen.sld b/scheme/cyclone/cgen.sld index f7a823bc..47720094 100644 --- a/scheme/cyclone/cgen.sld +++ b/scheme/cyclone/cgen.sld @@ -1392,6 +1392,7 @@ cv-name ".hdr.grayed = 0;\n" cv-name ".tag = closureN_tag;\n " cv-name ".fn = (function_type)__lambda_" (number->string lid) ";\n" + cv-name ".pc = 0;\n" ;; TODO: need to set this appropriately cv-name ".num_args = " num-args-str ";\n" cv-name ".num_elements = " (number->string (length free-vars)) ";\n" cv-name ".elements = (object *)alloca(sizeof(object) * "