Skip to content

Commit 16c4f9c

Browse files
committed
[Truffle] Kernel#caller in terms of #caller_locations
1 parent 80decc9 commit 16c4f9c

File tree

3 files changed

+11
-36
lines changed

3 files changed

+11
-36
lines changed

spec/truffle/tags/core/kernel/caller_tags.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

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

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -297,40 +297,6 @@ public RubySymbol calleeName(VirtualFrame frame) {
297297
}
298298
}
299299

300-
@CoreMethod(names = "caller", isModuleFunction = true, optional = 1)
301-
public abstract static class CallerNode extends CoreMethodArrayArgumentsNode {
302-
303-
public CallerNode(RubyContext context, SourceSection sourceSection) {
304-
super(context, sourceSection);
305-
}
306-
307-
@Specialization
308-
public Object caller(UndefinedPlaceholder omit) {
309-
return caller(1);
310-
}
311-
312-
@Specialization
313-
public Object caller(int omit) {
314-
notDesignedForCompilation();
315-
316-
omit += 1; // Always ignore this node
317-
318-
Backtrace backtrace = RubyCallStack.getBacktrace(this);
319-
List<Activation> activations = backtrace.getActivations();
320-
int size = activations.size() - omit;
321-
322-
if (size < 0) {
323-
return nil();
324-
}
325-
326-
Object[] callers = new Object[size];
327-
for (int n = 0; n < size; n++) {
328-
callers[n] = getContext().makeString(MRIBacktraceFormatter.formatCallerLine(activations, n + omit));
329-
}
330-
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), callers, callers.length);
331-
}
332-
}
333-
334300
@CoreMethod(names = "caller_locations", isModuleFunction = true, optional = 2)
335301
public abstract static class CallerLocationsNode extends CoreMethodArrayArgumentsNode {
336302

truffle/src/main/ruby/core/kernel.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,19 @@ def printf(*args)
1313
end
1414
module_function :printf
1515

16-
1716
alias_method :trust, :untaint
1817
alias_method :untrust, :taint
1918
alias_method :untrusted?, :tainted?
2019

20+
def caller(start = 1, limit = nil)
21+
start += 1
22+
if limit.nil?
23+
args = [start]
24+
else
25+
args = [start, limit]
26+
end
27+
caller_locations(*args).map(&:inspect)
28+
end
29+
module_function :caller
30+
2131
end

0 commit comments

Comments
 (0)