Skip to content

Commit 5a506d2

Browse files
committed
[Truffle] Implement the basics of Kernel#__callee__.
1 parent 5223bf2 commit 5a506d2

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
fails:Kernel.__callee__ returns the current method, even when aliased
22
fails:Kernel.__callee__ returns the aliased name when aliased method
33
fails:Kernel.__callee__ returns the caller from blocks too
4-
fails:Kernel.__callee__ returns the caller from define_method too
5-
fails:Kernel.__callee__ returns the caller from block inside define_method too
6-
fails:Kernel.__callee__ returns the caller from a define_method called from the same class
74
fails:Kernel.__callee__ returns method name even from eval
85
fails:Kernel.__callee__ returns nil when not called from a method
96
fails:Kernel.__callee__ returns the caller when sent as a string
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
fails:Kernel.__method__ returns the caller from define_method too
2-
fails:Kernel.__method__ returns the caller from block inside define_method too
31
fails:Kernel.__method__ returns method name even from eval
42
fails:Kernel.__method__ returns nil from inside a class body
53
fails:Kernel.__method__ returns nil when not called from a method

truffle/src/main/java/org/jruby/truffle/nodes/core/KernelNodes.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,25 @@ public boolean blockGiven() {
353353
}
354354
}
355355

356+
@CoreMethod(names = "__callee__", needsSelf = false)
357+
public abstract static class CalleeNameNode extends CoreMethodNode {
358+
359+
public CalleeNameNode(RubyContext context, SourceSection sourceSection) {
360+
super(context, sourceSection);
361+
}
362+
363+
public CalleeNameNode(CalleeNameNode prev) {
364+
super(prev);
365+
}
366+
367+
@Specialization
368+
public RubySymbol calleeName(VirtualFrame frame) {
369+
notDesignedForCompilation();
370+
// the "called name" of a method.
371+
return getContext().getSymbolTable().getSymbol(RubyCallStack.getCallingMethod(frame).getName());
372+
}
373+
}
374+
356375
@CoreMethod(names = "caller", isModuleFunction = true, optional = 1)
357376
public abstract static class CallerNode extends CoreMethodNode {
358377

@@ -1287,6 +1306,7 @@ public MethodNameNode(MethodNameNode prev) {
12871306
@Specialization
12881307
public RubySymbol methodName(VirtualFrame frame) {
12891308
notDesignedForCompilation();
1309+
// the "original/definition name" of the method.
12901310
return getContext().getSymbolTable().getSymbol(RubyCallStack.getCallingMethod(frame).getSharedMethodInfo().getName());
12911311
}
12921312

0 commit comments

Comments
 (0)