Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Hold native callsite info at an extra indirection.
This will help support inlining it into a P6opaque.
  • Loading branch information
jnthn committed Oct 12, 2013
1 parent 20c10a9 commit ca138b9
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 36 deletions.
13 changes: 7 additions & 6 deletions src/vm/jvm/runtime/org/perl6/nqp/runtime/NativeCallOps.java
Expand Up @@ -7,7 +7,8 @@

import org.perl6.nqp.sixmodel.reprs.CPointerInstance;
import org.perl6.nqp.sixmodel.reprs.NativeCallInstance;
import org.perl6.nqp.sixmodel.reprs.NativeCallInstance.ArgType;
import org.perl6.nqp.sixmodel.reprs.NativeCallBody;
import org.perl6.nqp.sixmodel.reprs.NativeCallBody.ArgType;

public final class NativeCallOps {
public static long init() {
Expand All @@ -17,7 +18,7 @@ public static long init() {
}

public static long build(SixModelObject target, String libname, String symbol, String convention, SixModelObject arguments, SixModelObject returns, ThreadContext tc) {
NativeCallInstance call = getNativeCallInstance(target);
NativeCallBody call = getNativeCallBody(target);

try {
/* Load the library and locate the symbol. */
Expand Down Expand Up @@ -46,7 +47,7 @@ public static long build(SixModelObject target, String libname, String symbol, S
}

public static SixModelObject call(SixModelObject returns, SixModelObject callObject, SixModelObject arguments, ThreadContext tc) {
NativeCallInstance call = getNativeCallInstance(callObject);
NativeCallBody call = getNativeCallBody(callObject);

try {
/* Convert arguments into array of appropriate objects. */
Expand All @@ -73,10 +74,10 @@ public static long refresh(SixModelObject obj) {
return 1L;
}

private static NativeCallInstance getNativeCallInstance(SixModelObject target) {
NativeCallInstance call;
private static NativeCallBody getNativeCallBody(SixModelObject target) {
NativeCallBody call;
if (target instanceof NativeCallInstance) {
call = (NativeCallInstance) target;
call = ((NativeCallInstance)target).body;
}
else {
/* TODO: Handle box target stuff here. */
Expand Down
Expand Up @@ -20,8 +20,9 @@ public SixModelObject type_object_for(ThreadContext tc, SixModelObject HOW) {
}

public SixModelObject allocate(ThreadContext tc, STable st) {
SixModelObject obj = new NativeCallInstance();
NativeCallInstance obj = new NativeCallInstance();
obj.st = st;
obj.body = new NativeCallBody();
return obj;
}

Expand Down
@@ -0,0 +1,35 @@
package org.perl6.nqp.sixmodel.reprs;

import com.sun.jna.Function;

/* Holds a description of a native call site. */
public class NativeCallBody {
/* Flag for whether we should free a string after passing it or not. These
* are going away once the array handling is refactored.*/
public static final byte ARG_NO_FREE_STR = 0;
public static final byte ARG_FREE_STR = 1;
public static final byte ARG_FREE_STR_MASK = 1;

/* The available native call argument types. */
public enum ArgType {
VOID,
CHAR,
SHORT,
INT,
LONG,
LONGLONG,
FLOAT,
DOUBLE,
ASCIISTR,
UTF8STR,
UTF16STR,
CSTRUCT,
CARRAY,
CALLBACK,
CPOINTER;
}

public Function entry_point;
public ArgType[] arg_types;
public ArgType ret_type;
}
@@ -1,35 +1,10 @@
package org.perl6.nqp.sixmodel.reprs;

import com.sun.jna.Function;

import org.perl6.nqp.sixmodel.SixModelObject;

public class NativeCallInstance extends SixModelObject {
/* Flag for whether we should free a string after passing it or not. These
* are going away once the array handling is refactored.*/
public static final byte ARG_NO_FREE_STR = 0;
public static final byte ARG_FREE_STR = 1;
public static final byte ARG_FREE_STR_MASK = 1;

public Function entry_point;
public ArgType[] arg_types;
public ArgType ret_type;

public enum ArgType {
VOID,
CHAR,
SHORT,
INT,
LONG,
LONGLONG,
FLOAT,
DOUBLE,
ASCIISTR,
UTF8STR,
UTF16STR,
CSTRUCT,
CARRAY,
CALLBACK,
CPOINTER;
}
/* Body held at a level of indirection to support inlining that into a
* P6opaque; this is about the best we can do on the JVM, which doesn't
* support interior pointers of complex value types. */
public NativeCallBody body;
}

0 comments on commit ca138b9

Please sign in to comment.