First implementation of Debugger for SyaNodeParser
This commit is contained in:
+11
-53
@@ -14,9 +14,11 @@ from core.builtin_concepts import BuiltinConcepts, ErrorConcept, ReturnValueConc
|
||||
UnknownConcept, AllBuiltinConcepts
|
||||
from core.concept import Concept, ConceptParts, NotInit, get_concept_attrs
|
||||
from core.error import ErrorObj
|
||||
from core.global_symbols import EVENT_USER_INPUT_EVALUATED
|
||||
from core.profiling import profile
|
||||
from core.sheerka.ExecutionContext import ExecutionContext
|
||||
from core.sheerka_logger import console_handler
|
||||
from core.simple_debug import my_debug
|
||||
from core.tokenizer import Token, TokenKind
|
||||
from printer.SheerkaPrinter import SheerkaPrinter
|
||||
from sdp.sheerkaDataProvider import SheerkaDataProvider, Event
|
||||
@@ -81,15 +83,6 @@ class Sheerka(Concept):
|
||||
self.return_value_concept_id = None
|
||||
self.error_concept_id = None
|
||||
|
||||
# a concept can be instantiated
|
||||
# ex: File is a concept, but File('foo.txt') is an instance
|
||||
# TODO: manage contexts
|
||||
self.instances = []
|
||||
|
||||
# List of the known rules by the system
|
||||
# ex: hello => say('hello')
|
||||
self.rules = []
|
||||
|
||||
self.sdp: SheerkaDataProvider = None
|
||||
self.cache_manager = CacheManager(cache_only)
|
||||
|
||||
@@ -105,10 +98,11 @@ class Sheerka(Concept):
|
||||
self.printer_handler = SheerkaPrinter(self)
|
||||
|
||||
self.during_restore = False
|
||||
self.during_initialisation = False
|
||||
self._builtins_classes_cache = None
|
||||
|
||||
self.save_execution_context = True
|
||||
self.enable_process_return_values = False
|
||||
self.enable_process_return_values = True
|
||||
|
||||
self.methods_with_context = {"test_using_context"} # only the names, the method is defined in sheerka_methods
|
||||
self.sheerka_methods = {
|
||||
@@ -120,10 +114,6 @@ class Sheerka(Concept):
|
||||
|
||||
self.locals = {}
|
||||
|
||||
self.last_executions = []
|
||||
self.last_return_values = []
|
||||
self.execution_count = 0
|
||||
|
||||
@property
|
||||
def resolved_concepts_by_first_keyword(self):
|
||||
"""
|
||||
@@ -196,6 +186,7 @@ class Sheerka(Concept):
|
||||
self.enable_process_return_values = enable_process_return_values
|
||||
|
||||
try:
|
||||
self.during_initialisation = True
|
||||
from sheerkapickle.sheerka_handlers import initialize_pickle_handlers
|
||||
initialize_pickle_handlers()
|
||||
|
||||
@@ -235,6 +226,9 @@ class Sheerka(Concept):
|
||||
except IOError as e:
|
||||
res = ReturnValueConcept(self, False, self.get(BuiltinConcepts.ERROR), e)
|
||||
|
||||
finally:
|
||||
self.during_initialisation = False
|
||||
|
||||
return res
|
||||
|
||||
def initialize_caching(self):
|
||||
@@ -445,6 +439,7 @@ class Sheerka(Concept):
|
||||
:return:
|
||||
"""
|
||||
# self.log.debug(f"Processing user input '{text}', {user_name=}.")
|
||||
my_debug(f"****************** Processing user input '{text}', {user_name=}.***********************************")
|
||||
event = Event(text, user_name)
|
||||
self.sdp.save_event(event)
|
||||
|
||||
@@ -456,6 +451,7 @@ class Sheerka(Concept):
|
||||
desc=f"Evaluating '{text}'") as execution_context:
|
||||
|
||||
user_input = self.ret(self.name, True, self.new(BuiltinConcepts.USER_INPUT, body=text, user_name=user_name))
|
||||
execution_context.add_inputs(user_input=user_input)
|
||||
|
||||
# TODO. Must be a context hint, not a return value
|
||||
reduce_requested = self.ret(self.name, True, self.new(BuiltinConcepts.REDUCE_REQUESTED))
|
||||
@@ -466,32 +462,12 @@ class Sheerka(Concept):
|
||||
if self.cache_manager.is_dirty:
|
||||
self.cache_manager.commit(execution_context)
|
||||
|
||||
# exec_count = ExecutionContext.ids[execution_context.event.get_digest()]
|
||||
# print("Execution Context Count:", exec_count)
|
||||
if self.save_execution_context:
|
||||
try:
|
||||
# if exec_count > 3400:
|
||||
# print("Saving result. digest=", execution_context.event.get_digest())
|
||||
self.sdp.save_result(execution_context)
|
||||
except Exception as ex:
|
||||
print(f"Failed to save execution context. Reason: {ex}")
|
||||
pass
|
||||
# self.log.error(f"Failed to save execution context. Reason: {ex}")
|
||||
self.publish(execution_context, EVENT_USER_INPUT_EVALUATED)
|
||||
|
||||
# Do not save execution contexts from process_return_values
|
||||
if self.enable_process_return_values:
|
||||
self.process_return_values(execution_context, ret)
|
||||
|
||||
self.execution_count += 1
|
||||
self._last_execution = execution_context
|
||||
if len(self.last_executions) == self.MAX_EXECUTION_HISTORY:
|
||||
del self.last_executions[0]
|
||||
self.last_executions.append(execution_context)
|
||||
|
||||
if len(self.last_return_values) == self.MAX_RETURN_VALUES_HISTORY:
|
||||
del self.last_return_values[0]
|
||||
self.last_return_values.append(ret)
|
||||
|
||||
return ret
|
||||
|
||||
def print(self, result, instructions=None):
|
||||
@@ -887,24 +863,6 @@ class Sheerka(Concept):
|
||||
|
||||
return self.parsers_prefix + name
|
||||
|
||||
# def concepts(self):
|
||||
# """
|
||||
# List of all known concepts (look up in sdp)
|
||||
# :return:
|
||||
# """
|
||||
# res = []
|
||||
# lst = self.sdp.list(self.CONCEPTS_BY_ID_ENTRY)
|
||||
# for item in lst:
|
||||
# if isinstance(item, list):
|
||||
# res.extend(item)
|
||||
# else:
|
||||
# res.append(item)
|
||||
#
|
||||
# return sorted(res, key=lambda i: int(i.id))
|
||||
|
||||
def get_last_execution(self):
|
||||
return self._last_execution
|
||||
|
||||
def test(self):
|
||||
return f"I have access to Sheerka !"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user