Class: R2CEnvironment
- Inherits:
-
RubyParserStuff::Environment
- Object
- RubyParserStuff::Environment
- R2CEnvironment
- Defined in:
- lib/r2cenvironment.rb
Constant Summary collapse
- TYPE =
0
- VALUE =
1
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
Instance Method Summary collapse
- #_get(name) ⇒ Object
- #add(id, type, depth = 0) ⇒ Object
- #depth ⇒ Object
-
#extend ⇒ Object
override.
- #get_val(name) ⇒ Object
- #lookup(name) ⇒ Object
- #old_extend ⇒ Object
- #scope ⇒ Object
- #set_val(name, val) ⇒ Object
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
8 9 10 |
# File 'lib/r2cenvironment.rb', line 8 def env @env end |
Instance Method Details
#_get(name) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/r2cenvironment.rb', line 52 def _get(name) @env.each do |closure| return closure[name] if closure.has_key? name end raise NameError, "Unbound var: #{name.inspect} in #{@env.inspect}" end |
#add(id, type, depth = 0) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/r2cenvironment.rb', line 10 def add(id, type, depth = 0) raise "Adding illegal identifier #{id.inspect}" unless Symbol === id raise ArgumentError, "type must be a valid Type instance: #{type.inspect}" unless CType === type @env[depth][id.to_s.sub(/^\*/, '').intern][TYPE] = type end |
#depth ⇒ Object
19 20 21 |
# File 'lib/r2cenvironment.rb', line 19 def depth @env.length end |
#extend ⇒ Object
override
24 25 26 |
# File 'lib/r2cenvironment.rb', line 24 def extend # override @env.unshift(Hash.new { |h,k| h[k] = [] }) end |
#get_val(name) ⇒ Object
28 29 30 |
# File 'lib/r2cenvironment.rb', line 28 def get_val(name) self._get(name)[VALUE] end |
#lookup(name) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/r2cenvironment.rb', line 32 def lookup(name) # HACK: if name is :self, cheat for now until we have full defn remapping return CType.fucked if name == :self return self._get(name)[TYPE] end |
#old_extend ⇒ Object
23 |
# File 'lib/r2cenvironment.rb', line 23 alias :old_extend :extend |
#scope ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/r2cenvironment.rb', line 43 def scope self.extend begin yield ensure self.unextend end end |
#set_val(name, val) ⇒ Object
39 40 41 |
# File 'lib/r2cenvironment.rb', line 39 def set_val(name, val) self._get(name)[VALUE] = val end |