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