Skip to content

Commit a85d07e

Browse files
committed
Deduplicate code to call a RubyMethod and renames
1 parent b1dbba7 commit a85d07e

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

src/main/java/org/truffleruby/core/method/MethodNodes.java

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,16 @@ public abstract static class CallNode extends AlwaysInlinedMethodNode {
135135
protected Object call(Frame callerFrame, RubyMethod method, Object[] rubyArgs, RootCallTarget target,
136136
@Cached CallInternalMethodNode callInternalMethodNode) {
137137
final InternalMethod internalMethod = method.method;
138-
final Object[] newArgs = RubyArguments.repack(rubyArgs, method.receiver);
138+
final Object receiver = method.receiver;
139+
return callBoundMethod(callerFrame, internalMethod, receiver, rubyArgs, callInternalMethodNode);
140+
}
141+
142+
static Object callBoundMethod(Frame frame, InternalMethod internalMethod, Object receiver,
143+
Object[] callerRubyArgs, CallInternalMethodNode callInternalMethodNode) {
144+
final Object[] newArgs = RubyArguments.repack(callerRubyArgs, receiver);
139145
RubyArguments.setMethod(newArgs, internalMethod);
140146
assert RubyArguments.assertFrameArguments(newArgs);
141-
return callInternalMethodNode.execute(callerFrame, internalMethod, method.receiver, newArgs, null);
147+
return callInternalMethodNode.execute(frame, internalMethod, receiver, newArgs, null);
142148
}
143149
}
144150

@@ -327,13 +333,13 @@ protected RootCallTarget methodCallTarget(InternalMethod method) {
327333
final SourceSection sourceSection = method.getSharedMethodInfo().getSourceSection();
328334
final RubyRootNode methodRootNode = RubyRootNode.of(method.getCallTarget());
329335

330-
final SetReceiverNode setReceiverNode = new SetReceiverNode(method);
336+
var callWithRubyMethodReceiverNode = new CallWithRubyMethodReceiverNode(method);
331337
final RubyLambdaRootNode wrapRootNode = new RubyLambdaRootNode(
332338
getLanguage(),
333339
sourceSection,
334340
methodRootNode.getFrameDescriptor(),
335341
method.getSharedMethodInfo(),
336-
setReceiverNode,
342+
callWithRubyMethodReceiverNode,
337343
methodRootNode.getSplit(),
338344
methodRootNode.returnID,
339345
BreakID.INVALID,
@@ -345,22 +351,19 @@ protected int getCacheLimit() {
345351
return getLanguage().options.METHOD_TO_PROC_CACHE;
346352
}
347353

348-
}
349-
350-
private static class SetReceiverNode extends RubyContextSourceNode {
351-
private final InternalMethod method;
352-
@Child private CallInternalMethodNode callInternalMethodNode = CallInternalMethodNode.create();
354+
private static class CallWithRubyMethodReceiverNode extends RubyContextSourceNode {
355+
private final InternalMethod method;
356+
@Child private CallInternalMethodNode callInternalMethodNode = CallInternalMethodNode.create();
353357

354-
public SetReceiverNode(InternalMethod method) {
355-
this.method = method;
356-
}
358+
public CallWithRubyMethodReceiverNode(InternalMethod method) {
359+
this.method = method;
360+
}
357361

358-
@Override
359-
public Object execute(VirtualFrame frame) {
360-
final Object originalBoundMethodReceiver = RubyArguments.getSelf(RubyArguments.getDeclarationFrame(frame));
361-
Object[] rubyArgs = RubyArguments.repack(frame.getArguments(), originalBoundMethodReceiver);
362-
RubyArguments.setMethod(rubyArgs, method);
363-
return callInternalMethodNode.execute(frame, method, originalBoundMethodReceiver, rubyArgs, null);
362+
@Override
363+
public Object execute(VirtualFrame frame) {
364+
final Object receiver = RubyArguments.getSelf(RubyArguments.getDeclarationFrame(frame));
365+
return CallNode.callBoundMethod(frame, method, receiver, frame.getArguments(), callInternalMethodNode);
366+
}
364367
}
365368
}
366369

0 commit comments

Comments
 (0)