X-Git-Url: http://nitlanguage.org diff --git a/src/compiler/global_compiler.nit b/src/compiler/global_compiler.nit index 9a89064..49671f9 100644 --- a/src/compiler/global_compiler.nit +++ b/src/compiler/global_compiler.nit @@ -247,7 +247,7 @@ class GlobalCompiler res.is_exact = true if is_native_array then var mtype_elt = mtype.arguments.first - v.add("{res} = nit_alloc(sizeof(struct {mtype.c_name}) + length*sizeof({mtype_elt.ctype}));") + v.add("{res} = nit_alloc(sizeof(struct {mtype.c_name}) + length*sizeof(val*));") v.add("((struct {mtype.c_name}*){res})->length = length;") else v.add("{res} = nit_alloc(sizeof(struct {mtype.c_name}));") @@ -404,9 +404,23 @@ class GlobalCompilerVisitor do var ret_type = mmodule.native_array_type(elttype) ret_type = anchor(ret_type).as(MClassType) + length = autobox(length, compiler.mainmodule.int_type) return self.new_expr("NEW_{ret_type.c_name}({length})", ret_type) end + redef fun native_array_get(nat, i) + do + var recv = "((struct {nat.mcasttype.c_name}*){nat})->values" + var ret_type = nat.mcasttype.as(MClassType).arguments.first + return self.new_expr("{recv}[{i}]", ret_type) + end + + redef fun native_array_set(nat, i, val) + do + var recv = "((struct {nat.mcasttype.c_name}*){nat})->values" + self.add("{recv}[{i}]={val};") + end + redef fun calloc_array(ret_type, arguments) do self.ret(self.new_expr("NEW_{ret_type.c_name}({arguments[1]})", ret_type)) @@ -515,11 +529,6 @@ class GlobalCompilerVisitor private fun get_recvtype(m: MMethodDef, recvtype: MClassType, args: Array[RuntimeVariable]): MClassType do check_valid_reciever(recvtype) - #debug("call {m} on {recvtype} on {args.first}:{args.first.mtype}") - if m.mproperty.is_toplevel then - # Do not customize top-level methods - recvtype = m.mclassdef.bound_mtype - end return recvtype end