tests: fix sav file for test_for_times
[nit.git] / src / native_interface / ni_metamodel.nit
index 51bc8ca..08df52b 100644 (file)
@@ -32,13 +32,21 @@ redef class MMType
                        return "nullable_{local_class.name.to_s}"
                else if pi == null then
                        return local_class.name.to_s
-               else if local_class.global.is_extern then
-                       return local_class.name.to_s
                else
                        return pi.cname
                end
        end
 
+       fun mangled_name: String
+       do
+               var pi = local_class.primitive_info
+               if is_nullable then
+                       return "nullable_{local_class.name.to_s}"
+               else
+                       return local_class.name.to_s
+               end
+       end
+
        # Return the expression to convert this type from its native version.
        fun from_native( name : String ) : String
        do
@@ -46,7 +54,7 @@ redef class MMType
                        not is_nullable then
                        return boxtype( name )
                else
-                       var getter = "{name}.v"
+                       var getter = "{name}->ref.val"
 
                        return boxtype( getter )
                end
@@ -60,7 +68,7 @@ redef class MMType
                        not is_nullable then
                        return "{native_name} = {unboxtype( nit_name )}"
                else
-                       return "{native_name}.v = {unboxtype( nit_name )}"
+                       return "{native_name}->ref.val = {unboxtype( nit_name )}"
                end
        end
 
@@ -72,9 +80,21 @@ redef class MMType
                        not is_nullable then # int, float, point/void* ...
                        return "{nit_name} = {boxtype(native_name)}"
                else
-                       return "{nit_name} = {"{native_name}.v"}"
+                       return "{nit_name} = {native_name}->ref.val"
                end
        end
+
+       fun uses_nitni_ref : Bool do return local_class.primitive_info == null or is_nullable
+
+       fun friendly_null_getter : String
+       do
+               return "null_{as_notnull.mangled_name}"
+       end
+       
+       fun local_friendly_null_getter_from( m : MMModule ) : String
+       do
+               return "{m.to_s}_{friendly_null_getter}"
+       end
 end
 
 redef class MMMethod
@@ -99,7 +119,7 @@ redef class MMMethod
        do
                var params = new List[String]
 
-               if not is_init then
+               if not global.is_init then
                        params.add( "{local_class.get_type.friendly_extern_name} recv" )
                end
 
@@ -124,7 +144,7 @@ redef class MMMethod
                # return type
                if signature.return_type != null then
                        s.append( "{signature.return_type.friendly_extern_name} " )
-               else if is_init then
+               else if global.is_init then
                        s.append( "{local_class.get_type.friendly_extern_name} " )
                else
                        s.append( "void " )
@@ -174,15 +194,8 @@ redef class MMMethod
        private fun cparams : List[ String ]
        do
                var params = new List[String]
-
-               if not is_init then
-                       params.add( "val_t recv" )
-               end
-
-               for p in signature.params do
-                       params.add( "val_t {p.name}" )
-               end
-
+               if not global.is_init then params.add( "val_t recv" )
+               for p in signature.params do params.add( "val_t {p.name}" )
                return params
        end
 
@@ -191,14 +204,14 @@ redef class MMMethod
                var s = new Buffer
 
                # return type
-               if signature.return_type != null or is_init then
+               if signature.return_type != null or global.is_init then
                        s.append( "val_t " )
                else
                        s.append( "void " )
                end
 
                # function name
-               if is_init then
+               if global.is_init then
                        s.append( "NEW_{local_class}_{cname}" )
                else
                        s.append( "{friendly_extern_name(local_class)}___out" )
@@ -219,16 +232,16 @@ redef class MMImportedCast
                if is_about_nullable_only then
                        if is_not_null_to_nullable  then # to null
                                # nullable_Object Object_as_nullable( Object o )
-                               return "{from.friendly_extern_name}_as_nullable"
+                               return "{from.mangled_name}_as_nullable"
                        else if is_nullable_to_not_null then # from null
                                # Object Object_as_not_null( nullable_Object o )
-                               return "{to.friendly_extern_name}_as_not_null"
+                               return "{to.mangled_name}_as_not_null"
                        else
                                abort
                        end
                else # inter types
                        # String Object_as_String( Object o )
-                       return "{from.friendly_extern_name}_as_{to.friendly_extern_name}"
+                       return "{from.mangled_name}_as_{to.mangled_name}"
                end
        end
 
@@ -253,13 +266,13 @@ redef class MMImportedCast
                        else if is_nullable_to_not_null then # from null
                                # Object_is_null( nullable_Object o )
                                # is opposite from others
-                               return "{to.local_class}_is_null"
+                               return "{to.mangled_name}_is_null"
                        else
                                abort
                        end
                else # inter types
                        # Object_is_a_String( Object o )
-                       return "{from.friendly_extern_name}_is_a_{to.friendly_extern_name}"
+                       return "{from.mangled_name}_is_a_{to.mangled_name}"
                end
        end