Skip to content

Commit

Permalink
[Truffle] Implement the basics of Kernel#__callee__.
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Mar 10, 2015
1 parent 5223bf2 commit 5a506d2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
3 changes: 0 additions & 3 deletions spec/truffle/tags/core/kernel/__callee___tags.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
fails:Kernel.__callee__ returns the current method, even when aliased
fails:Kernel.__callee__ returns the aliased name when aliased method
fails:Kernel.__callee__ returns the caller from blocks too
fails:Kernel.__callee__ returns the caller from define_method too
fails:Kernel.__callee__ returns the caller from block inside define_method too
fails:Kernel.__callee__ returns the caller from a define_method called from the same class
fails:Kernel.__callee__ returns method name even from eval
fails:Kernel.__callee__ returns nil when not called from a method
fails:Kernel.__callee__ returns the caller when sent as a string
2 changes: 0 additions & 2 deletions spec/truffle/tags/core/kernel/__method___tags.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
fails:Kernel.__method__ returns the caller from define_method too
fails:Kernel.__method__ returns the caller from block inside define_method too
fails:Kernel.__method__ returns method name even from eval
fails:Kernel.__method__ returns nil from inside a class body
fails:Kernel.__method__ returns nil when not called from a method
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,25 @@ public boolean blockGiven() {
}
}

@CoreMethod(names = "__callee__", needsSelf = false)
public abstract static class CalleeNameNode extends CoreMethodNode {

public CalleeNameNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

public CalleeNameNode(CalleeNameNode prev) {
super(prev);
}

@Specialization
public RubySymbol calleeName(VirtualFrame frame) {
notDesignedForCompilation();
// the "called name" of a method.
return getContext().getSymbolTable().getSymbol(RubyCallStack.getCallingMethod(frame).getName());
}
}

@CoreMethod(names = "caller", isModuleFunction = true, optional = 1)
public abstract static class CallerNode extends CoreMethodNode {

Expand Down Expand Up @@ -1287,6 +1306,7 @@ public MethodNameNode(MethodNameNode prev) {
@Specialization
public RubySymbol methodName(VirtualFrame frame) {
notDesignedForCompilation();
// the "original/definition name" of the method.
return getContext().getSymbolTable().getSymbol(RubyCallStack.getCallingMethod(frame).getSharedMethodInfo().getName());
}

Expand Down

0 comments on commit 5a506d2

Please sign in to comment.