From: Michael D. Lowis Date: Fri, 30 Apr 2021 14:25:47 +0000 (-0400) Subject: added array base type handling X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=fc5d0a7377302156a3770590ac70a85163c6bdbe;p=proto%2Fobnc.git added array base type handling --- diff --git a/cerise/inc/cerise.h b/cerise/inc/cerise.h index f416a53..47f2656 100644 --- a/cerise/inc/cerise.h +++ b/cerise/inc/cerise.h @@ -77,10 +77,11 @@ typedef struct LexFile { char* fpos; } LexFile; -typedef struct { +typedef struct Type { enum { - FORM_BOOL, FORM_INT, FORM_REAL, FORM_STRING + FORM_BOOL, FORM_INT, FORM_REAL, FORM_ARRAY, FORM_STRING } form; + struct Type* base; int size; } Type; @@ -199,7 +200,6 @@ extern Type BoolType, IntType, RealType, StringType; void codegen_setint(Item* item, Type* type, long long val); void codegen_setreal(Item* item, double val); void codegen_setstr(Item* item, char* val); - void codegen_imports(Parser* p); void codegen_global(Parser* p, char* name, Type* type); void codegen_main(Parser* p); diff --git a/cerise/src/grammar.c b/cerise/src/grammar.c index 15e3136..da2f7ca 100644 --- a/cerise/src/grammar.c +++ b/cerise/src/grammar.c @@ -258,7 +258,9 @@ RULE(type) (void)item; if (matches(p, IDENT)) { - expect(p, IDENT); + char* text = expect_text(p, IDENT); + Symbol* sym = symbol_get(p, SYM_TYPE, text); + item->type = sym->type; } else if (accept(p, ARRAY)) { @@ -268,7 +270,12 @@ RULE(type) error(p, "non-constant array size"); } expect(p, OF); - type(p, item); + Item base = {0}; + type(p, &base); + item->type = calloc(1, sizeof(Type)); + item->type->form = FORM_ARRAY; + item->type->size = item->imm.i; + item->type->base = base.type; } else if (accept(p, RECORD)) { diff --git a/cerise/tests/Module.m b/cerise/tests/Module.m index f7bc47c..ca2764d 100644 --- a/cerise/tests/Module.m +++ b/cerise/tests/Module.m @@ -11,8 +11,7 @@ const type TypeA = Int TypeB = array 5 of Int - TypeC = array 5 of - array 10 of Int + TypeC = array 5 of array 10 of Int TypeD = record var @@ -56,7 +55,6 @@ begin # c = b + b * b + b; # - # If statements if 1 == 1 then c = 1;