]> git.mdlowis.com Git - proto/obnc.git/commitdiff
added type emitting code for records
authorMichael D. Lowis <mike@mdlowis.com>
Thu, 22 Sep 2022 01:50:03 +0000 (21:50 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Thu, 22 Sep 2022 01:50:03 +0000 (21:50 -0400)
cerise/backend/ssa/codegen.c
cerise/src/ssa.c
cerise/tests/Module.m

index 72aa317df543fb28d8e0cc522d12ba6deced0c13..e8cc367bb0fab20d50c17bd3328f094b74d675c1 100644 (file)
@@ -77,7 +77,23 @@ void emit_type(Type* type)
             break;
 
         case FORM_RECORD:
-            printf("%%%s", type->name);
+            if (type->name)
+            {
+                printf("%%%s", type->name);
+            }
+            else
+            {
+                printf("{ ");
+                for (Field* field = type->fields; field; field = field->next)
+                {
+                    emit_type(field->type);
+                    if (field->next)
+                    {
+                        printf(", ");
+                    }
+                }
+                printf(" }");
+            }
             break;
 
         case FORM_PROC:
index e9521dee607f6dc933792db825e335f29bfe1f36..a5a298042c07c2a71ee35e5a4249305b450bf247 100644 (file)
@@ -204,9 +204,22 @@ SsaNode* ssa_store(Parser* p, SsaNode* dest, SsaNode* value)
 
 SsaNode* ssa_fieldref(Parser* p, SsaNode* record, char* fname)
 {
+#if 1
     (void)p, (void)record, (void)fname;
     assert(!"record field references unimplemented");
     return NULL;
+#else
+    if (record->mode == MODE_MEMORY && record->code == '[')
+    {
+        record = load(p, record);
+    }
+    index = load(p, index);
+    SsaNode* node = ssa_node('[', MODE_MEMORY);
+    node->type = array->type->base;
+    node->left = array;
+    node->right = index;
+    return node;
+#endif
 }
 
 SsaNode* ssa_index(Parser* p, SsaNode* array, SsaNode* index)
index b837bd4d829abb9ec4f09eba1e75032ad569a44c..0c8f2607c69e0761e67f2c4ab0e6d52778ac8ee2 100644 (file)
@@ -1,15 +1,25 @@
 module Module
 
+type
+  FooRec = record
+    a : Int
+    b : record
+      c : Int
+    end
+    d : array 5 of Int
+  end
+
 var
   vBool* : Bool
   vInt* : Int
   vReal : Real
   vIntArray : array 42 of Int
   vIntArray2 : array 5 of array 5 of Int
-#  vRec : record
-#    a : Int
-#    b : array 5 of Int
-#  end
+  vRec1 : FooRec
+  vRec2 : record
+    a : Int
+    b : array 5 of Int
+  end
 
 procedure TestReturnVoid()
 begin
@@ -160,107 +170,15 @@ begin
     vIntArray2[0][1] = vIntArray2[1][1] + vIntArray2[2][1];
 end
 
-#procedure TestRecordAccess()
-#begin
-#end
+procedure TestRecordAccess()
+begin
+#    vRec2.a = vRec2.a + vRec2.a;
+end
 
-#import
-#  Foo
-#  Bar3 = Bar2
-#
-#const
-#  A* = true
-#  B* = 42
-#  C* = 42.0
-#  D = -B
-#  E = -C
-#  F = not A
-#  G = B + 2 - 2 * 2
-#  H = false or A
-#
-#type
-#  TypeA* = Int
-#  TypeB* = array 5*B of Int
-#  TypeC* = array 5 of array 10 of Int
-#  TypeD* = record
-#    x,y : Int
-#    label : array 10 of Int
-#    dim : record
-#      w,h : Int
-#    end
-#  end
-#  TypeE* = record
-#    i : Int
-#    a : array 5 of Int
-#  end
-#  TypeF* = array 5 of TypeE
-#
-#var
-#  a* : Bool
-#  b* : Int
-#  c : Int
-#  d : Real
-#  e : Real
-#  f : array 5 of array 10 of Int
-#  g : TypeD
-#  h : array 5 of Int
-#  i : TypeF
-#  j : TypeA
-#
-##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
-##    a = 42;
-##    return a;
-##end
-##
-##procedure Baz*(a : Int)
-##begin
-##    if (1 > 2) then
-##        42;
-##    else
-##        24;
-##    end
-##end
-#
+procedure TestNestedRecordAccess()
 begin
-##  # Unary ops
-##  b = +b;
-##  b = -b;
-##
-##  # Function calls
-##  c = Foo(1,2);
-##  e[0] = 1;
-##  Foo(1,2);
-##  e[2][1] = 1 +  e[2][1];
-##  e[b] = 1;
-##    e[1][2] = 1;
-##    c = e[1][c];
-##  c = f.dim.w;
-##  f.dim.h = 0;
-##  f.label[0] = 42;
-#
-##    c = 4;
-##    g[c] = 42;
-##    e[0][9] = 42;
-#
-##    c = Bar(42);
-##    c = 42;
-##    c = 24;
-#
-##    Bar(Foo.testint);
-##    Bar(Bar2.testint);
-##    Bar(Bar3.testint);
+#    vRec2.a.b = vRec2.a.b + vRec2.a.b;
 end
+
+#begin
+#end