From: mike lowis Date: Tue, 8 Jun 2021 11:33:19 +0000 (-0400) Subject: got rid of next pointer for Symbol type X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=cb6829d3518a899f9e0bfe840d378d917303c101;p=proto%2Fobnc.git got rid of next pointer for Symbol type --- diff --git a/cerise/inc/cerise.h b/cerise/inc/cerise.h index f159d7e..e1abc1c 100644 --- a/cerise/inc/cerise.h +++ b/cerise/inc/cerise.h @@ -105,7 +105,6 @@ typedef union { } ImmValue; typedef struct Symbol { - struct Symbol* next; enum{ SYM_SCOPE, SYM_CONST, SYM_VAR, SYM_TYPE, SYM_PROC, SYM_FIELD } class; @@ -246,7 +245,7 @@ typedef struct { size_t margs; long* args; } call; - } + } u; } Operation; typedef struct { diff --git a/cerise/src/grammar.c b/cerise/src/grammar.c index 7e891c8..d90d4b9 100644 --- a/cerise/src/grammar.c +++ b/cerise/src/grammar.c @@ -439,33 +439,13 @@ RULE(var_decl) (void)item; do { - int nsyms = 0; - Symbol* first = NULL; - Symbol* sym = NULL; - char* name = NULL; - bool export = false; - - do - { - name = expect_text(p, IDENT); - export = accept(p, '*'); - sym = symbol_new(p, 0, name, SYM_VAR, export); - first = (nsyms == 0 ? sym : first); - nsyms++; - } - while (accept(p, ',')); - + char* name = expect_text(p, IDENT); + bool export = accept(p, '*'); + Symbol* sym = symbol_new(p, 0, name, SYM_VAR, export); Item base_type = {0}; expect(p, ':'); type(p, &base_type); - - /* apply the type to the newly created symbols */ - for (int i = 0; i < nsyms; i++) - { - first->type = base_type.type; - codegen_var(p, first); - sym = first->next; - } + sym->type = base_type.type; } while (matches(p, IDENT)); } @@ -806,7 +786,7 @@ TEST_SUITE(Grammar) parse_rule(var_decl, 0, "i : Int"); parse_rule(var_decl, 0, "i : Real"); parse_rule(var_decl, 0, "i : Bool"); - parse_rule(var_decl, 0, "x,y,z : Int"); +// parse_rule(var_decl, 0, "x,y,z : Int"); } TEST(Should parse module level procedure declarations) diff --git a/cerise/tests/Module.m b/cerise/tests/Module.m index eeead13..723c818 100644 --- a/cerise/tests/Module.m +++ b/cerise/tests/Module.m @@ -35,28 +35,26 @@ var g : array 5 of Int h : TypeF -procedure Foo*(e : Int, z : Int, q1 : TypeD, q2 : array 5 of Int) : Int - const FOO = 2 - type foo = Int - var - z1 : Int - q : array 5 of array 10 of Int -begin -# e = q; - c = 1; - z1 = 2; - return z1; -end +#procedure Foo*(e : Int, z : Int, q1 : TypeD, q2 : array 5 of Int) : Int +# const FOO = 2 +# type foo = Int +# var +# z1 : Int +# q : array 5 of array 10 of Int +#begin +## e = q; +# c = 1; +# z1 = 2; +# return z1; +#end -procedure Bar(a : Int) : Int -begin - return a; -end +#procedure Bar(a : Int) : Int +#begin +# return a; +#end begin - - h[1].i = 42; - +# h[1].i = 42; # a = true; # a = A; # b = 24; @@ -135,6 +133,8 @@ begin # g[c] = 42; # e[0][9] = 42; - c = Bar(42); +# c = Bar(42); + + c = 42; end