Merge: introduce plain_to_s
authorJean Privat <jean@pryen.org>
Fri, 29 May 2015 01:49:02 +0000 (21:49 -0400)
committerJean Privat <jean@pryen.org>
Fri, 29 May 2015 01:49:02 +0000 (21:49 -0400)
In order to have a more POLA `to_s` on collections, it is required that a new method with the old behavior is provided for clients that need it (especially the interpreter that use it for superstrings).

the compiler use `native_to_s` for superstrings but `c_src/nitg` still use `to_s` on array, so a regeneration of the bootstrap is required before changing the behavior of `to_s` on collections.

Pull-Request: #1385
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>
Reviewed-by: Alexandre Blondin Massé <alexandre.blondin.masse@gmail.com>
Reviewed-by: Romain Chanoir <chanoir.romain@courrier.uqam.ca>
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>

lib/standard/file.nit
lib/standard/string.nit
src/interpreter/naive_interpreter.nit
src/rapid_type_analysis.nit
tests/sav/nitserial_args1.res

index 3bad3f3..46c52ec 100644 (file)
@@ -1236,7 +1236,7 @@ end
 # Print `objects` on the standard output (`stdout`).
 fun printn(objects: Object...)
 do
-       sys.stdout.write(objects.to_s)
+       sys.stdout.write(objects.plain_to_s)
 end
 
 # Print an `object` on the standard output (`stdout`) and add a newline.
index 60f3af9..ff46e46 100644 (file)
@@ -2228,6 +2228,12 @@ redef class Collection[E]
        # Concatenate elements.
        redef fun to_s
        do
+               return plain_to_s
+       end
+
+       # Concatenate element without separators
+       fun plain_to_s: String
+       do
                var s = new FlatBuffer
                for e in self do if e != null then s.append(e.to_s)
                return s.to_s
@@ -2263,7 +2269,7 @@ end
 redef class Array[E]
 
        # Fast implementation
-       redef fun to_s
+       redef fun plain_to_s
        do
                var l = length
                if l == 0 then return ""
index b444dd8..9708f3f 100644 (file)
@@ -1629,7 +1629,7 @@ redef class ASuperstringExpr
                        array.add(i)
                end
                var i = v.array_instance(array, v.mainmodule.object_type)
-               var res = v.send(v.force_get_primitive_method("to_s", i.mtype), [i])
+               var res = v.send(v.force_get_primitive_method("plain_to_s", i.mtype), [i])
                assert res != null
                return res
        end
index 81e14fa..8e5565c 100644 (file)
@@ -559,7 +559,7 @@ redef class ASuperstringExpr
        redef fun accept_rapid_type_visitor(v)
        do
                var mmodule = v.analysis.mainmodule
-               var object_type = mmodule.object_type
+               var object_type = mmodule.string_type
                var arraytype = mmodule.array_type(object_type)
                v.add_type(arraytype)
                var nattype = mmodule.native_array_type(object_type)
index b69dc33..b36335e 100644 (file)
@@ -9,10 +9,10 @@ redef class Deserializer
        redef fun deserialize_class(name)
        do
                # Module: test_serialization
-               if name == "Array[Object]" then return new Array[Object].from_deserializer(self)
+               if name == "Array[String]" then return new Array[String].from_deserializer(self)
                if name == "Array[nullable Object]" then return new Array[nullable Object].from_deserializer(self)
                if name == "Array[Serializable]" then return new Array[Serializable].from_deserializer(self)
-               if name == "Array[String]" then return new Array[String].from_deserializer(self)
+               if name == "Array[Object]" then return new Array[Object].from_deserializer(self)
                return super
        end
 end