Skip to content

Commit 918cdb3

Browse files
committed
Introduce setdispatcherfor op on JVM backend.
So that Rakudo can start using it. Should mean we also get the same set of bug fixes that use of the new op provides for MoarVM also.
1 parent 5f40147 commit 918cdb3

File tree

3 files changed

+31
-17
lines changed

3 files changed

+31
-17
lines changed

src/vm/jvm/QAST/Compiler.nqp

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2706,20 +2706,8 @@ QAST::OperationsJAST.map_classlib_core_op('freshcoderef', $TYPE_OPS, 'freshcoder
27062706
QAST::OperationsJAST.map_classlib_core_op('markcodestatic', $TYPE_OPS, 'markcodestatic', [$RT_OBJ], $RT_OBJ, :tc);
27072707
QAST::OperationsJAST.map_classlib_core_op('markcodestub', $TYPE_OPS, 'markcodestub', [$RT_OBJ], $RT_OBJ, :tc);
27082708
QAST::OperationsJAST.map_classlib_core_op('getstaticcode', $TYPE_OPS, 'getstaticcode', [$RT_OBJ], $RT_OBJ, :tc);
2709-
QAST::OperationsJAST.add_core_op('setdispatcher', -> $qastcomp, $op {
2710-
if +@($op) != 1 {
2711-
nqp::die('setdispatcher requires one operand');
2712-
}
2713-
my $il := JAST::InstructionList.new();
2714-
my $dispres := $qastcomp.as_jast($op[0], :want($RT_OBJ));
2715-
$il.append($dispres.jast);
2716-
$*STACK.obtain($il, $dispres);
2717-
$il.append($DUP);
2718-
$il.append($ALOAD_1);
2719-
$il.append($SWAP);
2720-
$il.append(JAST::Instruction.new( :op('putfield'), $TYPE_TC, 'currentDispatcher', $TYPE_SMO ));
2721-
result($il, $RT_OBJ);
2722-
});
2709+
QAST::OperationsJAST.map_classlib_core_op('setdispatcher', $TYPE_OPS, 'setdispatcher', [$RT_OBJ], $RT_OBJ, :tc);
2710+
QAST::OperationsJAST.map_classlib_core_op('setdispatcherfor', $TYPE_OPS, 'setdispatcherfor', [$RT_OBJ, $RT_OBJ], $RT_OBJ, :tc);
27232711
QAST::OperationsJAST.add_core_op('takedispatcher', -> $qastcomp, $op {
27242712
if +@($op) != 1 || !nqp::istype($op[0], QAST::SVal) {
27252713
nqp::die('takedispatcher requires one string literal operand');

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

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5167,10 +5167,34 @@ public static SixModelObject getstaticcode(SixModelObject code, ThreadContext tc
51675167
else
51685168
throw ExceptionHandling.dieInternal(tc, "getstaticcode can only be used with a CodeRef");
51695169
}
5170+
public static SixModelObject setdispatcher(SixModelObject disp, ThreadContext tc) {
5171+
tc.currentDispatcher = disp;
5172+
return disp;
5173+
}
5174+
public static SixModelObject setdispatcherfor(SixModelObject disp, SixModelObject dispFor, ThreadContext tc) {
5175+
tc.currentDispatcher = disp;
5176+
if (dispFor instanceof CodeRef) {
5177+
tc.currentDispatcherFor = dispFor;
5178+
}
5179+
else {
5180+
InvocationSpec is = dispFor.st.InvocationSpec;
5181+
if (is == null)
5182+
throw ExceptionHandling.dieInternal(tc, "setdispatcherfor needs invokable target");
5183+
if (is.ClassHandle != null)
5184+
tc.currentDispatcherFor = (CodeRef)dispFor.get_attribute_boxed(tc,
5185+
is.ClassHandle, is.AttrName, is.Hint);
5186+
else
5187+
throw ExceptionHandling.dieInternal(tc, "setdispatcherfor needs simple invokable target");
5188+
}
5189+
return disp;
5190+
}
51705191
public static void takedispatcher(int lexIdx, ThreadContext tc) {
51715192
if (tc.currentDispatcher != null) {
5172-
tc.curFrame.oLex[lexIdx] = tc.currentDispatcher;
5173-
tc.currentDispatcher = null;
5193+
if (tc.currentDispatcherFor == null ||
5194+
tc.currentDispatcherFor == tc.curFrame.codeRef) {
5195+
tc.curFrame.oLex[lexIdx] = tc.currentDispatcher;
5196+
tc.currentDispatcher = null;
5197+
}
51745198
}
51755199
}
51765200

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,11 @@ public class ThreadContext {
7979
public CallCaptureInstance savedCC;
8080

8181
/**
82-
* The currently set dispatcher, for the next interested call to take.
82+
* The currently set dispatcher, for the next interested call (or the
83+
* one matching currentDispatcherFor, if set) to take.
8384
*/
8485
public SixModelObject currentDispatcher;
86+
public SixModelObject currentDispatcherFor;
8587

8688
/**
8789
* Serialization context write barrier disabled depth (anything non-zero

0 commit comments

Comments
 (0)