Class: Yadriggy::TypeChecker::FreeVarFinder
- Defined in:
- lib/yadriggy/typecheck.rb
Overview
A type environement that collects free variables. #bound_name? records the given symbol as a free variable name when it obtains the type of that symbol from its parent type environment.
Instance Attribute Summary collapse
-
#free_variables ⇒ Hash<Symbol,Type>
readonly
Obtains collected free variables.
Instance Method Summary collapse
- #bound_name?(name) ⇒ Boolean
-
#initialize(parent) ⇒ FreeVarFinder
constructor
A new instance of FreeVarFinder.
Methods inherited from TypeEnv
#bind_name, #context, #each, #new_base_tenv, #new_tenv
Constructor Details
#initialize(parent) ⇒ FreeVarFinder
Returns a new instance of FreeVarFinder.
110 111 112 113 |
# File 'lib/yadriggy/typecheck.rb', line 110 def initialize(parent) super @free_variables = {} end |
Instance Attribute Details
#free_variables ⇒ Hash<Symbol,Type> (readonly)
Obtains collected free variables.
108 109 110 |
# File 'lib/yadriggy/typecheck.rb', line 108 def free_variables @free_variables end |
Instance Method Details
#bound_name?(name) ⇒ Boolean
115 116 117 118 119 120 121 122 123 124 |
# File 'lib/yadriggy/typecheck.rb', line 115 def bound_name?(name) type = @names[name.to_sym] if type.nil? t = @parent&.bound_name?(name) @free_variables[name.to_sym] = t unless t.nil? t else type end end |