X-Git-Url: http://nitlanguage.org diff --git a/src/global_compiler.nit b/src/global_compiler.nit index 9e79281..9a82243 100644 --- a/src/global_compiler.nit +++ b/src/global_compiler.nit @@ -77,6 +77,7 @@ redef class ModelBuilder end # The main function of the C + compiler.compile_nitni_global_ref_functions compiler.compile_main_function # Compile until all runtime_functions are visited @@ -243,6 +244,7 @@ class GlobalCompiler 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 @@ -269,7 +271,14 @@ class GlobalCompiler 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 @@ -348,7 +357,7 @@ class GlobalCompilerVisitor 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 @@ -392,7 +401,7 @@ class GlobalCompilerVisitor 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 */") @@ -471,7 +480,8 @@ class GlobalCompilerVisitor do check_valid_reciever(recvtype) #debug("call {m} on {recvtype} on {args.first}:{args.first.mtype}") - if m.mclassdef.mclass.name == "Object" and recvtype.ctype == "val*" then + if m.mproperty.is_toplevel then + # Do not customize top-level methods recvtype = m.mclassdef.bound_mtype end return recvtype @@ -667,7 +677,7 @@ class GlobalCompilerVisitor 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}")