From: Lucas Bajolet Date: Thu, 29 Aug 2013 20:03:44 +0000 (-0400) Subject: nitg: Modified compilation routine to avoid use of String contructors X-Git-Tag: v0.6.1~9^2~3 X-Git-Url: http://nitlanguage.org nitg: Modified compilation routine to avoid use of String contructors Signed-off-by: Lucas Bajolet --- diff --git a/src/abstract_compiler.nit b/src/abstract_compiler.nit index 53ccced..5a5597c 100644 --- a/src/abstract_compiler.nit +++ b/src/abstract_compiler.nit @@ -807,13 +807,11 @@ abstract class AbstractCompilerVisitor self.add("if ({name}) \{") self.add("{res} = {name};") self.add("\} else \{") - var nat = self.new_var(self.get_class("NativeString").mclass_type) + var native_mtype = self.get_class("NativeString").mclass_type + var nat = self.new_var(native_mtype) self.add("{nat} = \"{string.escape_to_c}\";") - var res2 = self.init_instance(mtype) - self.add("{res} = {res2};") var length = self.int_instance(string.length) - self.send(self.get_property("with_native", mtype), [res, nat, length]) - self.check_init_instance(res, mtype) + self.add("{res} = {self.monomorphic_send(self.get_property("to_s_with_length", native_mtype), native_mtype, [nat, length]).as(not null)};") self.add("{name} = {res};") self.add("\}") return res diff --git a/src/naive_interpreter.nit b/src/naive_interpreter.nit index ba80cd9..7fdbf15 100644 --- a/src/naive_interpreter.nit +++ b/src/naive_interpreter.nit @@ -1401,10 +1401,7 @@ redef class AStringFormExpr do var txt = self.value.as(not null) var nat = v.native_string_instance(txt) - var res = new MutableInstance(v.mainmodule.get_primitive_class("String").mclass_type) - v.init_instance(res) - v.send(v.force_get_primitive_method("from_cstring", res.mtype), [res, nat]) - v.check_init_instance(res) + var res = v.send(v.force_get_primitive_method("to_s", nat.mtype), [nat]).as(not null) return res end end diff --git a/src/rapid_type_analysis.nit b/src/rapid_type_analysis.nit index e779174..3c32689 100644 --- a/src/rapid_type_analysis.nit +++ b/src/rapid_type_analysis.nit @@ -426,12 +426,10 @@ end redef class AStringFormExpr redef fun accept_rapid_type_visitor(v) do - var mtype = self.mtype.as(MClassType) - v.add_type(mtype) var native = v.get_class("NativeString").mclass_type v.add_type(native) - var prop = v.get_method(mtype, "from_cstring") - v.add_monomorphic_send(mtype, prop) + var prop = v.get_method(native, "to_s") + v.add_monomorphic_send(native, prop) end end