/IronPython_Main/External.LCA_RESTRICTED/Languages/Ruby/redist-libs/ruby/1.9.1/irb/frame.rb
Ruby | 66 lines | 44 code | 11 blank | 11 comment | 0 complexity | e16675e2447a362089d1b500378130e6 MD5 | raw file
Possible License(s): GPL-2.0, MPL-2.0-no-copyleft-exception, CPL-1.0, CC-BY-SA-3.0, BSD-3-Clause, ISC, AGPL-3.0, LGPL-2.1, Apache-2.0
- #
- # frame.rb -
- # $Release Version: 0.9$
- # $Revision: 25189 $
- # 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