diff gen/CodeGen.d @ 54:d84fec04d462 new_gen

Move all root var-decls so they are generated before anything else This allows forward references to globals Added a few tests, testing that scoping is proper and forward referencing of structs and globals
author Anders Halager <halager@gmail.com>
date Sat, 26 Apr 2008 19:13:10 +0200
parents da551f90e03f
children 79cb0afafabe
line wrap: on
line diff
--- a/gen/CodeGen.d	Sat Apr 26 18:52:27 2008 +0200
+++ b/gen/CodeGen.d	Sat Apr 26 19:13:10 2008 +0200
@@ -2,7 +2,7 @@
 
 import tango.io.Stdout,
        Int = tango.text.convert.Integer;
-import tango.core.Array : find;
+import tango.core.Array : find, partition;
 
 import llvm.llvm;
 
@@ -89,6 +89,12 @@
         auto visitor = new VisitFuncDecls(registerFunc);
         visitor.visit(decls);
 
+        // Before beginning we move all top level var-decls to the start
+        // and then we generate the var-decls first
+        // partition is NOT required to be stable, but that should not create
+        // any problems.
+        partition(decls, (Decl d) { return d.declType == DeclType.VarDecl; });
+
         foreach (decl; decls)
             genRootDecl(decl);