compile: work on MM classes instead of MMSrc classes
authorJean Privat <jean@pryen.org>
Tue, 7 Jul 2009 20:10:34 +0000 (16:10 -0400)
committerJean Privat <jean@pryen.org>
Tue, 7 Jul 2009 20:10:34 +0000 (16:10 -0400)
only consider MMSrc classes in special cases.

Signed-off-by: Jean Privat <jean@pryen.org>

src/compiling/compiling.nit
src/compiling/compiling_base.nit
src/compiling/compiling_global.nit
src/compiling/compiling_methods.nit
src/nitc.nit

index a713e15..b90ca12 100644 (file)
@@ -22,7 +22,7 @@ private import compiling_methods
 private import compiling_global
 private import syntax
 
-redef class MMSrcModule
+redef class MMModule
        # Compile the program
        # Generate all sep files (_sep.[ch]), the main file (_table.c) and the build file (_build.sh)
        # Then execute the build.sh
@@ -30,7 +30,6 @@ redef class MMSrcModule
        do
                tc.info("Building tables",1)
                for m in mhe.greaters_and_self do
-                       assert m isa MMSrcModule
                        tc.info("Building tables for module: {m.name}",2)
                        m.local_analysis(tc)
                end
@@ -45,7 +44,6 @@ redef class MMSrcModule
                files.add("$CLIBDIR/nit_main.c")
                tc.info("Generating C code",1)
                for m in mhe.greaters_and_self do
-                       assert m isa MMSrcModule
                        files.add("{tc.compdir}/{m.name}._sep.c")
                        tc.info("Generating C code for module: {m.name}",2)
                        m.compile_separate_module(tc, ga)
index d61e55c..cddf846 100644 (file)
@@ -87,7 +87,7 @@ class CompilerVisitor
        end
 
        # The processed module
-       readable var _module: MMSrcModule
+       readable var _module: MMModule
 
        # Where instr and decl are stored
        readable writable var _ctx: CContext = new CContext
@@ -99,7 +99,7 @@ class CompilerVisitor
        readable var _tc: ToolContext
 
        # Create a new CompilerVisitor based on a module
-       init(module: MMSrcModule, tc: ToolContext)
+       init(module: MMModule, tc: ToolContext)
        do
                _module = module
                _tc = tc
index d2217f8..ddd6582 100644 (file)
@@ -61,7 +61,7 @@ special ColorContext
        # FIXME: do something better.
        readable writable var _max_class_table_length: Int = 0
 
-       init(module: MMSrcModule)
+       init(module: MMModule)
        do
                _module = module
        end
@@ -71,7 +71,7 @@ class GlobalCompilerVisitor
 special CompilerVisitor
        # The global analysis result
        readable var _global_analysis: GlobalAnalysis
-       init(m: MMSrcModule, tc: ToolContext, ga: GlobalAnalysis)
+       init(m: MMModule, tc: ToolContext, ga: GlobalAnalysis)
        do
                super(m, tc)
                _global_analysis = ga
@@ -102,7 +102,7 @@ special ColorContext
        init(c: MMLocalClass) do _local_class = c
 end
 
-redef class MMSrcLocalClass
+redef class MMConcreteClass
        # The table element of the subtype check
        fun class_color_pos: TableEltClassColor do return _class_color_pos.as(not null)
        var _class_color_pos: nullable TableEltClassColor
@@ -126,16 +126,16 @@ redef class MMSrcLocalClass
                        module_table.add(cpp)
                        clt.add(new TableEltClassInitTable(self))
                end
-               for p in src_local_properties do
+               for p in local_local_properties do
                        var pg = p.global
                        if pg.intro == p then
-                               if p isa MMSrcAttribute then
+                               if p isa MMAttribute then
                                        ilt.add(new TableEltAttr(p))
-                               else if p isa MMSrcMethod then
+                               else if p isa MMMethod then
                                        clt.add(new TableEltMeth(p))
                                end
                        end
-                       if p isa MMSrcMethod and p.need_super then
+                       if p isa MMMethod and p.need_super then
                                clt.add(new TableEltSuper(p))
                        end
                end
@@ -154,15 +154,17 @@ redef class MMSrcLocalClass
        end
 end
 
-redef class MMSrcModule
+redef class MMModule
        # The local table of the module (refers things introduced in the module)
        var _local_table: Array[ModuleTableElt] = new Array[ModuleTableElt]
 
        # Builds the local tables and local classes layouts
        fun local_analysis(tc: ToolContext)
        do
-               for c in src_local_classes do
-                       c.build_layout_in(tc, _local_table)
+               for c in local_classes do
+                       if c isa MMConcreteClass then
+                               c.build_layout_in(tc, _local_table)
+                       end
                end
        end
 
@@ -218,7 +220,7 @@ redef class MMSrcModule
 
                        # Store the colortableelt in the class table pool
                        var bc = c.global.intro
-                       assert bc isa MMSrcLocalClass
+                       assert bc isa MMConcreteClass
                        ctab.add(bc.class_color_pos)
                end
 
@@ -252,7 +254,7 @@ redef class MMSrcModule
                                assert cc.class_table.is_empty
                                cc.class_table.add_all(scc.class_table)
                                var bc = c.global.intro
-                               assert bc isa MMSrcLocalClass
+                               assert bc isa MMConcreteClass
                                var colpos = bc.class_color_pos
                                var colposcolor = cc.class_table.length
                                ga.color(colpos) = colposcolor
@@ -268,7 +270,7 @@ redef class MMSrcModule
                        var cte = cc.class_layout
                        var ite = cc.instance_layout
                        for sc in c.crhe.greaters_and_self do
