end
# The main function of the C
+ compiler.compile_nitni_global_ref_functions
compiler.compile_main_function
# Compile until all runtime_functions are visited
# Compile class names (for the class_name and output_class_name methods)
protected fun compile_class_names do
var v = new_visitor
- self.header.add_decl("extern const char const * class_names[];")
- v.add("const char const * class_names[] = \{")
+ self.header.add_decl("extern const char *class_names[];")
+ v.add("const char *class_names[] = \{")
for t in self.runtime_type_analysis.live_types do
v.add("\"{t}\", /* {self.classid(t)} */")
end
v.add("{res}->classid = {self.classid(mtype)};")
self.generate_init_attr(v, res, mtype)
+ v.set_finalizer res
v.add("return {res};")
v.add("\}")
end
redef fun compile_nitni_structs
do
- self.header.add_decl("struct nitni_instance \{ val *value; \};")
+ self.header.add_decl """
+struct nitni_instance \{
+ struct nitni_instance *next,
+ *prev; /* adjacent global references in global list */
+ int count; /* number of time this global reference has been marked */
+ val *value;
+\};"""
+ super
end
end
return
else if pname == "copy_to" then
var recv1 = "((struct {arguments[1].mcasttype.c_name}*){arguments[1]})->values"
- self.add("memcpy({recv1},{recv},{arguments[2]}*sizeof({elttype.ctype}));")
+ self.add("memmove({recv1},{recv},{arguments[2]}*sizeof({elttype.ctype}));")
return
end
end
+ redef fun native_array_instance(elttype: MType, length: RuntimeVariable): RuntimeVariable
+ do
+ var ret_type = self.get_class("NativeArray").get_mtype([elttype])
+ return self.new_expr("NEW_{ret_type.c_name}({length})", ret_type)
+ end
+
redef fun calloc_array(ret_type, arguments)
do
self.ret(self.new_expr("NEW_{ret_type.c_name}({arguments[1]})", ret_type))
if res != null then self.assign(res, res2.as(not null))
return res
end
- var consider_null = not self.compiler.modelbuilder.toolcontext.opt_no_check_other.value or m.name == "==" or m.name == "!="
+ var consider_null = not self.compiler.modelbuilder.toolcontext.opt_no_check_null.value or m.name == "==" or m.name == "!="
if args.first.mcasttype isa MNullableType or args.first.mcasttype isa MNullType and consider_null then
# The reciever is potentially null, so we have to 3 cases: ==, != or NullPointerException
self.add("if ({args.first} == NULL) \{ /* Special null case */")
var ta = a.intro.static_mtype.as(not null)
ta = self.resolve_for(ta, recv2)
var res2 = self.new_expr("((struct {t.c_name}*){recv})->{a.intro.c_name}", ta)
- if not ta isa MNullableType and not self.compiler.modelbuilder.toolcontext.opt_no_check_other.value then
+ if not ta isa MNullableType and not self.compiler.modelbuilder.toolcontext.opt_no_check_attr_isset.value then
if ta.ctype == "val*" then
self.add("if ({res2} == NULL) \{")
self.add_abort("Uninitialized attribute {a.name}")