Class: Apricot::OverloadScope
- Includes:
- StorageScope
- Defined in:
- lib/apricot/scopes.rb
Instance Attribute Summary collapse
-
#block_arg ⇒ Object
Returns the value of attribute block_arg.
-
#splat ⇒ Object
(also: #splat?)
Returns the value of attribute splat.
Attributes inherited from Scope
#loop_label, #parent, #variables
Instance Method Summary collapse
-
#find_recur_target ⇒ Object
A (recur) is looking for a recursion target.
-
#find_var(name, depth = 0) ⇒ Object
An identifier or a nested scope is looking up a variable.
-
#initialize(parent_fn) ⇒ OverloadScope
constructor
A new instance of OverloadScope.
-
#new_local(name) ⇒ Object
Create a new local on the current level.
Methods included from StorageScope
#local_count, #local_names, #next_slot, #store_new_local, #variable_names
Constructor Details
#initialize(parent_fn) ⇒ OverloadScope
Returns a new instance of OverloadScope.
97 98 99 |
# File 'lib/apricot/scopes.rb', line 97 def initialize(parent_fn) super(parent_fn) end |
Instance Attribute Details
#block_arg ⇒ Object
Returns the value of attribute block_arg.
95 96 97 |
# File 'lib/apricot/scopes.rb', line 95 def block_arg @block_arg end |
#splat ⇒ Object Also known as: splat?
Returns the value of attribute splat.
92 93 94 |
# File 'lib/apricot/scopes.rb', line 92 def splat @splat end |
Instance Method Details
#find_recur_target ⇒ Object
A (recur) is looking for a recursion target. This, being a fn overload, is one.
122 123 124 |
# File 'lib/apricot/scopes.rb', line 122 def find_recur_target self end |
#find_var(name, depth = 0) ⇒ Object
An identifier or a nested scope is looking up a variable. If the variable is found here, return a reference to it. Otherwise look it up on the parent (a fn). Don’t increase the depth, the lookup on the fn will do that, and if we do it twice then the generated push_local_depth instructions look up too many scopes.
106 107 108 109 110 111 112 |
# File 'lib/apricot/scopes.rb', line 106 def find_var(name, depth = 0) if slot = @variables[name] LocalReference.new(slot, depth) else @parent.find_var(name, depth) end end |
#new_local(name) ⇒ Object
Create a new local on the current level.
115 116 117 118 |
# File 'lib/apricot/scopes.rb', line 115 def new_local(name) name = name.name if name.is_a? Identifier @variables[name] = store_new_local(name) end |