fun native_array_def(pname: String, ret_type: nullable MType, arguments: Array[RuntimeVariable]) is abstract
+ # Return an element of a native array.
+ # The method is unsafe and is just a direct wrapper for the specific implementation of native arrays
+ fun native_array_get(native_array: RuntimeVariable, index: Int): RuntimeVariable is abstract
+
+ # Store an element in a native array.
+ # The method is unsafe and is just a direct wrapper for the specific implementation of native arrays
+ fun native_array_set(native_array: RuntimeVariable, index: Int, value: RuntimeVariable) is abstract
+
# Evaluate `args` as expressions in the call of `mpropdef` on `recv`.
# This method is used to manage varargs in signatures and returns the real array
# of runtime variables to use in the call.
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))
end
end
+ redef fun native_array_get(nat, i)
+ do
+ var nclass = mmodule.native_array_class
+ var recv = "((struct instance_{nclass.c_name}*){nat})->values"
+ # Because the objects are boxed, return the box to avoid unnecessary (or broken) unboxing/reboxing
+ var res = self.new_expr("{recv}[{i}]", compiler.mainmodule.object_type)
+ return res
+ end
+
+ redef fun native_array_set(nat, i, val)
+ do
+ var nclass = mmodule.native_array_class
+ var recv = "((struct instance_{nclass.c_name}*){nat})->values"
+ self.add("{recv}[{i}]={val};")
+ end
+
fun link_unresolved_type(mclassdef: MClassDef, mtype: MType) do
assert mtype.need_anchor
var compiler = self.compiler