typing: add `ARangeExpr::init_callsite` and use it everywhere
[nit.git] / src / global_compiler.nit
index 004c8a3..bcb66ba 100644 (file)
@@ -25,6 +25,7 @@ module global_compiler
 
 import abstract_compiler
 import rapid_type_analysis
+import compiler_ffi
 
 redef class ModelBuilder
        # Entry point to performs a global compilation on the AST of a complete program.
@@ -236,12 +237,16 @@ class GlobalCompiler
                v.add("res->value = value;")
                v.add("return (val*)res;")
                v.add("\}")
-
        end
 
        redef fun new_visitor do return new GlobalCompilerVisitor(self)
 
        private var collect_types_cache: HashMap[MType, Array[MClassType]] = new HashMap[MType, Array[MClassType]]
+
+       redef fun compile_nitni_structs
+       do
+               self.header.add_decl("struct nitni_instance \{ val *value; \};")
+       end
 end
 
 # A visitor on the AST of property definition that generate the C code.
@@ -269,6 +274,8 @@ class GlobalCompilerVisitor
                        end
                        self.add("{res} = BOX_{valtype.c_name}({value}); /* autobox from {value.mtype} to {mtype} */")
                        return res
+               else if value.mtype.cname_blind == "void*" and mtype.cname_blind == "void*" then
+                       return value
                else
                        # Bad things will appen!
                        var res = self.new_var(mtype)
@@ -375,7 +382,7 @@ class GlobalCompilerVisitor
                                        self.add("{res} = 1; /* {args[1].inspect} cannot be null */")
                                end
                        else
-                               self.add_abort("Reciever is null")
+                               self.add_abort("Receiver is null")
                        end
                        self.add "\} else"
                end
@@ -447,11 +454,7 @@ class GlobalCompilerVisitor
        # Finalizes a call to a method ´m´ on type ´recvtype´ with arguments ´args´
        private fun finalize_call(m: MMethodDef, recvtype: MClassType, args: Array[RuntimeVariable]): nullable RuntimeVariable
        do
-               if args.length != m.msignature.arity + 1 then # because of self
-                       add("printf(\"NOT YET IMPLEMENTED: Invalid arity for {m}. {args.length} arguments given.\\n\"); show_backtrace(1);")
-                       debug("NOT YET IMPLEMENTED: Invalid arity for {m}. {args.length} arguments given.")
-                       return null
-               end
+               assert args.length == m.msignature.arity + 1 else debug("Invalid arity for {m}. {args.length} arguments given.")
 
                var rm = new CustomizedRuntimeFunction(m, recvtype)
                return rm.call(self, args)
@@ -699,10 +702,7 @@ class GlobalCompilerVisitor
        redef fun type_test(value, mtype, tag)
        do
                mtype = self.anchor(mtype)
-               var mclasstype = mtype
-               if mtype isa MNullableType then mclasstype = mtype.mtype
-               assert mclasstype isa MClassType
-               if not self.compiler.runtime_type_analysis.live_cast_types.has(mclasstype) then
+               if not self.compiler.runtime_type_analysis.live_cast_types.has(mtype) then
                        debug "problem: {mtype} was detected cast-dead"
                        abort
                end