Class: Apricot::LetScope

Inherits:
Scope show all
Defined in:
lib/apricot/scopes.rb

Overview

The let scope doesn’t have real storage for locals. It stores its locals on the nearest enclosing real scope, which is any separate block of code such as a fn, defn, defmacro or the top level of the program.

Instance Attribute Summary

Attributes inherited from Scope

#loop_label, #parent, #variables

Instance Method Summary collapse

Methods inherited from Scope

#initialize

Constructor Details

This class inherits a constructor from Apricot::Scope

Instance Method Details

#find_recur_targetObject

A (recur) is looking for a recursion target. This is one only if it is a (loop) form.



155
156
157
# File 'lib/apricot/scopes.rb', line 155

def find_recur_target
  loop_label ? self : @parent.find_recur_target
end

#find_var(name, depth = 0) ⇒ Object

An identifier or a nested scope is looking up a variable.



132
133
134
135
136
137
138
# File 'lib/apricot/scopes.rb', line 132

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, with storage on the nearest enclosing real scope.



142
143
144
145
# File 'lib/apricot/scopes.rb', line 142

def new_local(name)
  name = name.name if name.is_a? Identifier
  @variables[name] = @parent.store_new_local(name)
end

#store_new_local(name) ⇒ Object

A deeper let is asking for a new local slot. Pass it along to the parent so it eventually reaches a real scope.



149
150
151
# File 'lib/apricot/scopes.rb', line 149

def store_new_local(name)
  @parent.store_new_local(name)
end