Added keyword c:xxx: to express that we want the concept, not its body

This commit is contained in:
2019-12-29 18:56:41 +01:00
parent 81b2355633
commit 197b0700fa
9 changed files with 191 additions and 65 deletions
+19 -5
View File
@@ -1,4 +1,5 @@
import copy
from enum import Enum
from core.ast.visitors import UnreferencedNamesVisitor
from core.builtin_concepts import BuiltinConcepts, ParserResultConcept
@@ -18,6 +19,7 @@ class PythonEvaluator(OneReturnValueEvaluator):
def __init__(self):
super().__init__(self.NAME, [BuiltinConcepts.EVALUATION], 50)
self.locals = {}
def matches(self, context, return_value):
return return_value.status and \
@@ -71,23 +73,35 @@ class PythonEvaluator(OneReturnValueEvaluator):
for name in unreferenced_names_visitor.names:
context.log(self.verbose_log, f"Resolving '{name}'.", self.name)
return_concept = False
if name in my_locals:
if name.startswith("__C__") and name.endswith("__C__"):
name_resolved = name[5:-5]
return_concept = True
else:
name_resolved = name
if name_resolved in my_locals:
context.log(self.verbose_log, f"Using value from property.", self.name)
continue
concept = context.sheerka.new(name)
concept = context.sheerka.new(name_resolved)
if context.sheerka.isinstance(concept, BuiltinConcepts.UNKNOWN_CONCEPT):
context.log(self.verbose_log, f"'{name}' is not a concept. Skipping.", self.name)
context.log(self.verbose_log, f"'{name_resolved}' is not a concept. Skipping.", self.name)
continue
context.log(self.verbose_log, f"'{name}' is a concept. Evaluating.", self.name)
context.log(self.verbose_log, f"'{name_resolved}' is a concept. Evaluating.", self.name)
sub_context = context.push(self.name, desc=f"Evaluating '{concept}'", obj=concept)
sub_context.log_new(self.verbose_log)
evaluated = context.sheerka.evaluate_concept(sub_context, concept, self.verbose_log)
if evaluated.key == concept.key:
my_locals[name] = evaluated.body if ConceptParts.BODY in evaluated.cached_asts else evaluated
my_locals[name] = evaluated if return_concept else \
evaluated.body if ConceptParts.BODY in evaluated.cached_asts else \
evaluated
if self.locals:
my_locals.update(self.locals)
return my_locals