Class: Yoda::Evaluation::Evaluator

Inherits:
Object
  • Object
show all
Defined in:
lib/yoda/evaluation/evaluator.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(registry, scope) ⇒ Evaluator

Returns a new instance of Evaluator.

Parameters:



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

def initialize(registry, scope)
  @registry = registry
  @scope = scope
end

Instance Attribute Details

#registryStore::Registry (readonly)

Returns:



8
9
10
# File 'lib/yoda/evaluation/evaluator.rb', line 8

def registry
  @registry
end

#scopeParsing::Scopes::Base (readonly)



5
6
7
# File 'lib/yoda/evaluation/evaluator.rb', line 5

def scope
  @scope
end

Class Method Details

.from_ast(registry, ast, location) ⇒ Evaluator

Parameters:

Returns:



14
15
16
# File 'lib/yoda/evaluation/evaluator.rb', line 14

def self.from_ast(registry, ast, location)
  from_root_scope(registry, Parsing::Scopes::Builder.new(ast).root_scope, location)
end

.from_root_scope(registry, root_scope, location) ⇒ Evaluator

Parameters:

Returns:



22
23
24
# File 'lib/yoda/evaluation/evaluator.rb', line 22

def self.from_root_scope(registry, root_scope, location)
  new(registry, root_scope.find_evaluation_root_scope(location) || root_scope)
end

Instance Method Details

#calculate_trace(code_node) ⇒ Typing::Traces::Base?

Parameters:

  • code_node (::Parser::AST::Node, nil)

Returns:



48
49
50
51
52
# File 'lib/yoda/evaluation/evaluator.rb', line 48

def calculate_trace(code_node)
  return nil unless code_node
  evaluate
  evaluator.find_trace(code_node)
end

#calculate_type(code_node) ⇒ Model::Types::Base?

Parameters:

  • code_node (::Parser::AST::Node)

Returns:



35
36
37
# File 'lib/yoda/evaluation/evaluator.rb', line 35

def calculate_type(code_node)
  calculate_trace(code_node)&.type
end

#calculate_values(code_node) ⇒ Array<Store::Objects::Base>

Parameters:

  • code_node (::Parser::AST::Node)

Returns:



41
42
43
44
# File 'lib/yoda/evaluation/evaluator.rb', line 41

def calculate_values(code_node)
  trace = calculate_trace(code_node)
  trace ? trace.values : []
end

#scope_constantStore::Objects::Base?

Returns:



55
56
57
58
59
# File 'lib/yoda/evaluation/evaluator.rb', line 55

def scope_constant
  @scope_constant ||= begin
    Store::Query::FindConstant.new(registry).find(scope.scope_name)
  end
end