nitg: Modified compilation routine to avoid use of String contructors
authorLucas Bajolet <r4pass@hotmail.com>
Thu, 29 Aug 2013 20:03:44 +0000 (16:03 -0400)
committerLucas Bajolet <r4pass@hotmail.com>
Thu, 29 Aug 2013 21:23:35 +0000 (17:23 -0400)
Signed-off-by: Lucas Bajolet <r4pass@hotmail.com>

src/abstract_compiler.nit
src/naive_interpreter.nit
src/rapid_type_analysis.nit

index 53ccced..5a5597c 100644 (file)
@@ -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
index ba80cd9..7fdbf15 100644 (file)
@@ -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
index e779174..3c32689 100644 (file)
@@ -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