diff gen/CodeGen.d @ 72:628cb46ab13b new_gen

First update on the way to Arrays! :) Lexer and ast/Exp now have the types needed. All that needs to be updated now is the Parser. I suggest two options: 1) Making the Id a class that we can make a ArrayId and PointerId for at some point. 2) Use a struct as now, but adding some bools / ints to give a more abstract description of the type 2) is messy and 1) is slower... :/
author Anders Johnsen <skabet@gmail.com>
date Thu, 01 May 2008 23:08:41 +0200
parents 70a002b3fba4
children 192da4976daa
line wrap: on
line diff
--- a/gen/CodeGen.d	Thu May 01 19:51:22 2008 +0200
+++ b/gen/CodeGen.d	Thu May 01 23:08:41 2008 +0200
@@ -480,6 +480,7 @@
 
     Value getPointer(Exp exp)
     {
+        Stdout("lala ")(exp).newline;
         switch(exp.expType)
         {
             case ExpType.Identifier:
@@ -488,6 +489,7 @@
                 return table.find(sym.id.get);
             case ExpType.MemberReference:
                 auto mem = cast(MemberReference)exp;
+                Stdout(mem.target).newline;
                 switch(mem.target.expType)
                 {
                     case ExpType.Identifier:
@@ -508,6 +510,22 @@
                         Value val = b.buildGEP(v, vals, sym.id.get~"."~child.get);
                         return val;
 
+                    case ExpType.MemberReference:
+                        auto v = getPointer(mem.target);
+                        auto child = mem.child;
+                        auto symChild = child.env.find(child);
+                        DType t = mem.target.type;
+                        auto st = t.asStruct;
+
+                        int i = st.indexOf(child.get);
+
+                        Value[] vals;   
+                        vals ~= ConstantInt.Get(IntegerType.Int32, 0, false);
+                        vals ~= ConstantInt.Get(IntegerType.Int32, i, false);
+
+                        Value val = b.buildGEP(v, vals, "."~child.get);
+                        return val;
+
                     default:
                         Value val = genExpression(exp);
                         auto AI = b.buildAlloca(val.type, ".s");