X-Git-Url: http://nitlanguage.org diff --git a/src/compiler/separate_compiler.nit b/src/compiler/separate_compiler.nit index f6c483c..8587f4a 100644 --- a/src/compiler/separate_compiler.nit +++ b/src/compiler/separate_compiler.nit @@ -256,7 +256,7 @@ class SeparateCompiler "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 @@ -877,7 +877,8 @@ class SeparateCompiler self.provide_declaration("BOX_{c_name}", "val* BOX_{c_name}({mtype.ctype_extern});") v.add_decl("/* allocate {mtype} */") v.add_decl("val* BOX_{mtype.c_name}({mtype.ctype_extern} value) \{") - v.add("struct instance_{c_name}*res = nit_alloc(sizeof(struct instance_{c_name}));") + var alloc = v.nit_alloc("sizeof(struct instance_{c_name})", mclass.full_name) + v.add("struct instance_{c_name}*res = {alloc};") v.compiler.undead_types.add(mtype) v.require_declaration("type_{c_name}") v.add("res->type = &type_{c_name};") @@ -899,7 +900,8 @@ class SeparateCompiler else var res = v.new_named_var(mtype, "self") res.is_exact = true - v.add("{res} = nit_alloc(sizeof(struct instance_{mtype.c_name}));") + alloc = v.nit_alloc("sizeof(struct instance_{mtype.c_name})", mclass.full_name) + v.add("{res} = {alloc};") v.add("{res}->type = type;") hardening_live_type(v, "type") v.require_declaration("class_{c_name}") @@ -926,7 +928,8 @@ class SeparateCompiler var res = v.get_name("self") v.add_decl("struct instance_{c_name} *{res};") var mtype_elt = mtype.arguments.first - v.add("{res} = nit_alloc(sizeof(struct instance_{c_name}) + length*sizeof({mtype_elt.ctype}));") + var alloc = v.nit_alloc("sizeof(struct instance_{c_name}) + length*sizeof({mtype_elt.ctype})", mclass.full_name) + v.add("{res} = {alloc};") v.add("{res}->type = type;") hardening_live_type(v, "type") v.require_declaration("class_{c_name}") @@ -949,7 +952,8 @@ class SeparateCompiler else var res = v.new_named_var(mtype, "self") res.is_exact = true - v.add("{res} = nit_alloc(sizeof(struct instance_{pointer_type.c_name}));") + var alloc = v.nit_alloc("sizeof(struct instance_{pointer_type.c_name})", mclass.full_name) + v.add("{res} = {alloc};") v.add("{res}->type = type;") hardening_live_type(v, "type") v.require_declaration("class_{c_name}") @@ -972,9 +976,11 @@ class SeparateCompiler res.is_exact = true var attrs = self.attr_tables.get_or_null(mclass) if attrs == null then - v.add("{res} = nit_alloc(sizeof(struct instance));") + var alloc = v.nit_alloc("sizeof(struct instance)", mclass.full_name) + v.add("{res} = {alloc};") else - v.add("{res} = nit_alloc(sizeof(struct instance) + {attrs.length}*sizeof(nitattribute_t));") + var alloc = v.nit_alloc("sizeof(struct instance) + {attrs.length}*sizeof(nitattribute_t)", mclass.full_name) + v.add("{res} = {alloc};") end v.add("{res}->type = type;") hardening_live_type(v, "type") @@ -1053,7 +1059,7 @@ class SeparateCompiler v.add_abort("type null") v.add("\}") v.add("if({t}->table_size < 0) \{") - v.add("PRINT_ERROR(\"Insantiation of a dead type: %s\\n\", {t}->name);") + v.add("PRINT_ERROR(\"Instantiation of a dead type: %s\\n\", {t}->name);") v.add_abort("type dead") v.add("\}") end @@ -1174,8 +1180,9 @@ class SeparateCompilerVisitor args.first = self.autobox(args.first, m.mclassdef.mclass.mclass_type) end for i in [0..msignature.arity[ do - var t = msignature.mparameters[i].mtype - if i == msignature.vararg_rank then + var mp = msignature.mparameters[i] + var t = mp.mtype + if mp.is_vararg then t = args[i+1].mtype end args[i+1] = self.autobox(args[i+1], t) @@ -1189,8 +1196,9 @@ class SeparateCompilerVisitor args.first = self.unbox_extern(args.first, m.mclassdef.mclass.mclass_type) end for i in [0..msignature.arity[ do - var t = msignature.mparameters[i].mtype - if i == msignature.vararg_rank then + var mp = msignature.mparameters[i] + var t = mp.mtype + if mp.is_vararg then t = args[i+1].mtype end if m.is_extern then args[i+1] = self.unbox_extern(args[i+1], t) @@ -1397,8 +1405,7 @@ class SeparateCompilerVisitor 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 == "!=" - var maybenull = (recv.mcasttype isa MNullableType or recv.mcasttype isa MNullType) and consider_null - if maybenull then + if maybenull(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) @@ -2108,18 +2115,24 @@ class SeparateCompilerVisitor var res = self.new_expr("{recv}[{arguments[1]}]", compiler.mainmodule.object_type) res.mcasttype = ret_type.as(not null) self.ret(res) - return + return true else if pname == "[]=" then self.add("{recv}[{arguments[1]}]={arguments[2]};") - return + return true else if pname == "length" then self.ret(self.new_expr("((struct instance_{nclass.c_name}*){arguments[0]})->length", ret_type.as(not null))) - return + return true else if pname == "copy_to" then var recv1 = "((struct instance_{nclass.c_name}*){arguments[1]})->values" self.add("memmove({recv1}, {recv}, {arguments[2]}*sizeof({elttype.ctype}));") - return + return true + else if pname == "memmove" then + # fun memmove(start: Int, length: Int, dest: NativeArray[E], dest_start: Int) is intern do + var recv1 = "((struct instance_{nclass.c_name}*){arguments[3]})->values" + self.add("memmove({recv1}+{arguments[4]}, {recv}+{arguments[1]}, {arguments[2]}*sizeof({elttype.ctype}));") + return true end + return false end redef fun native_array_get(nat, i) @@ -2246,8 +2259,9 @@ class SeparateRuntimeFunction var sig = new FlatBuffer sig.append("({called_recv.ctype} self") for i in [0..called_signature.arity[ do - var mtype = called_signature.mparameters[i].mtype - if i == called_signature.vararg_rank then + var mp = called_signature.mparameters[i] + var mtype = mp.mtype + if mp.is_vararg then mtype = mmethoddef.mclassdef.mmodule.array_type(mtype) end sig.append(", {mtype.ctype} p{i}") @@ -2282,8 +2296,9 @@ class SeparateRuntimeFunction comment.append("({selfvar}: {selfvar.mtype}") arguments.add(selfvar) for i in [0..msignature.arity[ do - var mtype = msignature.mparameters[i].mtype - if i == msignature.vararg_rank then + var mp = msignature.mparameters[i] + var mtype = mp.mtype + if mp.is_vararg then mtype = v.mmodule.array_type(mtype) end comment.append(", {mtype}")