Class: Yoda::Typing::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/yoda/typing/context.rb

Defined Under Namespace

Classes: TraceStore

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(registry:, caller_object:, lexical_scope:, env: Environment.new, parent: nil, trace_store: TraceStore.new) ⇒ Context

Returns a new instance of Context.

Parameters:

  • registry (Store::Registry)
  • caller_object (Store::Objects::Base)

    represents who is the evaluator of the code.

  • lexical_scope (Array<Path>)

    represents where the code presents.



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/yoda/typing/context.rb', line 24

def initialize(registry:, caller_object:, lexical_scope:, env: Environment.new, parent: nil, trace_store: TraceStore.new)
  fail ArgumentError, registry unless registry.is_a?(Store::Registry)
  fail ArgumentError, caller_object unless caller_object.is_a?(Store::Objects::Base)
  fail ArgumentError, lexical_scope unless lexical_scope.is_a?(LexicalScope)

  @registry = registry
  @caller_object = caller_object
  @lexical_scope = lexical_scope
  @env = env
  @trace_store = trace_store
end

Instance Attribute Details

#caller_objectStore::Objects::Base (readonly)



10
11
12
# File 'lib/yoda/typing/context.rb', line 10

def caller_object
  @caller_object
end

#envEnvironment (readonly)

Returns:



16
17
18
# File 'lib/yoda/typing/context.rb', line 16

def env
  @env
end

#lexical_scopeLexicalScope (readonly)

Returns:



13
14
15
# File 'lib/yoda/typing/context.rb', line 13

def lexical_scope
  @lexical_scope
end

#registryStore::Registry (readonly)

Returns:



7
8
9
# File 'lib/yoda/typing/context.rb', line 7

def registry
  @registry
end

#trace_storeTraceStore (readonly)

Returns:



19
20
21
# File 'lib/yoda/typing/context.rb', line 19

def trace_store
  @trace_store
end

Instance Method Details

#bind_trace(node, trace) ⇒ Object

Parameters:

  • node (::AST::Node)
  • trace (Trace::Base)


52
53
54
# File 'lib/yoda/typing/context.rb', line 52

def bind_trace(node, trace)
  trace_store.bind_trace(node, trace)
end

#derive(caller_object: self.caller_object, lexical_scope: self.lexical_scope) ⇒ self

Parameters:

  • registry (Store::Registry)
  • caller_object (Store::Objects::Base) (defaults to: self.caller_object)

    represents who is the evaluator of the code.

  • lexical_scope (Array<Path>) (defaults to: self.lexical_scope)

    represents where the code presents.

Returns:

  • (self)


40
41
42
# File 'lib/yoda/typing/context.rb', line 40

def derive(caller_object: self.caller_object, lexical_scope: self.lexical_scope)
  self.class.new(registry: registry, caller_object: caller_object, lexical_scope: lexical_scope, parent: self, trace_store: trace_store)
end

#find_trace(node) ⇒ Trace::Base?

Parameters:

  • node (::AST::Node)

Returns:

  • (Trace::Base, nil)


46
47
48
# File 'lib/yoda/typing/context.rb', line 46

def find_trace(node)
  trace_store.find_trace(node)
end