do
# Collect all bas box class
# FIXME: this is not completely fine with a separate compilation scheme
- for classname in ["Int", "Bool", "Byte", "Char", "Float", "NativeString",
+ for classname in ["Int", "Bool", "Byte", "Char", "Float", "CString",
"Pointer", "Int8", "Int16", "UInt16", "Int32", "UInt32"] do
var classes = self.mainmodule.model.get_mclasses_by_name(classname)
if classes == null then continue
- assert classes.length == 1 else print classes.join(", ")
+ assert classes.length == 1 else print_error classes.join(", ")
self.box_kinds[classes.first] = self.box_kinds.length + 1
end
end
#if mclass.mclass_type.ctype == "val*" or mclass.mclass_type.is_subtype(self.mainmodule, mclass.mclass_type pointer_type) then
if mclass.mclass_type.ctype_extern == "val*" then
return 0
- else if mclass.kind == extern_kind and mclass.name != "NativeString" then
+ else if mclass.kind == extern_kind and mclass.name != "CString" then
return self.box_kinds[self.mainmodule.pointer_type.mclass]
else
return self.box_kinds[mclass]
for m in mainmodule.in_importation.greaters do for cd in m.mclassdefs do
var mclass = cd.mclass
- # Collect methods ad attributes
+ # Collect methods and attributes
for p in cd.intro_mproperties do
if p isa MMethod then
if rta == null then
v.add("return (val*){res};")
v.add("\}")
return
- else if mtype.mclass.kind == extern_kind and mtype.mclass.name != "NativeString" then
- # Is an extern class (other than Pointer and NativeString)
- # Pointer is caught in a previous `if`, and NativeString is internal
+ else if mtype.mclass.kind == extern_kind and mtype.mclass.name != "CString" then
+ # Is an extern class (other than Pointer and CString)
+ # Pointer is caught in a previous `if`, and CString is internal
var pointer_type = mainmodule.pointer_type
var alloc = v.nit_alloc("sizeof(struct instance) + {attrs.length}*sizeof(nitattribute_t)", mclass.full_name)
v.add("{res} = {alloc};")
end
+ if modelbuilder.toolcontext.opt_trace.value then
+ v.add("tracepoint(Nit_Compiler, Object_Instance,\"{mtype}\", (uintptr_t)self);")
+ v.add("GC_register_finalizer(self, object_destroy_callback, NULL, NULL, NULL);")
+ end
v.add("{res}->type = type;")
hardening_live_type(v, "type")
v.require_declaration("class_{c_name}")
return res
end
var valtype = value.mtype.as(MClassType)
- if mtype isa MClassType and mtype.mclass.kind == extern_kind and mtype.mclass.name != "NativeString" then
+ if mtype isa MClassType and mtype.mclass.kind == extern_kind and mtype.mclass.name != "CString" then
valtype = compiler.mainmodule.pointer_type
end
var res = self.new_var(mtype)
redef fun unbox_extern(value, mtype)
do
if mtype isa MClassType and mtype.mclass.kind == extern_kind and
- mtype.mclass.name != "NativeString" then
+ mtype.mclass.name != "CString" then
var pointer_type = compiler.mainmodule.pointer_type
var res = self.new_var_extern(mtype)
self.add "{res} = ((struct instance_{pointer_type.c_name}*){value})->value; /* unboxing {value.mtype} */"
redef fun box_extern(value, mtype)
do
if mtype isa MClassType and mtype.mclass.kind == extern_kind and
- mtype.mclass.name != "NativeString" then
+ mtype.mclass.name != "CString" then
var valtype = compiler.mainmodule.pointer_type
var res = self.new_var(mtype)
compiler.undead_types.add(mtype)
var res: nullable RuntimeVariable = null
var recv = arguments.first
var consider_null = not self.compiler.modelbuilder.toolcontext.opt_no_check_null.value or mmethod.name == "==" or mmethod.name == "!="
- if maybenull(recv) and consider_null then
+ if maybe_null(recv) and consider_null then
self.add("if ({recv} == NULL) \{")
if mmethod.name == "==" or mmethod.name == "is_same_instance" then
res = self.new_var(bool_type)
if not value.mtype.is_c_primitive then
self.add "{res} = {value} == NULL ? \"null\" : {type_info(value)}->name;"
else if value.mtype isa MClassType and value.mtype.as(MClassType).mclass.kind == extern_kind and
- value.mtype.as(MClassType).name != "NativeString" then
+ value.mtype.as(MClassType).name != "CString" then
self.add "{res} = \"{value.mtype.as(MClassType).mclass}\";"
else
self.require_declaration("type_{value.mtype.c_name}")
return k == interface_kind or t.is_c_primitive
end
- fun maybe_null(value: RuntimeVariable): Bool
- do
- var t = value.mcasttype
- return t isa MNullableType or t isa MNullType
- end
-
redef fun array_instance(array, elttype)
do
var nclass = mmodule.native_array_class
return res
end
- redef fun native_array_instance(elttype: MType, length: RuntimeVariable): RuntimeVariable
+ redef fun native_array_instance(elttype, length)
do
var mtype = mmodule.native_array_type(elttype)
self.require_declaration("NEW_{mtype.mclass.c_name}")
var recv = self.frame.arguments.first
var recv_type_info = self.type_info(recv)
self.require_declaration(mtype.const_color)
- return self.new_expr("NEW_{mtype.mclass.c_name}({length}, {recv_type_info}->resolution_table->types[{mtype.const_color}])", mtype)
+ return self.new_expr("NEW_{mtype.mclass.c_name}((int){length}, {recv_type_info}->resolution_table->types[{mtype.const_color}])", mtype)
end
compiler.undead_types.add(mtype)
self.require_declaration("type_{mtype.c_name}")
- return self.new_expr("NEW_{mtype.mclass.c_name}({length}, &type_{mtype.c_name})", mtype)
+ return self.new_expr("NEW_{mtype.mclass.c_name}((int){length}, &type_{mtype.c_name})", mtype)
end
redef fun native_array_def(pname, ret_type, arguments)