Class: Yoda::Evaluation::Evaluator
- Inherits:
-
Object
- Object
- Yoda::Evaluation::Evaluator
- Defined in:
- lib/yoda/evaluation/evaluator.rb
Instance Attribute Summary collapse
- #registry ⇒ Store::Registry readonly
- #scope ⇒ Parsing::Scopes::Base readonly
Class Method Summary collapse
- .from_ast(registry, ast, location) ⇒ Evaluator
- .from_root_scope(registry, root_scope, location) ⇒ Evaluator
Instance Method Summary collapse
- #calculate_trace(code_node) ⇒ Typing::Traces::Base?
- #calculate_type(code_node) ⇒ Model::Types::Base?
- #calculate_values(code_node) ⇒ Array<Store::Objects::Base>
-
#initialize(registry, scope) ⇒ Evaluator
constructor
A new instance of Evaluator.
- #scope_constant ⇒ Store::Objects::Base?
Constructor Details
#initialize(registry, scope) ⇒ Evaluator
Returns a new instance of Evaluator.
28 29 30 31 |
# File 'lib/yoda/evaluation/evaluator.rb', line 28 def initialize(registry, scope) @registry = registry @scope = scope end |
Instance Attribute Details
#registry ⇒ Store::Registry (readonly)
8 9 10 |
# File 'lib/yoda/evaluation/evaluator.rb', line 8 def registry @registry end |
#scope ⇒ Parsing::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
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
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?
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?
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>
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_constant ⇒ Store::Objects::Base?
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 |