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
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
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