From d0334b1627ee1cc48443fb6e5f08310ae743d2b3 Mon Sep 17 00:00:00 2001 From: Lucas Bajolet Date: Thu, 27 Aug 2015 14:29:25 -0400 Subject: [PATCH] src: Added complete FlatString generation from compiler Signed-off-by: Lucas Bajolet --- lib/core/text/abstract_text.nit | 6 ++++++ lib/core/text/flat.nit | 4 ++++ src/compiler/abstract_compiler.nit | 5 +++-- src/interpreter/naive_interpreter.nit | 2 +- src/rapid_type_analysis.nit | 2 +- 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/core/text/abstract_text.nit b/lib/core/text/abstract_text.nit index 1faaad3..584a287 100644 --- a/lib/core/text/abstract_text.nit +++ b/lib/core/text/abstract_text.nit @@ -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] diff --git a/lib/core/text/flat.nit b/lib/core/text/flat.nit index bebc8e5..bf423ad 100644 --- a/lib/core/text/flat.nit +++ b/lib/core/text/flat.nit @@ -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 diff --git a/src/compiler/abstract_compiler.nit b/src/compiler/abstract_compiler.nit index b58d4a3..2f83449 100644 --- a/src/compiler/abstract_compiler.nit +++ b/src/compiler/abstract_compiler.nit @@ -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 diff --git a/src/interpreter/naive_interpreter.nit b/src/interpreter/naive_interpreter.nit index 1181cf0..23a7b0c 100644 --- a/src/interpreter/naive_interpreter.nit +++ b/src/interpreter/naive_interpreter.nit @@ -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 diff --git a/src/rapid_type_analysis.nit b/src/rapid_type_analysis.nit index 9ef5320..bcdb6db 100644 --- a/src/rapid_type_analysis.nit +++ b/src/rapid_type_analysis.nit @@ -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 -- 1.7.9.5