-                               if sc isa MMSrcLocalClass then
+                               if sc isa MMConcreteClass then
                                        cte.add(sc, sc.class_layout)
                                        ite.add(sc, sc.instance_layout)
                                end
@@ -303,7 +305,7 @@ redef class MMSrcModule
                                cc.class_table.clear
                                cc.class_table.add_all(scc.class_table)
                                var bc = c.global.intro
-                               assert bc isa MMSrcLocalClass
+                               assert bc isa MMConcreteClass
                                var colpos = bc.class_color_pos
                                cc.class_table[ga.color(colpos)] = colpos
                                while cc.class_table.length <= maxcolor do
@@ -415,7 +417,6 @@ redef class MMSrcModule
        fun compile_tables_to_c(v: GlobalCompilerVisitor)
        do
                for m in mhe.greaters_and_self do
-                       assert m isa MMSrcModule
                        m.compile_local_table_to_c(v)
                end
 
@@ -488,7 +489,8 @@ redef class MMSrcModule
                        end
                        e.compile_macros(v, value)
                end
-               for c in src_local_classes do
+               for c in local_classes do
+                       if not c isa MMConcreteClass then continue
                        for pg in c.global_properties do
                                var p = c[pg]
                                if p.local_class == c then
index 294f17a..7ee3c3d 100644 (file)
@@ -272,7 +272,7 @@ end
 # A Nit method currenlty compiled
 class NitMethodContext
        # Current method compiled
-       readable var _method: nullable MMSrcMethod
+       readable var _method: nullable MMMethod
 
        # Association between parameters and the corresponding variables
        readable writable var _method_params: nullable Array[ParamVariable]
@@ -295,7 +295,7 @@ class NitMethodContext
        # Variable where a functionnal nit continue must store its value
        readable writable var _continue_value: nullable String
 
-       init(method: nullable MMSrcMethod)
+       init(method: nullable MMMethod)
        do
                _method = method
        end
@@ -307,6 +307,36 @@ redef class ClosureVariable
        readable writable var _ctypename: nullable String
 end
 
+redef class MMAttribute
+       # Compile a read acces on selffor a given reciever.
+       fun compile_isset(v: CompilerVisitor, n: PNode, recv: String): String
+       do
+               return "TAG_Bool({global.attr_access}({recv})!=NIT_NULL) /* isset {local_class}::{name}*/"
+       end
+
+       # Compile a read acces on selffor a given reciever.
+       fun compile_read_access(v: CompilerVisitor, n: PNode, recv: String): String
+       do
+               var res = "{global.attr_access}({recv}) /*{local_class}::{name}*/"
+               if not signature.return_type.is_nullable then
+                       res = v.ensure_var(res, "{local_class}::{name}")
+                       v.add_instr("if ({res} == NIT_NULL) \{ fprintf(stderr, \"Uninitialized attribute %s\", \"{name}\"); {v.printf_locate_error(n)} nit_exit(1); } /* implicit isset */;")
+               end
+               return res
+       end
+
+       # Compile a write acces on selffor a given reciever.
+       fun compile_write_access(v: CompilerVisitor, n: nullable PNode, recv: String, value: String)
+       do
+               v.add_instr("{global.attr_access}({recv}) /*{local_class}::{name}*/ = {value};")
+       end
+end
+
+redef class MMLocalProperty
+       # Compile the property as a C property
+       fun compile_property_to_c(v: CompilerVisitor) do end
+end
+
 redef class MMMethod
        # Compile as an expression.
        # require that signature.return_type != null
@@ -451,39 +481,6 @@ redef class MMMethod
        do
                return "FWBT_{cname}_{i}"
        end
-end
-
-redef class MMAttribute
-       # Compile a read acces on selffor a given reciever.
-       fun compile_isset(v: CompilerVisitor, n: PNode, recv: String): String
-       do
-               return "TAG_Bool({global.attr_access}({recv})!=NIT_NULL) /* isset {local_class}::{name}*/"
-       end
-
-       # Compile a read acces on selffor a given reciever.
-       fun compile_read_access(v: CompilerVisitor, n: PNode, recv: String): String
-       do
-               var res = "{global.attr_access}({recv}) /*{local_class}::{name}*/"
-               if not signature.return_type.is_nullable then
-                       res = v.ensure_var(res, "{local_class}::{name}")
-                       v.add_instr("if ({res} == NIT_NULL) \{ fprintf(stderr, \"Uninitialized attribute %s\", \"{name}\"); {v.printf_locate_error(n)} nit_exit(1); } /* implicit isset */;")
-               end
-               return res
-       end
-
-       # Compile a write acces on selffor a given reciever.
-       fun compile_write_access(v: CompilerVisitor, n: nullable PNode, recv: String, value: String)
-       do
-               v.add_instr("{global.attr_access}({recv}) /*{local_class}::{name}*/ = {value};")
-       end
-end
-
-redef class MMLocalProperty
-       # Compile the property as a C property
-       fun compile_property_to_c(v: CompilerVisitor) do end
-end
-
-redef class MMSrcMethod
 
        # Compile and declare the signature to C
        protected fun decl_csignature(v: CompilerVisitor, args: Array[String]): String
@@ -681,7 +678,7 @@ end
 
 redef class AMethPropdef
        # Compile the method body
-       fun do_compile_inside(v: CompilerVisitor, method: MMSrcMethod, params: Array[String]): nullable String is abstract
+       fun do_compile_inside(v: CompilerVisitor, method: MMMethod, params: Array[String]): nullable String is abstract
 end
 
 redef class PSignature
index bc788ae..6a11696 100644 (file)
@@ -95,7 +95,6 @@ special AbstractCompiler
        redef fun perform_work(mods)
        do
                for mod in mods do
-                       assert mod isa MMSrcModule
                        mod.compile_prog_to_c(self)
                end