Skip to content

Commit 0e2ce95

Browse files
committed
First implementation of nqp::buildnativecall.
1 parent 7e305ec commit 0e2ce95

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package org.perl6.nqp.runtime;
22

3+
import com.sun.jna.NativeLibrary;
4+
35
import org.perl6.nqp.sixmodel.SixModelObject;
46

7+
import org.perl6.nqp.sixmodel.reprs.NativeCallInstance;
8+
59
public final class NativeCallOps {
610
public static long init() {
711
/* Nothing to do here. The REPRs are all registered over in
@@ -10,10 +14,33 @@ public static long init() {
1014
}
1115

1216
public static long build(SixModelObject target, String libname, String symbol, String convention, SixModelObject arguments, SixModelObject returns) {
17+
NativeCallInstance call = getNativeCallInstance(target);
18+
19+
/* Load the library and locate the symbol. */
20+
/* TODO: Error handling! */
21+
NativeLibrary library = NativeLibrary.getInstance(libname);
22+
call.entry_point = library.getFunction(symbol);
23+
24+
/* TODO: Set the calling convention. */
25+
26+
/* Set up the argument types. */
27+
1328
return 1L;
1429
}
1530

1631
public static SixModelObject call(SixModelObject returns, SixModelObject call, SixModelObject arguments) {
1732
return null;
1833
}
34+
35+
private static NativeCallInstance getNativeCallInstance(SixModelObject target) {
36+
NativeCallInstance call;
37+
if (target instanceof NativeCallInstance) {
38+
call = (NativeCallInstance) target;
39+
}
40+
else {
41+
/* TODO: Handle box target stuff here. */
42+
call = null;
43+
}
44+
return call;
45+
}
1946
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.perl6.nqp.sixmodel.reprs;
22

3+
import com.sun.jna.Function;
4+
35
import org.perl6.nqp.sixmodel.SixModelObject;
46

57
public class NativeCallInstance extends SixModelObject {
@@ -26,4 +28,6 @@ public class NativeCallInstance extends SixModelObject {
2628
public static final byte ARG_NO_FREE_STR = 0;
2729
public static final byte ARG_FREE_STR = 1;
2830
public static final byte ARG_FREE_STR_MASK = 1;
31+
32+
public Function entry_point;
2933
}

0 commit comments

Comments
 (0)