Prepare Nit code for inherited and automatic constructors.
[nit.git] / src / compiling / compiling_global.nit
index 5ae0cb0..b2c6931 100644 (file)
@@ -23,7 +23,7 @@ private import syntax
 
 # Something that store color of table elements
 class ColorContext
-       attr _colors: HashMap[TableElt, Int]
+       attr _colors: HashMap[TableElt, Int] = null
 
        # The color of a table element.
        meth color(e: TableElt): Int
@@ -473,16 +473,15 @@ redef class MMSrcModule
                if not has_global_class_named(sysname) then
                        print("No main")
                else
-                       var sys = class_by_name(sysname).get_type
-                       var main = sys.select_method(once "init".to_symbol)
-                       if main == null then
-                               main = sys.select_method(once "main".to_symbol)
-                       end
-                       if main == null then
+                       var sys = class_by_name(sysname)
+                       # var initm = sys.select_method(once "init".to_symbol)
+                       var mainm = sys.select_method(once "main".to_symbol)
+                       if mainm == null then
                                print("No main")
                        else
+                               #v.add_instr("G_sys = NEW_{initm.cname}();")
                                v.add_instr("G_sys = NEW_Sys();")
-                               v.add_instr("{main.cname}(G_sys);")
+                               v.add_instr("{mainm.cname}(G_sys);")
                        end
                end
                v.add_instr("return 0;")
@@ -493,7 +492,7 @@ redef class MMSrcModule
        # Compile sep files 
        meth compile_mod_to_c(v: CompilerVisitor)
        do
-               v.add_decl("#define LOCATE_{name} \"{filename}\"")
+               v.add_decl("extern const char *LOCATE_{name};")
                if not v.tc.global then
                        v.add_decl("extern const int SFT_{name}[];")
                end
@@ -519,7 +518,6 @@ redef class MMSrcModule
                                                v.add_decl("#define {pg.attr_access}(recv) ATTR(recv, {pg.color_id})")
                                        end
                                end
-                               assert p isa MMSrcLocalProperty
                                p.compile_property_to_c(v)
                        end
                end
@@ -528,6 +526,8 @@ redef class MMSrcModule
        # Compile module file for the current module
        meth compile_local_table_to_c(v: CompilerVisitor)
        do
+               v.add_instr("const char *LOCATE_{name} = \"{filename}\";")
+
                if v.tc.global or _local_table.is_empty then
                        return
                end
@@ -557,11 +557,11 @@ end
 
 class TableEltPropPos
 special LocalTableElt
-       attr _property: MMSrcLocalProperty
+       attr _property: MMLocalProperty
        redef meth symbol do return _property.global.color_id
        redef meth value(ga) do return "{ga.color(self)} /* Property {_property} */"
 
-       init(p: MMSrcLocalProperty)
+       init(p: MMLocalProperty)
        do
                _property = p
        end
@@ -592,7 +592,7 @@ special TableEltPropPos
                                found = true
                        else if found and c.che < s then
                                var p = s[g]
-                               if p != null and p isa MMConcreteProperty then
+                               if p != null then
                                        #print "found {s.module}::{s}::{p}"
                                        return p.cname
                                end
@@ -818,7 +818,7 @@ redef class MMLocalClass
                        if e == null then
                                v.add_instr("\{0} /* Class Hole :( */,")
                        else
-                               v.add_instr("\{(int) {e.compile_to_c(v, self)}},")
+                               v.add_instr("\{(bigint) {e.compile_to_c(v, self)}},")
                        end
                end
                if clen > ctab.length then
@@ -854,9 +854,8 @@ redef class MMLocalClass
                                var t = p.signature.return_type
                                if p isa MMAttribute and t != null then
                                        # FIXME: Not compatible with sep compilation
-                                       var pi = p.concrete_property
-                                       assert pi isa MMSrcAttribute
-                                       var np = pi.node
+                                       assert p isa MMSrcAttribute
+                                       var np = p.node
                                        assert np isa AAttrPropdef
                                        var ne = np.n_expr
                                        if ne != null then
@@ -896,7 +895,7 @@ redef class MMLocalClass
                                v.indent
                                v.add_instr(init_table_decl)
                                v.add_instr("val_t self = NEW_{name}();")
-                               v.add_instr("{p.concrete_property.cname}({args.join(", ")});")
+                               v.add_instr("{p.cname}({args.join(", ")});")
                                v.add_instr("return self;")
                                v.unindent
                                v.add_instr("}")