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
+1 -1
View File
@@ -61,7 +61,7 @@ class AddConceptEvaluator(OneReturnValueEvaluator):
if not isinstance(part_ret_val, ReturnValueConcept) or not part_ret_val.status:
continue # Nothing to do is not initialized
# update the parts
# update the metadata
source = self.get_source(part_ret_val)
setattr(concept.metadata, prop, source)
+9 -1
View File
@@ -29,13 +29,21 @@ class EvalEvaluator(AllReturnValuesEvaluator):
for ret_val in return_values:
if ret_val.status and isinstance(ret_val.body, Concept) and ret_val.body.body:
context.log(self.verbose_log, f"Evaluating {ret_val}", who=self)
context.log(self.verbose_log, f"Evaluating {ret_val.body}", who=self)
result.append(sheerka.ret(self.name, True, ret_val.body.body, parents=[ret_val, self.eval_requested]))
elif ret_val.status and sheerka.isaset(context, ret_val.body):
context.log(self.verbose_log, f"Evaluating set {ret_val.body}", who=self)
result.append(sheerka.ret(
self.name,
True,
sheerka.get_set_elements(context, ret_val.body),
parents=[ret_val, self.eval_requested]))
if len(result) > 0:
return result
else:
# suppress the successful BuiltinConcepts.CONCEPT_EVAL_REQUESTED
# status of CONCEPT_EVAL_REQUESTED is now set to False
return sheerka.ret(
self.name,
False,
+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)