Class: BusScheme::StackFrame
Instance Attribute Summary collapse
-
#called_as ⇒ Object
readonly
Returns the value of attribute called_as.
-
#called_from ⇒ Object
readonly
Returns the value of attribute called_from.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#line ⇒ Object
readonly
Returns the value of attribute line.
Instance Method Summary collapse
- #[](symbol) ⇒ Object
- #[]=(symbol, value) ⇒ Object
-
#filtered? ⇒ Boolean
special forms should not be shown in stack traces neither should ‘begin’.
-
#has_key?(symbol) ⇒ Boolean
Just your regular hash stuff, only it takes the parent into account.
- #immediate_has_key? ⇒ Object
- #immediate_lookup ⇒ Object
- #immediate_set ⇒ Object
-
#initialize(locals, parent, called_as) ⇒ StackFrame
constructor
takes a hash and a parent.
- #trace ⇒ Object
Methods included from Callable
Constructor Details
#initialize(locals, parent, called_as) ⇒ StackFrame
takes a hash and a parent
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/stack_frame.rb', line 6 def initialize(locals, parent, called_as) @parent, @called_as = [parent, called_as] @file = @called_as.respond_to?(:file) ? @called_as.file : '(eval)' @line = @called_as.respond_to?(:line) ? @called_as.line : 0 @called_as = '(anonymous)' if called_as.is_a?(Cons) or called_as.is_a?(Array) @called_from = if BusScheme.stack.empty? or !BusScheme.stack.last.respond_to? :called_as '(top-level)' else BusScheme.stack.last.called_as end locals.each { |k, v| immediate_set k, v } end |
Instance Attribute Details
#called_as ⇒ Object (readonly)
Returns the value of attribute called_as.
3 4 5 |
# File 'lib/stack_frame.rb', line 3 def called_as @called_as end |
#called_from ⇒ Object (readonly)
Returns the value of attribute called_from.
3 4 5 |
# File 'lib/stack_frame.rb', line 3 def called_from @called_from end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
3 4 5 |
# File 'lib/stack_frame.rb', line 3 def file @file end |
#line ⇒ Object (readonly)
Returns the value of attribute line.
3 4 5 |
# File 'lib/stack_frame.rb', line 3 def line @line end |
Instance Method Details
#[](symbol) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/stack_frame.rb', line 30 def [](symbol) if immediate_has_key?(symbol) immediate_lookup(symbol) else @parent && @parent[symbol] end end |
#[]=(symbol, value) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/stack_frame.rb', line 38 def []=(symbol, value) if !immediate_has_key?(symbol) and @parent && @parent.has_key?(symbol) @parent[symbol] = value else immediate_set symbol, value end end |
#filtered? ⇒ Boolean
special forms should not be shown in stack traces neither should ‘begin’
52 53 54 55 |
# File 'lib/stack_frame.rb', line 52 def filtered? return false unless @called_as @called_as.special_form or @called_as == :begin.sym end |
#has_key?(symbol) ⇒ Boolean
Just your regular hash stuff, only it takes the parent into account
26 27 28 |
# File 'lib/stack_frame.rb', line 26 def has_key?(symbol) immediate_has_key?(symbol) or @parent && @parent.has_key?(symbol) end |
#immediate_has_key? ⇒ Object
21 |
# File 'lib/stack_frame.rb', line 21 alias_method :immediate_has_key?, :has_key? |
#immediate_lookup ⇒ Object
23 |
# File 'lib/stack_frame.rb', line 23 alias_method :immediate_lookup, :[] |
#immediate_set ⇒ Object
22 |
# File 'lib/stack_frame.rb', line 22 alias_method :immediate_set, :[]= |
#trace ⇒ Object
46 47 48 |
# File 'lib/stack_frame.rb', line 46 def trace "#{@file}:#{@line} in #{@called_from}" unless filtered? end |