Added set of set handling (thru concept ISA)

This commit is contained in:
2020-02-17 21:07:06 +01:00
parent 7481b458e1
commit 86c2ff58d4
33 changed files with 635 additions and 232 deletions
+10 -8
View File
@@ -42,17 +42,18 @@ class PythonEvaluator(OneReturnValueEvaluator):
return sheerka.ret(self.name, False, not_for_me, parents=[return_value])
# get locals
my_locals = self.get_locals(context, node)
context.log(self.verbose_log, f"locals={my_locals}", self.name)
my_globals = self.get_globals(context, node)
my_locals = {}
context.log(self.verbose_log, f"globals={my_globals}", self.name)
# eval
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)
evaluated = eval(compiled, my_globals, my_locals)
else:
context.log(self.verbose_log, "Evaluating using 'exec'.", self.name)
evaluated = self.exec_with_return(node.ast_, my_locals)
evaluated = self.exec_with_return(node.ast_, my_globals, my_locals)
context.log(self.verbose_log, f"{evaluated=}", self.name)
return sheerka.ret(self.name, True, evaluated, parents=[return_value])
@@ -62,7 +63,7 @@ class PythonEvaluator(OneReturnValueEvaluator):
error = sheerka.new(BuiltinConcepts.ERROR, body=error)
return sheerka.ret(self.name, False, error, parents=[return_value])
def get_locals(self, context, node):
def get_globals(self, context, node):
my_locals = {
"sheerka": context.sheerka,
"desc": context.sheerka.dump_handler.dump_desc,
@@ -70,6 +71,7 @@ class PythonEvaluator(OneReturnValueEvaluator):
"definitions": context.sheerka.dump_handler.dump_definitions,
"history": context.sheerka.dump_handler.dump_history,
"state": context.sheerka.dump_handler.dump_state,
"Concept": core.concept.Concept
}
if context.obj:
context.log(self.verbose_log,
@@ -189,7 +191,7 @@ class PythonEvaluator(OneReturnValueEvaluator):
return result
def exec_with_return(self, code_ast, my_locals):
def exec_with_return(self, code_ast, my_globals, my_locals):
init_ast = copy.deepcopy(code_ast)
init_ast.body = code_ast.body[:-1]
@@ -199,6 +201,6 @@ class PythonEvaluator(OneReturnValueEvaluator):
exec(compile(init_ast, "<ast>", "exec"), {}, my_locals)
if type(last_ast.body[0]) == ast.Expr:
return eval(compile(self.expr_to_expression(last_ast.body[0]), "<ast>", "eval"), {}, my_locals)
return eval(compile(self.expr_to_expression(last_ast.body[0]), "<ast>", "eval"), my_globals, my_locals)
else:
exec(compile(last_ast, "<ast>", "exec"), {}, my_locals)
exec(compile(last_ast, "<ast>", "exec"), my_globals, my_locals)