nitg&i: intern implementation of `is_same_instance`
authorJean Privat <jean@pryen.org>
Tue, 26 Nov 2013 20:14:02 +0000 (15:14 -0500)
committerJean Privat <jean@pryen.org>
Tue, 26 Nov 2013 20:14:02 +0000 (15:14 -0500)
Signed-off-by: Jean Privat <jean@pryen.org>

src/abstract_compiler.nit
src/naive_interpreter.nit

index df82067..c41a128 100644 (file)
@@ -1570,6 +1570,9 @@ redef class AInternMethPropdef
                else if pname == "is_same_type" then
                        v.ret(v.is_same_type_test(arguments[0], arguments[1]))
                        return
+               else if pname == "is_same_instance" then
+                       v.ret(v.equal_test(arguments[0], arguments[1]))
+                       return
                else if pname == "output_class_name" then
                        var nat = v.class_name_string(arguments.first)
                        v.add("printf(\"%s\\n\", {nat});")
index d2ccbce..5d996ff 100644 (file)
@@ -481,7 +481,7 @@ abstract class Instance
        fun is_true: Bool do abort
 
        # Return true if `self` IS `o` (using the Nit semantic of is)
-       fun eq_is(o: Instance): Bool do return self is o
+       fun eq_is(o: Instance): Bool do return self.is_same_instance(o)
 
        # Human readable object identity "Type#number"
        redef fun to_s do return "{mtype}"
@@ -537,7 +537,7 @@ class PrimitiveInstance[E: Object]
        redef fun eq_is(o)
        do
                if not o isa PrimitiveInstance[Object] then return false
-               return self.val is o.val
+               return self.val.is_same_instance(o.val)
        end
 
        redef fun to_s do return "{mtype}#{val.object_id}({val})"
@@ -654,6 +654,8 @@ redef class AInternMethPropdef
                        return v.bool_instance(args[0] != args[1])
                else if pname == "is_same_type" then
                        return v.bool_instance(args[0].mtype == args[1].mtype)
+               else if pname == "is_same_instance" then
+                       return v.bool_instance(args[1] != null and args[0].eq_is(args[1]))
                else if pname == "exit" then
                        exit(args[1].to_i)
                        abort