Skip to content

Commit ca138b9

Browse files
committed
Hold native callsite info at an extra indirection.
This will help support inlining it into a P6opaque.
1 parent 20c10a9 commit ca138b9

File tree

4 files changed

+48
-36
lines changed

4 files changed

+48
-36
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
import org.perl6.nqp.sixmodel.reprs.CPointerInstance;
99
import org.perl6.nqp.sixmodel.reprs.NativeCallInstance;
10-
import org.perl6.nqp.sixmodel.reprs.NativeCallInstance.ArgType;
10+
import org.perl6.nqp.sixmodel.reprs.NativeCallBody;
11+
import org.perl6.nqp.sixmodel.reprs.NativeCallBody.ArgType;
1112

1213
public final class NativeCallOps {
1314
public static long init() {
@@ -17,7 +18,7 @@ public static long init() {
1718
}
1819

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

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

4849
public static SixModelObject call(SixModelObject returns, SixModelObject callObject, SixModelObject arguments, ThreadContext tc) {
49-
NativeCallInstance call = getNativeCallInstance(callObject);
50+
NativeCallBody call = getNativeCallBody(callObject);
5051

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

76-
private static NativeCallInstance getNativeCallInstance(SixModelObject target) {
77-
NativeCallInstance call;
77+
private static NativeCallBody getNativeCallBody(SixModelObject target) {
78+
NativeCallBody call;
7879
if (target instanceof NativeCallInstance) {
79-
call = (NativeCallInstance) target;
80+
call = ((NativeCallInstance)target).body;
8081
}
8182
else {
8283
/* TODO: Handle box target stuff here. */

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ public SixModelObject type_object_for(ThreadContext tc, SixModelObject HOW) {
2020
}
2121

2222
public SixModelObject allocate(ThreadContext tc, STable st) {
23-
SixModelObject obj = new NativeCallInstance();
23+
NativeCallInstance obj = new NativeCallInstance();
2424
obj.st = st;
25+
obj.body = new NativeCallBody();
2526
return obj;
2627
}
2728

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package org.perl6.nqp.sixmodel.reprs;
2+
3+
import com.sun.jna.Function;
4+
5+
/* Holds a description of a native call site. */
6+
public class NativeCallBody {
7+
/* Flag for whether we should free a string after passing it or not. These
8+
* are going away once the array handling is refactored.*/
9+
public static final byte ARG_NO_FREE_STR = 0;
10+
public static final byte ARG_FREE_STR = 1;
11+
public static final byte ARG_FREE_STR_MASK = 1;
12+
13+
/* The available native call argument types. */
14+
public enum ArgType {
15+
VOID,
16+
CHAR,
17+
SHORT,
18+
INT,
19+
LONG,
20+
LONGLONG,
21+
FLOAT,
22+
DOUBLE,
23+
ASCIISTR,
24+
UTF8STR,
25+
UTF16STR,
26+
CSTRUCT,
27+
CARRAY,
28+
CALLBACK,
29+
CPOINTER;
30+
}
31+
32+
public Function entry_point;
33+
public ArgType[] arg_types;
34+
public ArgType ret_type;
35+
}
Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,10 @@
11
package org.perl6.nqp.sixmodel.reprs;
22

3-
import com.sun.jna.Function;
4-
53
import org.perl6.nqp.sixmodel.SixModelObject;
64

75
public class NativeCallInstance extends SixModelObject {
8-
/* Flag for whether we should free a string after passing it or not. These
9-
* are going away once the array handling is refactored.*/
10-
public static final byte ARG_NO_FREE_STR = 0;
11-
public static final byte ARG_FREE_STR = 1;
12-
public static final byte ARG_FREE_STR_MASK = 1;
13-
14-
public Function entry_point;
15-
public ArgType[] arg_types;
16-
public ArgType ret_type;
17-
18-
public enum ArgType {
19-
VOID,
20-
CHAR,
21-
SHORT,
22-
INT,
23-
LONG,
24-
LONGLONG,
25-
FLOAT,
26-
DOUBLE,
27-
ASCIISTR,
28-
UTF8STR,
29-
UTF16STR,
30-
CSTRUCT,
31-
CARRAY,
32-
CALLBACK,
33-
CPOINTER;
34-
}
6+
/* Body held at a level of indirection to support inlining that into a
7+
* P6opaque; this is about the best we can do on the JVM, which doesn't
8+
* support interior pointers of complex value types. */
9+
public NativeCallBody body;
3510
}

0 commit comments

Comments
 (0)