# HG changeset patch # User Anders Johnsen # Date 1209742430 -7200 # Node ID 682e20aa224ff275f23c8a4db8194137ba33d8ba # Parent 81813366ef927d81fc1317d22f820b720f4acddc Pointers working now - big YAY diff -r 81813366ef92 -r 682e20aa224f ast/Exp.d --- 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 diff -r 81813366ef92 -r 682e20aa224f gen/CodeGen.d --- 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; diff -r 81813366ef92 -r 682e20aa224f parser/Parser.d --- 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); diff -r 81813366ef92 -r 682e20aa224f sema/DType.d --- 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"); diff -r 81813366ef92 -r 682e20aa224f sema/ImplicitCast.d --- 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");