Added RET keyword
This commit is contained in:
@@ -59,7 +59,7 @@ class AddConceptEvaluator(OneReturnValueEvaluator):
|
||||
concept.metadata.definition_type = def_concept_node.definition_type
|
||||
name_to_use = self.get_name_to_use(def_concept_node)
|
||||
|
||||
for prop in ("definition", "where", "pre", "post", "body"):
|
||||
for prop in ("definition", "where", "pre", "post", "body", "ret"):
|
||||
|
||||
part_ret_val = getattr(def_concept_node, prop)
|
||||
|
||||
|
||||
@@ -81,6 +81,7 @@ class PythonEvaluator(OneReturnValueEvaluator):
|
||||
concepts_entries = None
|
||||
evaluated = BuiltinConcepts.NOT_INITIALIZED
|
||||
errors = []
|
||||
expect_success = BuiltinConcepts.EVAL_SUCCESS_REQUESTED in context.local_hints
|
||||
for globals_ in all_possible_globals:
|
||||
try:
|
||||
# eval
|
||||
@@ -92,7 +93,8 @@ class PythonEvaluator(OneReturnValueEvaluator):
|
||||
context.log("Evaluating using 'exec'.", self.name)
|
||||
evaluated = self.exec_with_return(node.ast_, globals_, sheerka.locals)
|
||||
|
||||
break # in this first version, we stop once a success is found
|
||||
if not expect_success or evaluated:
|
||||
break # in this first version, we stop once a success is found
|
||||
except Exception as ex:
|
||||
if concepts_entries is None:
|
||||
concepts_entries = self.get_concepts_entries_from_globals(my_globals)
|
||||
@@ -246,7 +248,7 @@ class PythonEvaluator(OneReturnValueEvaluator):
|
||||
# make the product the rest as cartesian product
|
||||
res = [fixed_values]
|
||||
for k, v in concepts_with_body.items():
|
||||
res = core.utils.dict_product(res, [{k: context.sheerka.objvalue(v)}, {k: v}])
|
||||
res = core.utils.dict_product(res, [{k: v}, {k: context.sheerka.objvalue(v)}])
|
||||
|
||||
return res
|
||||
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
from core.builtin_concepts import BuiltinConcepts
|
||||
from core.builtin_helpers import ensure_evaluated
|
||||
from core.concept import Concept, ConceptParts
|
||||
from evaluators.BaseEvaluator import OneReturnValueEvaluator
|
||||
|
||||
|
||||
class RetEvaluator(OneReturnValueEvaluator):
|
||||
"""
|
||||
The evaluator transform the a concept, using the ret value
|
||||
"""
|
||||
|
||||
NAME = "Ret"
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(self.NAME, [BuiltinConcepts.EVALUATION], 10)
|
||||
|
||||
def matches(self, context, return_value):
|
||||
return return_value.status and \
|
||||
isinstance(return_value.value, Concept) and \
|
||||
return_value.value.metadata.ret is not None
|
||||
|
||||
def eval(self, context, return_value):
|
||||
sheerka = context.sheerka
|
||||
concept = return_value.value
|
||||
context.log(f"Processing ret value for concept {concept}.", self.name)
|
||||
|
||||
if not concept.metadata.is_evaluated:
|
||||
evaluated = ensure_evaluated(context, concept)
|
||||
if evaluated.key != concept.key:
|
||||
context.log(f"Failed to evaluate concept '{concept}'")
|
||||
return None
|
||||
ret = evaluated.get_value(ConceptParts.RET)
|
||||
else:
|
||||
ret = concept.get_value(ConceptParts.RET)
|
||||
|
||||
if isinstance(ret, Concept) and sheerka.is_known(ret):
|
||||
return sheerka.ret(self.name, True, ret, parents=[return_value])
|
||||
|
||||
context.log(f"ret '{ret}' is not a concept!")
|
||||
return None
|
||||
Reference in New Issue
Block a user