Merge branch 'ni' into wip
[nit.git] / src / compiling / compiling_icode.nit
index 6deb795..aaa49f0 100644 (file)
@@ -19,6 +19,7 @@ package compiling_icode
 
 import icode
 private import analysis
+import primitive_info
 import compiling_base
 
 # Compiler context from ICode to C
@@ -575,6 +576,11 @@ redef class ICall
        redef fun compile_call_to_c(v, args)
        do
                var w = new Writer
+               
+               # do not compile explicit calls from native methods
+               # theses are really manually called in the native implementation
+               if is_explicit_from_extern then return w
+
                var prop = property
                if prop.global.is_init then args.add("init_table")
                w.add(prop.global.meth_call)
@@ -590,6 +596,10 @@ end
 redef class ISuper
        redef fun compile_call_to_c(v, args)
        do
+               # do not compile explicit calls from native methods
+               # theses are really manually called in the native implementation
+               if is_explicit_from_extern then return new Writer
+
                var prop = property
                if prop.global.is_init then args.add("init_table")
                var w = new Writer
@@ -607,6 +617,11 @@ redef class INew
        redef fun compile_call_to_c(v, args)
        do
                var w = new Writer
+
+               # do not compile explicit calls from native methods
+               # theses are really manually called in the native implementation
+               if is_explicit_from_extern then return w
+
                w.add("NEW_")
                w.add(stype.local_class.to_s)
                w.add("_")
@@ -675,7 +690,7 @@ redef class INative
                v.add_location(location)
                if method.is_intern then
                        compile_intern_method_to_c(v)
-               else if not method.is_init then
+               else if not method.global.is_init then
                        compile_extern_method_to_c(v)
                end
        end
@@ -1024,18 +1039,16 @@ redef class ITypeCheck
        redef fun compile_to_c(v)
        do
                if not need_result then return
-               # FIXME handle formaltypes
                v.add_location(location)
-               var g = stype.local_class.global
-               var recv = v.register(expr)
+               var recv = v.register(expr2)
                var w = new_result(v)
                w.add("TAG_Bool(")
-               if expr.stype.is_nullable then
+               if expr2.stype.is_nullable then
                        if stype.is_nullable then
                                w.add("(")
                                w.add(recv)
                                w.add("==NIT_NULL) || ")
-                       else if stype.as_nullable == expr.stype then
+                       else if stype.as_nullable == expr2.stype then
                                w.add(recv)
                                w.add("!=NIT_NULL)")
                                return
@@ -1045,15 +1058,38 @@ redef class ITypeCheck
                                w.add("!=NIT_NULL) && ")
                        end
                end
-               w.add("VAL_ISA(")
-               w.add(recv)
-               w.add(", ")
-               w.add(g.color_id)
-               w.add(", ")
-               w.add(g.id_id)
-               w.add(")) /*cast ")
-               w.add(stype.to_s)
-               w.add("*/")
+               # FIXME handle formaltypes
+               var t = stype
+               if t isa MMVirtualType then
+                       var slf = v.register(expr1)
+                       var g = t.property.global
+                       w.add("VAL_ISA(")
+                       w.add(recv)
+                       w.add(", ")
+                       w.add(g.vt_class_color)
+                       w.add("(")
+                       w.add(slf)
+                       w.add(")")
+                       w.add(", ")
+                       w.add(g.vt_class_id)
+                       w.add("(")
+                       w.add(slf)
+                       w.add(")")
+                       w.add(")) /*cast ")
+                       w.add(t.to_s)
+                       w.add("*/")
+               else
+                       var g = t.local_class.global
+                       w.add("VAL_ISA(")
+                       w.add(recv)
+                       w.add(", ")
+                       w.add(g.color_id)
+                       w.add(", ")
+                       w.add(g.id_id)
+                       w.add(")) /*cast ")
+                       w.add(t.to_s)
+                       w.add("*/")
+               end
        end
 end