diff gen/CodeGen.d @ 183:8ea749b7da91

Fixed a few errors so that two more tests passes. Also, now you only need a type in a function param.
author Anders Johnsen <skabet@gmail.com>
date Fri, 25 Jul 2008 10:59:16 +0200
parents 59cd211a1bd3
children 7b274cfdc1dc
line wrap: on
line diff
--- a/gen/CodeGen.d	Fri Jul 25 01:40:08 2008 +0200
+++ b/gen/CodeGen.d	Fri Jul 25 10:59:16 2008 +0200
@@ -95,23 +95,22 @@
             (FuncDecl fd)
             {
                 Type[] param_types;
-                foreach (i, p; fd.funcArgs)
+                foreach (i, p; fd.type.params)
                 {
-                    DType t = p.identifier.type;
-                    if (auto st = t.asStruct())
+                    if (auto st = p.asStruct())
                     {
                         Type pointer = PointerType.Get(llvm(st));
                         param_types ~= pointer;
                     }
-                    else if (auto ar = t.asArray())
+                    else if (auto ar = p.asArray())
                     {
                         Type pointer = PointerType.Get(llvm(ar));
                         param_types ~= pointer;
                     }
                     else
-                        param_types ~= llvm(t);
+                        param_types ~= llvm(p);
                 }
-                auto ret_t = fd.identifier.type;
+                auto ret_t = fd.type.returnType;
                 if(auto st = cast(DStruct)ret_t)
                     ret_t = DType.Void;
                 else if(auto f = cast(DFunction)ret_t)
@@ -124,7 +123,7 @@
                     if(i == 0 && fd.sret)
                         llfunc.addParamAttr(0, ParamAttr.StructRet);
 
-                    DType t = p.identifier.type;
+                    DType t = fd.type.params[i];
                     if (auto st = t.asStruct)
                     {
                         if (i == 0 && fd.sret)
@@ -598,9 +597,24 @@
             +/
             case StmtType.For:
                 auto fStmt = cast(ForStmt)stmt;
-                genStmt(fStmt.init);
-                scope inc = new ExpStmt(fStmt.incre);
-                genLoop(stmt.env, fStmt.cond, false, fStmt.forBody, inc);
+                Stmt[] stmts;
+                if(fStmt.init)
+                    genStmt(fStmt.init);
+                ExpStmt inc;
+                if(fStmt.incre)
+                    stmts ~= new ExpStmt(fStmt.incre);
+                Exp cond;
+                if(fStmt.cond)
+                    cond = fStmt.cond;
+                else
+                {
+                    auto i = new IntegerLit(fStmt.loc,"1");
+                    i.number.type = NumberType.Int;
+                    i.number.integer = 1;
+                    cond = i;
+                }
+                stmts ~= fStmt.forBody;
+                genLoop(stmt.env, cond, false, stmts);
                 break;
             case StmtType.Switch:
                 auto sw = cast(SwitchStmt)stmt;