Class: Jade::Frontend::TypeChecking::State
- Inherits:
-
Data
- Object
- Data
- Jade::Frontend::TypeChecking::State
- Defined in:
- lib/jade/frontend/type_checking/state.rb
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#skip_constraints ⇒ Object
readonly
Returns the value of attribute skip_constraints.
Class Method Summary collapse
Instance Method Summary collapse
- #add_errors(more_errors) ⇒ Object
- #bind(key, value) ⇒ Object
- #fresh ⇒ Object
- #to_result ⇒ Object
- #unify(left, right, rigid_vars = [], &block) ⇒ Object
- #unify_result(result, right, rigid_vars = [], &block) ⇒ Object
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env
4 5 6 |
# File 'lib/jade/frontend/type_checking/state.rb', line 4 def env @env end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors
4 5 6 |
# File 'lib/jade/frontend/type_checking/state.rb', line 4 def errors @errors end |
#skip_constraints ⇒ Object (readonly)
Returns the value of attribute skip_constraints
4 5 6 |
# File 'lib/jade/frontend/type_checking/state.rb', line 4 def skip_constraints @skip_constraints end |
Class Method Details
.init(env, skip_constraints: false) ⇒ Object
5 6 7 |
# File 'lib/jade/frontend/type_checking/state.rb', line 5 def self.init(env, skip_constraints: false) new(env, [], skip_constraints) end |
Instance Method Details
#add_errors(more_errors) ⇒ Object
30 31 32 |
# File 'lib/jade/frontend/type_checking/state.rb', line 30 def add_errors(more_errors) with(errors: errors + more_errors) end |
#bind(key, value) ⇒ Object
38 39 40 |
# File 'lib/jade/frontend/type_checking/state.rb', line 38 def bind(key, value) with(env: env.bind(key, value)) end |
#fresh ⇒ Object
34 35 36 |
# File 'lib/jade/frontend/type_checking/state.rb', line 34 def fresh env.fresh end |
#to_result ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/jade/frontend/type_checking/state.rb', line 42 def to_result if errors.any? Err[errors] else Ok[env] end end |
#unify(left, right, rigid_vars = [], &block) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/jade/frontend/type_checking/state.rb', line 14 def unify(left, right, rigid_vars = [], &block) applied_left = env.substitution.apply(left) applied_right = env.substitution.apply(right) case Unification.unify(applied_left, applied_right, env, Unification::Context[rigid_vars]) in Ok(sub) with(env: env.composose_substitution(sub)) in Err(error) with( env: env.composose_substitution(error.partial_sub), errors: errors + [block.call(error)], ) end end |
#unify_result(result, right, rigid_vars = [], &block) ⇒ Object
9 10 11 12 |
# File 'lib/jade/frontend/type_checking/state.rb', line 9 def unify_result(result, right, rigid_vars = [], &block) unify(result.type, right, rigid_vars, &block) .then { [it, result.apply(it.env.substitution)] } end |