public static SixModelObject castNativeCall(ThreadContext tc, SixModelObject target_spec, SixModelObject target_type, Pointer o) {
if (o == null)
return target_type;
ArgType target = ArgType.INT;
SixModelObject nqpobj = target_type.st.REPR.allocate(tc, target_type.st);
StorageSpec ss = target_spec.st.REPR.get_storage_spec(tc, target_spec.st);
switch (ss.boxed_primitive) {
case StorageSpec.BP_INT:
switch (ss.bits) {
case 8:
nqpobj.set_int(tc, o.getByte(0));
break;
case 16:
nqpobj.set_int(tc, o.getShort(0));
break;
case 32:
nqpobj.set_int(tc, o.getInt(0));
break;
case 64:
nqpobj.set_int(tc, o.getLong(0));
break;
default:
throw ExceptionHandling.dieInternal(tc,
String.format("Cannot cast to %d bits integer", ss.bits));
}
break;
case StorageSpec.BP_NUM:
switch (ss.bits) {
case 32:
nqpobj.set_num(tc, o.getFloat(0));
break;
case 64:
nqpobj.set_num(tc, o.getDouble(0));
break;
default:
throw ExceptionHandling.dieInternal(tc,
String.format("Cannot cast to %d bits number", ss.bits));
}
break;
case StorageSpec.BP_STR:
/* TODO: Handle encodings. */
nqpobj.set_str(tc, o.getString(0));
break;
default:
if (target_type instanceof org.perl6.nqp.sixmodel.reprs.CStrInstance) {
/* TODO: Handle encodings. */
nqpobj.set_str(tc, o.getString(0));
}
else if (nqpobj instanceof org.perl6.nqp.sixmodel.reprs.CPointerInstance) {
CPointerInstance cpointer = (CPointerInstance) nqpobj;
cpointer.pointer = o;
}