PageRenderTime 14ms CodeModel.GetById 7ms app.highlight 5ms RepoModel.GetById 2ms app.codeStats 0ms

/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
 1#
 2#   frame.rb -
 3#   	$Release Version: 0.9$
 4#   	$Revision: 25189 $
 5#   	by Keiju ISHITSUKA(Nihon Rational Software Co.,Ltd)
 6#
 7# --
 8#
 9#
10#
11
12require "e2mmap"
13
14module IRB
15  class Frame
16    extend Exception2MessageMapper
17    def_exception :FrameOverflow, "frame overflow"
18    def_exception :FrameUnderflow, "frame underflow"
19
20    INIT_STACK_TIMES = 3
21    CALL_STACK_OFFSET = 3
22
23    def initialize
24      @frames = [TOPLEVEL_BINDING] * INIT_STACK_TIMES
25    end
26
27    def trace_func(event, file, line, id, binding)
28      case event
29      when 'call', 'class'
30	@frames.push binding
31      when 'return', 'end'
32	@frames.pop
33      end
34    end
35
36    def top(n = 0)
37      bind = @frames[-(n + CALL_STACK_OFFSET)]
38      Fail FrameUnderflow unless bind
39      bind
40    end
41
42    def bottom(n = 0)
43      bind = @frames[n]
44      Fail FrameOverflow unless bind
45      bind
46    end
47
48    # singleton functions
49    def Frame.bottom(n = 0)
50      @backtrace.bottom(n)
51    end
52
53    def Frame.top(n = 0)
54      @backtrace.top(n)
55    end
56
57    def Frame.sender
58      eval "self", @backtrace.top
59    end
60
61    @backtrace = Frame.new
62    set_trace_func proc{|event, file, line, id, binding, klass|
63      @backtrace.trace_func(event, file, line, id, binding)
64    }
65  end
66end