Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Implement remaining cases of CArray.

All that's remaining for JVM NativeCall now is nqp::nativecallrefresh.
  • Loading branch information...
commit 8181f81c06e49a9fa8eb526bade2d9a8dbeb42b0 1 parent baf1a11
@arnsholt arnsholt authored
View
10 src/vm/jvm/runtime/org/perl6/nqp/sixmodel/reprs/CArray.java
@@ -91,9 +91,17 @@ else if (data.elem_type.st.REPR instanceof CPointer) {
data.jna_size = Native.POINTER_SIZE;
data.elem_kind = ElemKind.CPOINTER;
}
+ else if (data.elem_type.st.REPR instanceof CArray) {
+ data.jna_size = Native.POINTER_SIZE;
+ data.elem_kind = ElemKind.CARRAY;
+ }
+ else if (data.elem_type.st.REPR instanceof CStruct) {
+ data.jna_size = Native.POINTER_SIZE;
+ data.elem_kind = ElemKind.CSTRUCT;
+ }
else {
/* TODO: Remaining cases. */
- ExceptionHandling.dieInternal(tc, "CArray only handles ints and nums so far.");
+ ExceptionHandling.dieInternal(tc, "CArray only handles ints, nums, strings, CArrays, CPointers and CStructs so far.");
}
st.REPRData = data;
View
16 src/vm/jvm/runtime/org/perl6/nqp/sixmodel/reprs/CArrayInstance.java
@@ -5,6 +5,7 @@
import com.sun.jna.Memory;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
+import com.sun.jna.Structure;
import org.perl6.nqp.runtime.ExceptionHandling;
import org.perl6.nqp.runtime.NativeCallOps;
@@ -130,6 +131,7 @@ else if (repr_data.elem_size == 64) {
public void bind_pos_boxed(ThreadContext tc, long index, SixModelObject value) {
CArrayREPRData repr_data = (CArrayREPRData) st.REPRData;
int intidx = (int) index;
+ value = Ops.decont(value, tc);
/* TODO: Die if this is a NUMERIC/INTEGER CArray. */
if (index >= allocated)
@@ -143,6 +145,15 @@ public void bind_pos_boxed(ThreadContext tc, long index, SixModelObject value) {
ptr = new Memory(bytes.length);
ptr.write(0, bytes, 0, bytes.length);
break;
+ case CARRAY:
+ ptr = ((CArrayInstance) value).storage;
+ break;
+ case CSTRUCT:
+ ptr = ((CStructInstance) value).storage.getPointer();
+ break;
+ case CPOINTER:
+ ptr = ((CPointerInstance) value).pointer;
+ break;
default:
ExceptionHandling.dieInternal(tc, "CArray.bind_pos_boxed reached its default case. This should never happen.");
}
@@ -192,8 +203,11 @@ private SixModelObject makeObject(ThreadContext tc, Pointer ptr) {
return NativeCallOps.toNQPType(tc, ArgType.CARRAY, repr_data.elem_type, ptr);
case CPOINTER:
return NativeCallOps.toNQPType(tc, ArgType.CPOINTER, repr_data.elem_type, ptr);
+ case CSTRUCT:
+ Class<?> structClass = ((CStructREPRData) repr_data.elem_type.st.REPRData).structureClass;
+ return NativeCallOps.toNQPType(tc, ArgType.CSTRUCT, repr_data.elem_type, Structure.newInstance(structClass, ptr));
default:
- ExceptionHandling.dieInternal(tc, "CArray can only makeObject strings, arrays and pointers");
+ ExceptionHandling.dieInternal(tc, "CArray can only makeObject strings, arrays, structs and pointers");
}
/* And a dummy return statement to placate Java's flow analysis. */
Please sign in to comment.
Something went wrong with that request. Please try again.