diff options
author | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-25 15:02:05 +0000 |
---|---|---|
committer | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-25 15:02:05 +0000 |
commit | 0dc342de848a642ecce8db697b8fecd83a63e117 (patch) | |
tree | 2b7ed4724aff1f86073e4740134bda9c4aac1a39 /trunk/lib/irb/frame.rb | |
parent | ef70cf7138ab8034b5b806f466e4b484b24f0f88 (diff) |
added tag v1_9_0_4
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/tags/v1_9_0_4@18845 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'trunk/lib/irb/frame.rb')
-rw-r--r-- | trunk/lib/irb/frame.rb | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/trunk/lib/irb/frame.rb b/trunk/lib/irb/frame.rb new file mode 100644 index 0000000000..8a5d0696fb --- /dev/null +++ b/trunk/lib/irb/frame.rb @@ -0,0 +1,66 @@ +# +# frame.rb - +# $Release Version: 0.9$ +# $Revision$ +# by Keiju ISHITSUKA(Nihon Rational Software Co.,Ltd) +# +# -- +# +# +# + +require "e2mmap" + +module IRB + class Frame + extend Exception2MessageMapper + def_exception :FrameOverflow, "frame overflow" + def_exception :FrameUnderflow, "frame underflow" + + INIT_STACK_TIMES = 3 + CALL_STACK_OFFSET = 3 + + def initialize + @frames = [TOPLEVEL_BINDING] * INIT_STACK_TIMES + end + + def trace_func(event, file, line, id, binding) + case event + when 'call', 'class' + @frames.push binding + when 'return', 'end' + @frames.pop + end + end + + def top(n = 0) + bind = @frames[-(n + CALL_STACK_OFFSET)] + Fail FrameUnderflow unless bind + bind + end + + def bottom(n = 0) + bind = @frames[n] + Fail FrameOverflow unless bind + bind + end + + # singleton functions + def Frame.bottom(n = 0) + @backtrace.bottom(n) + end + + def Frame.top(n = 0) + @backtrace.top(n) + end + + def Frame.sender + eval "self", @backtrace.top + end + + @backtrace = Frame.new + set_trace_func proc{|event, file, line, id, binding, klass| + @backtrace.trace_func(event, file, line, id, binding) + } + end +end |