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}));")
var res = self.new_var(mtype)
if not compiler.runtime_type_analysis.live_types.has(valtype) then
self.add("/*no autobox from {value.mtype} to {mtype}: {value.mtype} is not live! */")
- self.add("PRINT_ERROR(\"Dead code executed!\\n\"); show_backtrace(1);")
+ self.add("PRINT_ERROR(\"Dead code executed!\\n\"); fatal_exit(1);")
return res
end
self.add("{res} = BOX_{valtype.c_name}({value}); /* autobox from {value.mtype} to {mtype} */")
# Bad things will appen!
var res = self.new_var(mtype)
self.add("/* {res} left unintialized (cannot convert {value.mtype} to {mtype}) */")
- self.add("PRINT_ERROR(\"Cast error: Cannot cast %s to %s.\\n\", \"{value.mtype}\", \"{mtype}\"); show_backtrace(1);")
+ self.add("PRINT_ERROR(\"Cast error: Cannot cast %s to %s.\\n\", \"{value.mtype}\", \"{mtype}\"); fatal_exit(1);")
return res
end
end
var res = self.new_var(mtype)
if not compiler.runtime_type_analysis.live_types.has(value.mtype.as(MClassType)) then
self.add("/*no boxing of {value.mtype}: {value.mtype} is not live! */")
- self.add("PRINT_ERROR(\"Dead code executed!\\n\"); show_backtrace(1);")
+ self.add("PRINT_ERROR(\"Dead code executed!\\n\"); fatal_exit(1);")
return res
end
self.add("{res} = BOX_{valtype.c_name}({value}); /* boxing {value.mtype} */")
redef fun native_array_instance(elttype: MType, length: RuntimeVariable): RuntimeVariable
do
- var ret_type = self.get_class("NativeArray").get_mtype([elttype])
+ 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))
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
do
if recv.mtype.is_c_primitive then return
self.add("PRINT_ERROR(\"BTD BUG: Dynamic type is %s, static type is %s\\n\", class_names[{recv}->classid], \"{recv.mcasttype}\");")
- self.add("show_backtrace(1);")
+ self.add("fatal_exit(1);")
end
redef fun isset_attribute(a, recv)
redef fun array_instance(array, elttype)
do
elttype = self.anchor(elttype)
- var arraytype = self.get_class("Array").get_mtype([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(self.get_class("NativeArray").get_mtype([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
for i in [0..mmethoddef.msignature.arity[ do
var mtype = mmethoddef.msignature.mparameters[i].mtype
if i == mmethoddef.msignature.vararg_rank then
- mtype = v.get_class("Array").get_mtype([mtype])
+ mtype = v.mmodule.array_type(mtype)
end
mtype = v.resolve_for(mtype, selfvar)
comment.append(", {mtype}")