Skip to content

Commit dbaecae

Browse files
committed
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.
1 parent a405133 commit dbaecae

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

src/vm/jvm/runtime/org/perl6/nqp/runtime/NativeCallOps.java

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,16 @@ private static Class<?> javaType(ThreadContext tc, ArgType target, SixModelObjec
297297
return NativeLong.class;
298298
case LONGLONG:
299299
return Long.class;
300+
case UCHAR:
301+
return Byte.class;
302+
case USHORT:
303+
return Short.class;
304+
case UINT:
305+
return Integer.class;
306+
case ULONG:
307+
return NativeLong.class;
308+
case ULONGLONG:
309+
return Long.class;
300310
case FLOAT:
301311
return Float.class;
302312
case DOUBLE:
@@ -331,6 +341,16 @@ public static Object toJNAType(ThreadContext tc, SixModelObject o, ArgType targe
331341
return new NativeLong((long) o.get_int(tc));
332342
case LONGLONG:
333343
return new Long((long) o.get_int(tc));
344+
case UCHAR:
345+
return new Byte((byte) o.get_int(tc));
346+
case USHORT:
347+
return new Short((short) o.get_int(tc));
348+
case UINT:
349+
return new Integer((int) o.get_int(tc));
350+
case ULONG:
351+
return new NativeLong((long) o.get_int(tc));
352+
case ULONGLONG:
353+
return new Long((long) o.get_int(tc));
334354
case FLOAT:
335355
return new Float((float) o.get_num(tc));
336356
case DOUBLE:
@@ -428,6 +448,44 @@ public static SixModelObject toNQPType(ThreadContext tc, ArgType target, SixMode
428448
nqpobj.set_int(tc, val);
429449
break;
430450
}
451+
case UCHAR: {
452+
nqpobj = type.st.REPR.allocate(tc, type.st);
453+
long val = ((Byte) o).byteValue();
454+
if (val < 0)
455+
val += 0x100;
456+
nqpobj.set_int(tc, val);
457+
break;
458+
}
459+
case USHORT: {
460+
nqpobj = type.st.REPR.allocate(tc, type.st);
461+
long val = ((Short) o).byteValue();
462+
if (val < 0)
463+
val += 0x10000;
464+
nqpobj.set_int(tc, val);
465+
break;
466+
}
467+
case UINT: {
468+
nqpobj = type.st.REPR.allocate(tc, type.st);
469+
long val = ((Integer) o).byteValue();
470+
if (val < 0)
471+
val += 0x100000000L;
472+
nqpobj.set_int(tc, val);
473+
break;
474+
}
475+
case ULONG: {
476+
/* TODO: handle unsignedness properly. */
477+
nqpobj = type.st.REPR.allocate(tc, type.st);
478+
long val = ((NativeLong) o).longValue();
479+
nqpobj.set_int(tc, val);
480+
break;
481+
}
482+
case ULONGLONG: {
483+
/* TODO: handle unsignedness properly. */
484+
nqpobj = type.st.REPR.allocate(tc, type.st);
485+
long val = ((Long) o).longValue();
486+
nqpobj.set_int(tc, val);
487+
break;
488+
}
431489
case FLOAT: {
432490
nqpobj = type.st.REPR.allocate(tc, type.st);
433491
float val = ((Float) o).floatValue();

src/vm/jvm/runtime/org/perl6/nqp/sixmodel/reprs/NativeCall.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@ public enum ArgType {
3232
CARRAY,
3333
CALLBACK,
3434
CPOINTER,
35-
VMARRAY;
35+
VMARRAY,
36+
UCHAR,
37+
USHORT,
38+
UINT,
39+
ULONG,
40+
ULONGLONG;
3641
}
3742

3843
public SixModelObject type_object_for(ThreadContext tc, SixModelObject HOW) {

0 commit comments

Comments
 (0)