if self.classids.has_key(mtype) then
return self.classids[mtype]
end
- print "No classid for {mtype}"
+ print_error "No classid for {mtype}"
abort
end
redef fun unbox_extern(value, mtype)
do
if mtype isa MClassType and mtype.mclass.kind == extern_kind and
- mtype.mclass.name != "NativeString" then
+ mtype.mclass.name != "CString" then
var res = self.new_var_extern(mtype)
self.add "{res} = ((struct {mtype.c_name}*){value})->value; /* unboxing {value.mtype} */"
return res
redef fun box_extern(value, mtype)
do
if not mtype isa MClassType or mtype.mclass.kind != extern_kind or
- mtype.mclass.name == "NativeString" then return value
+ mtype.mclass.name == "CString" then return value
var valtype = value.mtype.as(MClassType)
var res = self.new_var(mtype)
var recv1 = "((struct {arguments[1].mcasttype.c_name}*){arguments[1]})->values"
self.add("memmove({recv1},{recv},{arguments[2]}*sizeof({elttype.ctype}));")
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 {arguments[3].mcasttype.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_instance(elttype: MType, length: RuntimeVariable): RuntimeVariable
+ redef fun native_array_instance(elttype, length)
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)
+ return self.new_expr("NEW_{ret_type.c_name}((int){length})", ret_type)
end
redef fun native_array_get(nat, i)
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
-
redef fun send(m, args)
do
var types = self.collect_types(args.first)
if args.first.mtype.is_c_primitive then
var mclasstype = args.first.mtype.as(MClassType)
if not self.compiler.runtime_type_analysis.live_types.has(mclasstype) then
+ self.add("/* skip, dead class {mclasstype} */")
+ return res
+ end
+ if not mclasstype.has_mproperty(self.compiler.mainmodule, m) then
self.add("/* skip, no method {m} */")
return res
end
fun check_valid_reciever(recvtype: MClassType)
do
if self.compiler.runtime_type_analysis.live_types.has(recvtype) or recvtype.mclass.name == "Object" then return
- print "{recvtype} is not a live type"
+ print_error "{recvtype} is not a live type"
abort
end