Refactored sheerka execution flow + Enhanced log management
This commit is contained in:
@@ -7,10 +7,6 @@ from parsers.PythonParser import PythonNode
|
||||
import ast
|
||||
import core.ast.nodes
|
||||
|
||||
import logging
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class PythonEvaluator(OneReturnValueEvaluator):
|
||||
NAME = "Python"
|
||||
@@ -31,17 +27,21 @@ class PythonEvaluator(OneReturnValueEvaluator):
|
||||
sheerka = context.sheerka
|
||||
node = return_value.value.value
|
||||
try:
|
||||
log.debug(f"Evaluating python node {node}")
|
||||
context.log(self.verbose_log, f"Evaluating python node {node}", self.name)
|
||||
my_locals = self.get_locals(context, node.ast_)
|
||||
context.log(self.verbose_log, f"locals={my_locals}", self.name)
|
||||
|
||||
if isinstance(node.ast_, ast.Expression):
|
||||
context.log(self.verbose_log, "Evaluating using 'eval'", self.name)
|
||||
compiled = compile(node.ast_, "<string>", "eval")
|
||||
evaluated = eval(compiled, {}, my_locals)
|
||||
else:
|
||||
context.log(self.verbose_log, "Evaluating using 'exec'", self.name)
|
||||
evaluated = self.exec_with_return(node.ast_, my_locals)
|
||||
|
||||
return sheerka.ret(self.name, True, evaluated, parents=[return_value])
|
||||
except Exception as error:
|
||||
context.log_error(self.verbose_log, error, self.name)
|
||||
error = sheerka.new(BuiltinConcepts.ERROR, body=error)
|
||||
return sheerka.ret(self.name, False, error, parents=[return_value])
|
||||
|
||||
@@ -60,7 +60,7 @@ class PythonEvaluator(OneReturnValueEvaluator):
|
||||
if context.sheerka.isinstance(concept, BuiltinConcepts.UNKNOWN_CONCEPT):
|
||||
continue
|
||||
|
||||
sub_context = context.push(self.name, "Evaluating body", concept)
|
||||
sub_context = context.push(self.name, desc="Evaluating body", obj=concept)
|
||||
context.sheerka.eval_concept(sub_context, concept, ["body"])
|
||||
|
||||
if not context.sheerka.isa(concept.body, BuiltinConcepts.ERROR):
|
||||
|
||||
Reference in New Issue
Block a user