Implemented SheerkaOntology
This commit is contained in:
@@ -7,7 +7,8 @@ import core.builtin_helpers
|
||||
import core.utils
|
||||
from core.ast_helpers import UnreferencedNamesVisitor, NamesWithAttributesVisitor
|
||||
from core.builtin_concepts import BuiltinConcepts, ParserResultConcept
|
||||
from core.concept import ConceptParts, Concept, NotInit
|
||||
from core.concept import ConceptParts, Concept
|
||||
from core.global_symbols import NotInit, NotFound
|
||||
from core.rule import Rule
|
||||
from core.sheerka.ExecutionContext import ExecutionContext
|
||||
from core.tokenizer import Token, TokenKind
|
||||
@@ -127,12 +128,16 @@ class PythonEvaluator(OneReturnValueEvaluator):
|
||||
for globals_ in all_possible_globals:
|
||||
try:
|
||||
# eval
|
||||
my_locals = {}
|
||||
if isinstance(node.ast_, ast.Expression):
|
||||
context.log("Evaluating using 'eval'.", self.name)
|
||||
evaluated = eval(node.get_compiled(), globals_, sheerka.locals)
|
||||
evaluated = eval(node.get_compiled(), globals_, my_locals)
|
||||
else:
|
||||
context.log("Evaluating using 'exec'.", self.name)
|
||||
evaluated = self.exec_with_return(node.ast_, globals_, sheerka.locals)
|
||||
evaluated = self.exec_with_return(node.ast_, globals_, my_locals)
|
||||
|
||||
# TODO find a better implementation using SheerkaMemory
|
||||
sheerka.locals.update(my_locals)
|
||||
|
||||
if not expect_success or evaluated:
|
||||
break # in this first version, we stop once a success is found
|
||||
@@ -140,8 +145,8 @@ class PythonEvaluator(OneReturnValueEvaluator):
|
||||
if concepts_entries is None:
|
||||
concepts_entries = self.get_concepts_entries_from_globals(my_globals)
|
||||
eval_error = PythonEvalError(ex,
|
||||
traceback.format_exc() if get_trace_back else None,
|
||||
self.get_concepts_values_from_globals(globals_, concepts_entries))
|
||||
traceback.format_exc() if get_trace_back else None,
|
||||
self.get_concepts_values_from_globals(globals_, concepts_entries))
|
||||
errors.append(eval_error)
|
||||
exception_debugger.debug_var("exception", eval_error.error, is_error=True)
|
||||
exception_debugger.debug_var("trace", eval_error.traceback, is_error=True)
|
||||
@@ -223,8 +228,13 @@ class PythonEvaluator(OneReturnValueEvaluator):
|
||||
my_globals["sheerka"] = Expando(bag)
|
||||
continue
|
||||
|
||||
# search in local variables. To remove when local variables will be merged with memory
|
||||
if name in context.sheerka.locals:
|
||||
my_globals[name] = context.sheerka.locals[name]
|
||||
continue
|
||||
|
||||
# search in short term memory
|
||||
if (obj := context.get_from_short_term_memory(name)) is not None:
|
||||
if (obj := context.get_from_short_term_memory(name)) is not NotFound:
|
||||
context.log(f"Resolving '{name}'. Using value found in STM.", self.name)
|
||||
my_globals[name] = obj
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user