Class: Yoda::Services::Evaluator

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/yoda/services/evaluator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ast:, environment:) ⇒ Evaluator

Returns a new instance of Evaluator.

Parameters:



21
22
23
24
25
26
# File 'lib/yoda/services/evaluator.rb', line 21

def initialize(ast:, environment:)
  @ast = ast
  @environment = environment
  @inferencer = Typing::Inferencer.create_for_root(environment: environment)
  @lock = Concurrent::ReadWriteLock.new
end

Instance Attribute Details

#astAST::Vnode (readonly)

Returns:



9
10
11
# File 'lib/yoda/services/evaluator.rb', line 9

def ast
  @ast
end

#environmentModel::Environment (readonly)

Returns:



12
13
14
# File 'lib/yoda/services/evaluator.rb', line 12

def environment
  @environment
end

#inferencerTyping::Inferencer (readonly)

Returns:



15
16
17
# File 'lib/yoda/services/evaluator.rb', line 15

def inferencer
  @inferencer
end

Instance Method Details

#evaluatevoid

This method returns an undefined value.



29
30
31
# File 'lib/yoda/services/evaluator.rb', line 29

def evaluate
  tracer
end

#tracerTyping::Inferencer::Tracer



34
35
36
37
38
39
40
41
# File 'lib/yoda/services/evaluator.rb', line 34

def tracer
  @lock.with_write_lock do
    @tracer ||= begin
      inferencer.infer(ast)
      inferencer.tracer
    end
  end
end