Class: Jade::Frontend::TypeChecking::State

Inherits:
Data
  • Object
show all
Defined in:
lib/jade/frontend/type_checking/state.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#envObject (readonly)

Returns the value of attribute env

Returns:

  • (Object)

    the current value of env



4
5
6
# File 'lib/jade/frontend/type_checking/state.rb', line 4

def env
  @env
end

#errorsObject (readonly)

Returns the value of attribute errors

Returns:

  • (Object)

    the current value of errors



4
5
6
# File 'lib/jade/frontend/type_checking/state.rb', line 4

def errors
  @errors
end

#skip_constraintsObject (readonly)

Returns the value of attribute skip_constraints

Returns:

  • (Object)

    the current value of 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

#freshObject



34
35
36
# File 'lib/jade/frontend/type_checking/state.rb', line 34

def fresh
  env.fresh
end

#to_resultObject



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