]> git.mdlowis.com Git - proto/obnc.git/commitdiff
cleaned up record access code
authorMichael D. Lowis <mike.lowis@gentex.com>
Thu, 27 May 2021 19:55:05 +0000 (15:55 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Thu, 27 May 2021 19:55:05 +0000 (15:55 -0400)
cerise/backend/c99/codegen.c
cerise/tests/Module.m

index 5e90fd18bdebc4ada95c8399bde39e87332061a4..6f00c37cca41482caae0bb67005c3c862bd63724 100644 (file)
@@ -26,7 +26,7 @@ static char* TypeNames[FORM_COUNT] = {
     [FORM_BOOL]   = "Bool",
     [FORM_INT]    = "Int",
     [FORM_REAL]   = "Real",
-    [FORM_STRING] = "char*"
+    [FORM_STRING] = "Byte*"
 };
 
 static char* Operators[] = {
@@ -101,7 +101,7 @@ static void make_var(Parser* p, Symbol* sym, int isref)
     }
     else if (sym->type->form == FORM_RECORD)
     {
-        printf("char %s[%d]", name, sym->type->size);
+        printf("Byte %s[%d]", name, sym->type->size);
     }
     else
     {
@@ -130,7 +130,7 @@ static int declare_temp(Parser* p, Type* type, int isref)
     };
     if (type->form == FORM_RECORD)
     {
-        printf("    char* %s", name);
+        printf("    Byte* %s", name);
     }
     else
     {
@@ -149,7 +149,7 @@ static char* temp(Item* a)
     }
     else if (a->mode == ITEM_FIELD)
     {
-        snprintf(name, sizeof(name), "*((%s)_T%d)", typetoptr(a->type), a->reg);
+        snprintf(name, sizeof(name), "*((%s)(_T%d + %d))", typetoptr(a->type), a->reg, a->offset);
     }
     else
     {
@@ -178,7 +178,7 @@ static void load_var(Parser* p, Item* item)
                 item->reg = declare_temp(p, item->type, isref);
                 if (item->type->form == FORM_RECORD)
                 {
-                    printf(" = (char*)&%s[0];\n", item->imm.s);
+                    printf(" = (Byte*)&%s[0];\n", item->imm.s);
                 }
                 else
                 {
@@ -230,9 +230,11 @@ static void unary_op(Parser* p, int op, Item* a)
 void codegen_startmod(Parser* p)
 {
     (void)p;
+    printf("typedef char Byte;\n");
     printf("typedef _Bool Bool;\n");
     printf("typedef long Int;\n");
     printf("typedef double Real;\n");
+    puts("");
 }
 
 void codegen_endmod(Parser* p)
@@ -369,7 +371,6 @@ void codegen_store(Parser* p, Item* a, Item* b)
     else if (a->mode == ITEM_FIELD)
     {
         load_var(p, b);
-//        printf("    *((%s)%s) = %s;\n", typetoptr(a->type), temp(a), temp(b));
         printf("    %s = %s;\n", temp(a), temp(b));
     }
     else
@@ -494,8 +495,5 @@ void codegen_field(Parser* p, Item* record, char* name)
     Field* f = get_field(p, record->type, name);
     record->mode = ITEM_FIELD;
     record->type = f->type;
-    printf("    char* _T%d", p->curr_reg);
-    p->curr_reg++;
-    printf(" = _T%d + %ld;\n", record->reg, f->offset);
-    record->reg = p->curr_reg-1;
+    record->offset += f->offset;
 }
index 60afadfee027552610a8926181eb06873b7e93ff..665c1eb754ed50601de278a48410a86d044e1d6a 100644 (file)
@@ -14,7 +14,7 @@ type
   TypeC = array 5 of array 10 of Int
   TypeD = record
     x,y : Int
-    label : array 10 of Real
+    label : array 10 of Int
     dim : record
       w,h : Int
     end
@@ -112,6 +112,7 @@ begin
 #  e[b] = 1;
 #    e[1][2] = 1;
 #    c = e[1][c];
-  c = f.dim.w;
+#  c = f.dim.w;
   f.dim.h = 0;
+#  f.label[0] = 42;
 end