# Generate an array value
fun array_instance(array: Array[RuntimeVariable], elttype: MType): RuntimeVariable is abstract
src/compiler/abstract_compiler.nit:1845,2--1846,95
redef fun array_instance(array, elttype)
do
var nclass = mmodule.native_array_class
var arrayclass = mmodule.array_class
var arraytype = arrayclass.get_mtype([elttype])
var res = self.init_instance(arraytype)
self.add("\{ /* {res} = array_instance Array[{elttype}] */")
var length = self.int_instance(array.length)
var nat = native_array_instance(elttype, length)
for i in [0..array.length[ do
var r = self.autobox(array[i], self.object_type)
self.add("((struct instance_{nclass.c_name}*){nat})->values[{i}] = (val*) {r};")
end
self.send(self.get_property("with_native", arrayclass.intro.bound_mtype), [res, nat, length])
self.add("\}")
return res
end
src/compiler/separate_compiler.nit:2149,2--2165,4
redef fun array_instance(array, elttype)
do
elttype = self.anchor(elttype)
var arraytype = mmodule.array_type(elttype)
var res = self.init_instance(arraytype)
self.add("\{ /* {res} = array_instance Array[{elttype}] */")
var nat = self.new_var(mmodule.native_array_type(elttype))
nat.is_exact = true
self.add("{nat} = NEW_{nat.mtype.c_name}({array.length});")
for i in [0..array.length[ do
var r = self.autobox(array[i], elttype)
self.add("((struct {nat.mtype.c_name}*) {nat})->values[{i}] = {r};")
end
var length = self.int_instance(array.length)
self.send(self.get_property("with_native", arraytype), [res, nat, length])
self.add("\}")
return res
end
src/compiler/global_compiler.nit:993,2--1010,4