Skip to content

Commit

Permalink
Compile code for calling native functions.
Browse files Browse the repository at this point in the history
MVM_nativecall_build builds a JIT graph manually and compiles it. The
result is attached to the MVMNativeCallBody. For now the new nativeinvoke_*
ops (mirroring invoke_*) will enter that code. Ideally we will replace the
whole frame containing the nativeinvoke by JIT compiled code.

The nativeinvoke_o op just invokes the JITed code which will handle argument
fetching on its own so we can avoid the overhead of copying arguments into an
nqp::list.

We need to unblock GC on the current thread after we return from the
native function and before we box the return value. Otherwise if GC is
triggered by the boxing function, we will hang as GC is blocked.

You can now tell the JIT that the C function you want to call should take an
argument from WORK[cur_op + whatever] which is the equivalent of all those
GET_REG(cur_op, whatever) in interp.c.
Same for return values. When in interp.c you'd write GET_REG(cur_op, 0) = ...;
you tell the JIT: node->u.call.rv_mode = MVM_JIT_RV_DYNIDX;
box_rv_node->u.call.rv_idx = 0;
  • Loading branch information
niner committed Sep 19, 2017
1 parent eeb664e commit 2d21965
Show file tree
Hide file tree
Showing 19 changed files with 742 additions and 394 deletions.
4 changes: 3 additions & 1 deletion lib/MAST/Nodes.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -542,14 +542,16 @@ class MAST::Call is MAST::Node {
has @!flags;
has @!args;
has $!result;
has int $!op;

method new(:$target!, :@flags!, :$result = MAST::Node, *@args) {
method new(:$target!, :@flags!, :$result = MAST::Node, :$op = 0, *@args) {
sanity_check(@flags, @args);
my $obj := nqp::create(self);
nqp::bindattr($obj, MAST::Call, '$!target', $target);
nqp::bindattr($obj, MAST::Call, '@!flags', @flags);
nqp::bindattr($obj, MAST::Call, '@!args', @args);
nqp::bindattr($obj, MAST::Call, '$!result', $result);
nqp::bindattr_i($obj, MAST::Call, '$!op', $op);
$obj
}

Expand Down
Loading

0 comments on commit 2d21965

Please sign in to comment.