From 4b977eae94d17f69f0d3b4e1a524f497dd74a3fc Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Fri, 14 May 2021 17:01:56 -0400 Subject: [PATCH] segfaults everywhere --- cerise/inc/cerise.h | 6 +++--- cerise/src/grammar.c | 22 +++++++++++++++------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/cerise/inc/cerise.h b/cerise/inc/cerise.h index 04ee5da..25d4f67 100644 --- a/cerise/inc/cerise.h +++ b/cerise/inc/cerise.h @@ -77,12 +77,12 @@ typedef struct LexFile { char* fpos; } LexFile; -struct Symbol; +struct Type; typedef struct Field { struct Field* next; char* name; - Type* type; + struct Type* type; long offset; int export : 1; } Field; @@ -93,7 +93,7 @@ typedef struct Type { FORM_RECORD, FORM_COUNT } form; - struct Symbol* fields; + struct Field* fields; struct Type* base; int size; } Type; diff --git a/cerise/src/grammar.c b/cerise/src/grammar.c index 811b8d2..8c72c67 100644 --- a/cerise/src/grammar.c +++ b/cerise/src/grammar.c @@ -347,16 +347,26 @@ RULE(type) { item->type = calloc(1, sizeof(Type)); item->type->form = FORM_RECORD; - Symbol head = {0}; - int nfields = 0; + +// long offset = 0; + Field **field = &(item->type->fields); while (peek(p)->type != END) { + int nfields = 0; + Field* first = NULL; do { char* name = expect_text(p, IDENT); bool export = accept(p, '*'); - (void)symbol_addfield(p, &head, name, SYM_FIELD, export); + *field = calloc(1, sizeof(Field)); + (*field)->name = name; + (*field)->export = export; + field = &((*field)->next); + if (!first) + { + first = *field; + } nfields++; } while (accept(p, ',')); @@ -366,13 +376,11 @@ RULE(type) type(p, &field_type); /* apply the type to the newly created symbols */ - Symbol* field = head.desc; for (int i = 0; i < nfields; i++) { - field->type = field_type.type; - field = field->next; + first->type = field_type.type; + first = first->next; } - item->type->fields = head.desc; } expect(p, END); -- 2.49.0