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.
107 108 109 110 |
# File 'lib/yadriggy/typecheck.rb', line 107 def initialize(parent) super @free_variables = {} end |
Instance Attribute Details
#free_variables ⇒ Hash<Symbol,Type> (readonly)
Obtains collected free variables.
105 106 107 |
# File 'lib/yadriggy/typecheck.rb', line 105 def free_variables @free_variables end |
Instance Method Details
#bound_name?(name) ⇒ Boolean
112 113 114 115 116 117 118 119 120 121 |
# File 'lib/yadriggy/typecheck.rb', line 112 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 |