Class: Jade::Frontend::TypeChecking::Env
- Inherits:
-
Data
- Object
- Data
- Jade::Frontend::TypeChecking::Env
- Defined in:
- lib/jade/frontend/type_checking/env.rb
Instance Attribute Summary collapse
-
#bindings ⇒ Object
readonly
Returns the value of attribute bindings.
-
#definitions ⇒ Object
readonly
Returns the value of attribute definitions.
-
#entry_name ⇒ Object
readonly
Returns the value of attribute entry_name.
-
#node_types ⇒ Object
readonly
Returns the value of attribute node_types.
-
#substitution ⇒ Object
readonly
Returns the value of attribute substitution.
-
#var_gen ⇒ Object
readonly
Returns the value of attribute var_gen.
Class Method Summary collapse
Instance Method Summary collapse
- #bind(key, value) ⇒ Object
-
#canonicalize_node_types ⇒ Object
Post-finalize, apply the env’s substitution to every pinned type so stored types are canonical (no leftover Type::Var that the substitution would resolve).
- #composose_substitution(sub) ⇒ Object
- #define(key, value) ⇒ Object
- #free_vars ⇒ Object
- #fresh ⇒ Object
- #lookup(key) ⇒ Object
- #lookup_def(key) ⇒ Object
- #pin_type(node_id, type) ⇒ Object
Instance Attribute Details
#bindings ⇒ Object (readonly)
Returns the value of attribute bindings
8 9 10 |
# File 'lib/jade/frontend/type_checking/env.rb', line 8 def bindings @bindings end |
#definitions ⇒ Object (readonly)
Returns the value of attribute definitions
8 9 10 |
# File 'lib/jade/frontend/type_checking/env.rb', line 8 def definitions @definitions end |
#entry_name ⇒ Object (readonly)
Returns the value of attribute entry_name
8 9 10 |
# File 'lib/jade/frontend/type_checking/env.rb', line 8 def entry_name @entry_name end |
#node_types ⇒ Object (readonly)
Returns the value of attribute node_types
8 9 10 |
# File 'lib/jade/frontend/type_checking/env.rb', line 8 def node_types @node_types end |
#substitution ⇒ Object (readonly)
Returns the value of attribute substitution
8 9 10 |
# File 'lib/jade/frontend/type_checking/env.rb', line 8 def substitution @substitution end |
#var_gen ⇒ Object (readonly)
Returns the value of attribute var_gen
8 9 10 |
# File 'lib/jade/frontend/type_checking/env.rb', line 8 def var_gen @var_gen end |
Class Method Details
.empty(var_gen = VarGen.new) ⇒ Object
12 13 14 |
# File 'lib/jade/frontend/type_checking/env.rb', line 12 def self.empty(var_gen = VarGen.new) Env[nil, {}, Substitution::EMPTY, {}, var_gen, {}] end |
Instance Method Details
#bind(key, value) ⇒ Object
20 21 22 23 24 |
# File 'lib/jade/frontend/type_checking/env.rb', line 20 def bind(key, value) bindings .merge(key => value) .then { with(bindings: it) } end |
#canonicalize_node_types ⇒ Object
Post-finalize, apply the env’s substitution to every pinned type so stored types are canonical (no leftover Type::Var that the substitution would resolve).
33 34 35 36 37 |
# File 'lib/jade/frontend/type_checking/env.rb', line 33 def canonicalize_node_types node_types .transform_values { substitution.apply(it) } .then { with(node_types: it) } end |
#composose_substitution(sub) ⇒ Object
73 74 75 |
# File 'lib/jade/frontend/type_checking/env.rb', line 73 def composose_substitution(sub) with(substitution: substitution.compose(sub)) end |
#define(key, value) ⇒ Object
39 40 41 42 43 |
# File 'lib/jade/frontend/type_checking/env.rb', line 39 def define(key, value) definitions .merge(key => value) .then { with(definitions: it) } end |
#free_vars ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/jade/frontend/type_checking/env.rb', line 65 def free_vars bindings .values .flat_map(&:free_vars) .flat_map { substitution.apply(it).unbound_vars } .uniq(&:id) end |
#fresh ⇒ Object
16 17 18 |
# File 'lib/jade/frontend/type_checking/env.rb', line 16 def fresh var_gen.fresh end |
#lookup(key) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/jade/frontend/type_checking/env.rb', line 45 def lookup(key) binding = bindings[key] type, constraints = case bindings[key] in Scheme => scheme Instantiation.instantiate(scheme, var_gen) in Placeholder => placeholder Scheme[placeholder.free_vars, placeholder.type, placeholder.constraints] .then { Instantiation.instantiate(it, var_gen) } end Result.init(type, constraints) end |
#lookup_def(key) ⇒ Object
61 62 63 |
# File 'lib/jade/frontend/type_checking/env.rb', line 61 def lookup_def(key) definitions[key] end |
#pin_type(node_id, type) ⇒ Object
26 27 28 |
# File 'lib/jade/frontend/type_checking/env.rb', line 26 def pin_type(node_id, type) with(node_types: node_types.merge(node_id => type)) end |