]> git.mdlowis.com Git - proto/obnc.git/commitdiff
added array base type handling
authorMichael D. Lowis <mike.lowis@gentex.com>
Fri, 30 Apr 2021 14:25:47 +0000 (10:25 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Fri, 30 Apr 2021 14:25:47 +0000 (10:25 -0400)
cerise/inc/cerise.h
cerise/src/grammar.c
cerise/tests/Module.m

index f416a538e2b9a0299384eafb560369dda2e60148..47f26561225b1c0ed08cde74942a85530f12acab 100644 (file)
@@ -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);
index 15e3136096b9a72d186b0457153fa240f30286c3..da2f7cad75dd4eb573ab5b62a0494e72e6e56a19 100644 (file)
@@ -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))
     {
index f7bc47c1f04b921b035d281ffbe735d9f0afc149..ca2764d76e30e4d1726e62703fea4fc3b4dc6621 100644 (file)
@@ -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;