src: Added complete FlatString generation from compiler
authorLucas Bajolet <r4pass@hotmail.com>
Thu, 27 Aug 2015 18:29:25 +0000 (14:29 -0400)
committerLucas Bajolet <r4pass@hotmail.com>
Fri, 28 Aug 2015 19:21:07 +0000 (15:21 -0400)
Signed-off-by: Lucas Bajolet <r4pass@hotmail.com>

lib/core/text/abstract_text.nit
lib/core/text/flat.nit
src/compiler/abstract_compiler.nit
src/interpreter/naive_interpreter.nit
src/rapid_type_analysis.nit

index 1faaad3..584a287 100644 (file)
@@ -1817,6 +1817,12 @@ redef class NativeString
 
        # Returns `self` as a String of `length`.
        fun to_s_with_length(length: Int): String is abstract
+
+       # Returns `self` as a String with `bytelen` and `length` set
+       #
+       # SEE: `abstract_text::Text` for more infos on the difference
+       # between `Text::bytelen` and `Text::length`
+       fun to_s_full(bytelen, unilen: Int): String is abstract
 end
 
 redef class NativeArray[E]
index bebc8e5..bf423ad 100644 (file)
@@ -885,6 +885,10 @@ redef class NativeString
                return str
        end
 
+       redef fun to_s_full(bytelen, unilen) do
+               return new FlatString.full(self, bytelen, 0, bytelen - 1, unilen)
+       end
+
        # Returns `self` as a new String.
        redef fun to_s_with_copy: FlatString
        do
index b58d4a3..2f83449 100644 (file)
@@ -1598,8 +1598,9 @@ abstract class AbstractCompilerVisitor
                var native_mtype = mmodule.native_string_type
                var nat = self.new_var(native_mtype)
                self.add("{nat} = \"{string.escape_to_c}\";")
-               var length = self.int_instance(string.bytelen)
-               self.add("{res} = {self.send(self.get_property("to_s_with_length", native_mtype), [nat, length]).as(not null)};")
+               var bytelen = self.int_instance(string.bytelen)
+               var unilen = self.int_instance(string.length)
+               self.add("{res} = {self.send(self.get_property("to_s_full", native_mtype), [nat, bytelen, unilen]).as(not null)};")
                self.add("{name} = {res};")
                self.add("\}")
                return res
index 1181cf0..23a7b0c 100644 (file)
@@ -343,7 +343,7 @@ class NaiveInterpreter
        fun string_instance(txt: String): Instance
        do
                var nat = native_string_instance(txt)
-               var res = self.send(self.force_get_primitive_method("to_s_with_length", nat.mtype), [nat, self.int_instance(txt.bytelen)])
+               var res = self.send(self.force_get_primitive_method("to_s_full", nat.mtype), [nat, self.int_instance(txt.bytelen), self.int_instance(txt.length)])
                assert res != null
                return res
        end
index 9ef5320..bcdb6db 100644 (file)
@@ -581,7 +581,7 @@ redef class AStringFormExpr
        do
                var native = v.analysis.mainmodule.native_string_type
                v.add_type(native)
-               var prop = v.get_method(native, "to_s_with_length")
+               var prop = v.get_method(native, "to_s_full")
                v.add_monomorphic_send(native, prop)
        end
 end