changeset 80:682e20aa224f new_gen

Pointers working now - big YAY
author Anders Johnsen <skabet@gmail.com>
date Fri, 02 May 2008 17:33:50 +0200
parents 81813366ef92
children 110c7e1c4ca2
files ast/Exp.d gen/CodeGen.d parser/Parser.d sema/DType.d sema/ImplicitCast.d
diffstat 5 files changed, 32 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/ast/Exp.d	Fri May 02 16:39:04 2008 +0200
+++ b/ast/Exp.d	Fri May 02 17:33:50 2008 +0200
@@ -238,7 +238,10 @@
         return this;
     }
 
-    override DType type() { return exp.type(); }
+    override DType type() 
+    { 
+        return exp.type().asPointer.pointerOf; 
+    }
 
     public Exp exp;
 }
@@ -361,15 +364,10 @@
 
     override DType type()
     {
-        if (myType !is null)
-            return myType;
-        myType = new DPointer(pointerOf.type);
-        return myType;
+        return pointerOf.type.getPointerTo;
     }
 
     Identifier pointerOf;
-
-    private DType myType;
 }
 
 class ArrayIdentifier : Identifier
--- a/gen/CodeGen.d	Fri May 02 16:39:04 2008 +0200
+++ b/gen/CodeGen.d	Fri May 02 17:33:50 2008 +0200
@@ -490,6 +490,10 @@
                 auto identifier = cast(Identifier)exp;
                 auto sym = exp.env.find(identifier);
                 return table.find(sym.id.get);
+            case ExpType.Deref:
+                auto derefExp = cast(DerefExp)exp;
+                auto target = getPointer(derefExp.exp);
+                return b.buildLoad(target, "deref");
             case ExpType.MemberReference:
                 auto mem = cast(MemberReference)exp;
                 Stdout(mem.target).newline;
--- a/parser/Parser.d	Fri May 02 16:39:04 2008 +0200
+++ b/parser/Parser.d	Fri May 02 17:33:50 2008 +0200
@@ -202,6 +202,13 @@
             default:
                 if (t.isBasicType())
                     goto case Tok.Identifier;
+                if (t.type == Tok.Star)
+                {
+                    auto exp = parseExpression();
+                    require(Tok.Seperator);
+                    return action.actOnExprStmt(exp);
+                }
+                    
                 throw error(__LINE__, "Unexpexted begining of statement.").tok(lexer.peek);
         }
         throw error(__LINE__, "").tok(t);
--- a/sema/DType.d	Fri May 02 16:39:04 2008 +0200
+++ b/sema/DType.d	Fri May 02 17:33:50 2008 +0200
@@ -90,6 +90,14 @@
      */
     bool hasImplicitConversionTo(DType that) { return false; }
 
+    DPointer getPointerTo()
+    {
+        if(myPointer !is null)
+            return myPointer;
+        myPointer = new DPointer(this);
+        return myPointer;
+    }
+
     static DInteger
         Bool,
         Byte, UByte, Short, UShort,
@@ -97,6 +105,8 @@
 
     static DType Void;
 
+    private DPointer myPointer;
+
     static this()
     {
         Void   = new DType("void");
--- a/sema/ImplicitCast.d	Fri May 02 16:39:04 2008 +0200
+++ b/sema/ImplicitCast.d	Fri May 02 17:33:50 2008 +0200
@@ -79,10 +79,12 @@
         auto identifierType = exp.identifier.type;
         auto expType = exp.exp.type;
 
-        if(identifierType.byteSize != expType.byteSize)
+        if(identifierType != expType)
         {
+            Stdout(&identifierType)(identifierType).newline;
+            Stdout(&expType)(expType).newline;
             if(!expType.hasImplicitConversionTo(identifierType))
-                throw error(__LINE__, "Cannot make implicit cast");
+                throw error(__LINE__, "Cannot make implicit cast between");
 
             auto castExp = new CastExp(
                     new Identifier(expType.name),
@@ -98,9 +100,9 @@
 
         if(stmt.exp)
         {
-            auto returnType = (cast(DFunction)stmt.env.parentFunction.type).returnType;
+            auto returnType = stmt.env.parentFunction.type.asFunction.returnType;
             auto expType = stmt.exp.type;
-            if(returnType.byteSize != expType.byteSize)
+            if(returnType != expType)
             {
                 if(!expType.hasImplicitConversionTo(returnType))
                     throw error(__LINE__, "Cannot make implicit cast");