engines: use `callsite.msignature` in ASuperExpr
[nit.git] / src / abstract_compiler.nit
index 7d10d12..76d2e6c 100644 (file)
@@ -540,7 +540,12 @@ abstract class AbstractCompiler
                var ost = modelbuilder.toolcontext.opt_stacktrace.value
 
                if ost == null then
-                       ost = "nitstack"
+                       var platform = mainmodule.target_platform
+                       if platform != null and not platform.supports_libunwind then
+                               ost = "none"
+                       else
+                               ost = "nitstack"
+                       end
                        modelbuilder.toolcontext.opt_stacktrace.value = ost
                end
 
@@ -1545,6 +1550,7 @@ redef class MMethodDef
        # Can the body be inlined?
        fun can_inline(v: VISITOR): Bool
        do
+               if is_abstract then return true
                var modelbuilder = v.compiler.modelbuilder
                if modelbuilder.mpropdef2npropdef.has_key(self) then
                        var npropdef = modelbuilder.mpropdef2npropdef[self]
@@ -1617,13 +1623,16 @@ redef class APropdef
        fun can_inline: Bool do return true
 end
 
-redef class AConcreteMethPropdef
+redef class AMethPropdef
        redef fun compile_to_c(v, mpropdef, arguments)
        do
-               for i in [0..mpropdef.msignature.arity[ do
-                       var variable = self.n_signature.n_params[i].variable.as(not null)
-                       v.assign(v.variable(variable), arguments[i+1])
+               if mpropdef.is_abstract then
+                       var cn = v.class_name_string(arguments.first)
+                       v.add("fprintf(stderr, \"Runtime error: Abstract method `%s` called on `%s`\", \"{mpropdef.mproperty.name.escape_to_c}\", {cn});")
+                       v.add_raw_abort
+                       return
                end
+
                # Call the implicit super-init
                var auto_super_inits = self.auto_super_inits
                if auto_super_inits != null then
@@ -1636,7 +1645,23 @@ redef class AConcreteMethPropdef
                                v.compile_callsite(auto_super_init, args)
                        end
                end
-               v.stmt(self.n_block)
+
+               var n_block = n_block
+               if n_block != null then
+                       for i in [0..mpropdef.msignature.arity[ do
+                               var variable = self.n_signature.n_params[i].variable.as(not null)
+                               v.assign(v.variable(variable), arguments[i+1])
+                       end
+                       v.stmt(n_block)
+               else if mpropdef.is_intern then
+                       compile_intern_to_c(v, mpropdef, arguments)
+               else if mpropdef.is_extern then
+                       if mpropdef.mproperty.is_init then
+                               compile_externinit_to_c(v, mpropdef, arguments)
+                       else
+                               compile_externmeth_to_c(v, mpropdef, arguments)
+                       end
+               end
        end
 
        redef fun can_inline
@@ -1648,10 +1673,8 @@ redef class AConcreteMethPropdef
                if nblock isa ABlockExpr and nblock.n_expr.length == 0 then return true
                return false
        end
-end
 
-redef class AInternMethPropdef
-       redef fun compile_to_c(v, mpropdef, arguments)
+       fun compile_intern_to_c(v: AbstractCompilerVisitor, mpropdef: MMethodDef, arguments: Array[RuntimeVariable])
        do
                var pname = mpropdef.mproperty.name
                var cname = mpropdef.mclassdef.mclass.name
@@ -1884,10 +1907,8 @@ redef class AInternMethPropdef
                v.add("printf(\"NOT YET IMPLEMENTED {class_name}:{mpropdef} at {location.to_s}\\n\");")
                debug("Not implemented {mpropdef}")
        end
-end
 
-redef class AExternMethPropdef
-       redef fun compile_to_c(v, mpropdef, arguments)
+       fun compile_externmeth_to_c(v: AbstractCompilerVisitor, mpropdef: MMethodDef, arguments: Array[RuntimeVariable])
        do
                var externname
                var nextern = self.n_extern
@@ -1916,10 +1937,8 @@ redef class AExternMethPropdef
                        v.ret(res)
                end
        end
-end
 
-redef class AExternInitPropdef
-       redef fun compile_to_c(v, mpropdef, arguments)
+       fun compile_externinit_to_c(v: AbstractCompilerVisitor, mpropdef: MMethodDef, arguments: Array[RuntimeVariable])
        do
                var externname
                var nextern = self.n_extern
@@ -2015,15 +2034,6 @@ redef class AClassdef
        end
 end
 
-redef class ADeferredMethPropdef
-       redef fun compile_to_c(v, mpropdef, arguments) do
-               var cn = v.class_name_string(arguments.first)
-               v.add("fprintf(stderr, \"Runtime error: Abstract method `%s` called on `%s`\", \"{mpropdef.mproperty.name.escape_to_c}\", {cn});")
-               v.add_raw_abort
-       end
-       redef fun can_inline do return true
-end
-
 redef class AExpr
        # Try to compile self as an expression
        # Do not call this method directly, use `v.expr` instead
@@ -2555,7 +2565,7 @@ redef class ASuperExpr
                if callsite != null then
                        # Add additionnals arguments for the super init call
                        if args.length == 1 then
-                               for i in [0..callsite.mproperty.intro.msignature.arity[ do
+                               for i in [0..callsite.msignature.arity[ do
                                        args.add(v.frame.arguments[i+1])
                                end
                        end
@@ -2689,3 +2699,44 @@ redef class MModule
        # Note: can return null instead of an empty set
        fun collect_linker_libs: nullable Set[String] do return null
 end
+
+# Create a tool context to handle options and paths
+var toolcontext = new ToolContext
+
+var opt_mixins = new OptionArray("Additionals module to min-in", "-m")
+toolcontext.option_context.add_option(opt_mixins)
+
+toolcontext.tooldescription = "Usage: nitg [OPTION]... file.nit\nCompiles Nit programs."
+
+# We do not add other options, so process them now!
+toolcontext.process_options(args)
+
+# We need a model to collect stufs
+var model = new Model
+# An a model builder to parse files
+var modelbuilder = new ModelBuilder(model, toolcontext)
+
+var arguments = toolcontext.option_context.rest
+if arguments.length > 1 then
+       print "Too much arguments: {arguments.join(" ")}"
+       print toolcontext.tooldescription
+       exit 1
+end
+var progname = arguments.first
+
+# Here we load an process all modules passed on the command line
+var mmodules = modelbuilder.parse([progname])
+mmodules.add_all modelbuilder.parse(opt_mixins.value)
+
+if mmodules.is_empty then return
+modelbuilder.run_phases
+
+var mainmodule
+if mmodules.length == 1 then
+       mainmodule = mmodules.first
+else
+       mainmodule = new MModule(model, null, mmodules.first.name, mmodules.first.location)
+       mainmodule.set_imported_mmodules(mmodules)
+end
+
+toolcontext.run_global_phases(mmodules)