Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Basic unsigned int native call support on JVM.
Java and the JVM don't really do unsinged, so it's a bit hacky, but it
is at least enough to pass the tests added to Rakudo for unsinged int
args and returns.
  • Loading branch information
jnthn committed Apr 4, 2015
1 parent a405133 commit dbaecae
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
58 changes: 58 additions & 0 deletions src/vm/jvm/runtime/org/perl6/nqp/runtime/NativeCallOps.java
Expand Up @@ -297,6 +297,16 @@ private static Class<?> javaType(ThreadContext tc, ArgType target, SixModelObjec
return NativeLong.class;
case LONGLONG:
return Long.class;
case UCHAR:
return Byte.class;
case USHORT:
return Short.class;
case UINT:
return Integer.class;
case ULONG:
return NativeLong.class;
case ULONGLONG:
return Long.class;
case FLOAT:
return Float.class;
case DOUBLE:
Expand Down Expand Up @@ -331,6 +341,16 @@ public static Object toJNAType(ThreadContext tc, SixModelObject o, ArgType targe
return new NativeLong((long) o.get_int(tc));
case LONGLONG:
return new Long((long) o.get_int(tc));
case UCHAR:
return new Byte((byte) o.get_int(tc));
case USHORT:
return new Short((short) o.get_int(tc));
case UINT:
return new Integer((int) o.get_int(tc));
case ULONG:
return new NativeLong((long) o.get_int(tc));
case ULONGLONG:
return new Long((long) o.get_int(tc));
case FLOAT:
return new Float((float) o.get_num(tc));
case DOUBLE:
Expand Down Expand Up @@ -428,6 +448,44 @@ public static SixModelObject toNQPType(ThreadContext tc, ArgType target, SixMode
nqpobj.set_int(tc, val);
break;
}
case UCHAR: {
nqpobj = type.st.REPR.allocate(tc, type.st);
long val = ((Byte) o).byteValue();
if (val < 0)
val += 0x100;
nqpobj.set_int(tc, val);
break;
}
case USHORT: {
nqpobj = type.st.REPR.allocate(tc, type.st);
long val = ((Short) o).byteValue();
if (val < 0)
val += 0x10000;
nqpobj.set_int(tc, val);
break;
}
case UINT: {
nqpobj = type.st.REPR.allocate(tc, type.st);
long val = ((Integer) o).byteValue();
if (val < 0)
val += 0x100000000L;
nqpobj.set_int(tc, val);
break;
}
case ULONG: {
/* TODO: handle unsignedness properly. */
nqpobj = type.st.REPR.allocate(tc, type.st);
long val = ((NativeLong) o).longValue();
nqpobj.set_int(tc, val);
break;
}
case ULONGLONG: {
/* TODO: handle unsignedness properly. */
nqpobj = type.st.REPR.allocate(tc, type.st);
long val = ((Long) o).longValue();
nqpobj.set_int(tc, val);
break;
}
case FLOAT: {
nqpobj = type.st.REPR.allocate(tc, type.st);
float val = ((Float) o).floatValue();
Expand Down
Expand Up @@ -32,7 +32,12 @@ public enum ArgType {
CARRAY,
CALLBACK,
CPOINTER,
VMARRAY;
VMARRAY,
UCHAR,
USHORT,
UINT,
ULONG,
ULONGLONG;
}

public SixModelObject type_object_for(ThreadContext tc, SixModelObject HOW) {
Expand Down

0 comments on commit dbaecae

Please sign in to comment.