Class: JSE::Env
- Inherits:
-
Object
- Object
- JSE::Env
- Defined in:
- lib/jse/env.rb
Instance Attribute Summary collapse
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Instance Method Summary collapse
- #clear_meta ⇒ Object
- #eval(node) ⇒ Object
- #exists?(name) ⇒ Boolean
- #get_meta ⇒ Object
-
#initialize(parent: nil) ⇒ Env
constructor
A new instance of Env.
- #load(mod) ⇒ Object
- #register(name, value) ⇒ Object
- #resolve(name) ⇒ Object
- #set(name, value) ⇒ Object
- #set_meta(dict) ⇒ Object
Constructor Details
#initialize(parent: nil) ⇒ Env
Returns a new instance of Env.
3 4 5 6 7 |
# File 'lib/jse/env.rb', line 3 def initialize(parent: nil) @parent = parent @bindings = {} @current_meta = {} end |
Instance Attribute Details
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
9 10 11 |
# File 'lib/jse/env.rb', line 9 def parent @parent end |
Instance Method Details
#clear_meta ⇒ Object
56 57 58 |
# File 'lib/jse/env.rb', line 56 def @current_meta = {} end |
#eval(node) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/jse/env.rb', line 40 def eval(node) if node.respond_to?(:apply) node.apply(self) else node end end |
#exists?(name) ⇒ Boolean
30 31 32 33 34 |
# File 'lib/jse/env.rb', line 30 def exists?(name) return true if @bindings.key?(name) return @parent.exists?(name) if @parent false end |
#get_meta ⇒ Object
52 53 54 |
# File 'lib/jse/env.rb', line 52 def @current_meta end |
#load(mod) ⇒ Object
36 37 38 |
# File 'lib/jse/env.rb', line 36 def load(mod) mod.each { |name, functor| register(name, functor) } end |
#register(name, value) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/jse/env.rb', line 19 def register(name, value) if @bindings.key?(name) raise "Symbol '#{name}' already exists in current scope" end @bindings[name] = value end |
#resolve(name) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/jse/env.rb', line 11 def resolve(name) if @bindings.key?(name) @bindings[name] elsif @parent @parent.resolve(name) end end |
#set(name, value) ⇒ Object
26 27 28 |
# File 'lib/jse/env.rb', line 26 def set(name, value) @bindings[name] = value end |
#set_meta(dict) ⇒ Object
48 49 50 |
# File 'lib/jse/env.rb', line 48 def (dict) @current_meta = dict end |