PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 0ms 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
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
  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. require "e2mmap"
  12. module IRB
  13. class Frame
  14. extend Exception2MessageMapper
  15. def_exception :FrameOverflow, "frame overflow"
  16. def_exception :FrameUnderflow, "frame underflow"
  17. INIT_STACK_TIMES = 3
  18. CALL_STACK_OFFSET = 3
  19. def initialize
  20. @frames = [TOPLEVEL_BINDING] * INIT_STACK_TIMES
  21. end
  22. def trace_func(event, file, line, id, binding)
  23. case event
  24. when 'call', 'class'
  25. @frames.push binding
  26. when 'return', 'end'
  27. @frames.pop
  28. end
  29. end
  30. def top(n = 0)
  31. bind = @frames[-(n + CALL_STACK_OFFSET)]
  32. Fail FrameUnderflow unless bind
  33. bind
  34. end
  35. def bottom(n = 0)
  36. bind = @frames[n]
  37. Fail FrameOverflow unless bind
  38. bind
  39. end
  40. # singleton functions
  41. def Frame.bottom(n = 0)
  42. @backtrace.bottom(n)
  43. end
  44. def Frame.top(n = 0)
  45. @backtrace.top(n)
  46. end
  47. def Frame.sender
  48. eval "self", @backtrace.top
  49. end
  50. @backtrace = Frame.new
  51. set_trace_func proc{|event, file, line, id, binding, klass|
  52. @backtrace.trace_func(event, file, line, id, binding)
  53. }
  54. end
  55. end