Skip to content

Commit

Permalink
make all the Unfinished and RASPFunction calls explicit, so they can …
Browse files Browse the repository at this point in the history
…be easily found whenever editing things
  • Loading branch information
gailweiss committed Feb 5, 2024
1 parent a10c438 commit 57ecaf2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
5 changes: 2 additions & 3 deletions RASP_support/DrawCompFlow.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,12 +556,11 @@ def draw_comp_flow(self, w, filename=None,
keep_dot=False, show=True,
force_vertical_layers=True, add_tokens_on_ff=False):
if w is not None:
self(w) # execute seq (and all its ancestors) on the given input w.
# if w==None, assume seq has already been executed on some input.
self.call(w) # execute seq (and all its ancestors) on the given input
if not self.last_w == w:
print("evaluating input failed")
return
else:
else: # if w == None, assume seq has already been executed on some input.
w = self.last_w
if None is filename:
name = self.name
Expand Down
12 changes: 6 additions & 6 deletions RASP_support/Evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def __str__(self):
return self.creator + " function: " + self.name \
+ "(" + ", ".join(self.argnames) + ")"

def __call__(self, *args):
def call(self, *args):
top_eval = args[-1]
args = args[:-1]
# nesting, because function shouldn't affect the enclosing environment
Expand Down Expand Up @@ -165,7 +165,7 @@ def draw(self, ast):
if not isinstance(unf, UnfinishedSequence):
raise RASPTypeError("draw expects unfinished sequence, got:", unf)
unf.draw_comp_flow(example)
res = unf(example)
res = unf.call(example)
res.created_from_input = example
self.backup_example = prev_backup
return JustVal(res)
Expand Down Expand Up @@ -557,15 +557,15 @@ def _evaluateApplication(self, ast, unf):
raise RASPTypeError(
"Applying unfinished expects iterable input, got:",
strdesc(input_val))
res = unf(input_val)
res = unf.call(input_val)
res.created_from_input = input_val
return res

def _evaluateRASPFunction(self, ast, raspfun):
args_trees = self._get_first_cont_list(ast.inputexprs)
args = tuple(self.evaluateExpr(t) for t in args_trees) + (self,)
real_args = args[:-1]
res = raspfun(*args)
res = raspfun.call(*args)
if isinstance(res, Unfinished):
res.setname(
raspfun.name+"("+" , ".join(strdesc(a, desc_cap=20)
Expand Down Expand Up @@ -629,7 +629,7 @@ def _test_res(self, res):
if isinstance(res, Unfinished):
def succeeds_with(exampe):
try:
res(example, just_pass_exception_up=True)
res.call(example, just_pass_exception_up=True)
except Exception:
return False
else:
Expand All @@ -643,7 +643,7 @@ def succeeds_with(exampe):
return
example = self.sequence_running_example if self.backup_example \
is None else self.backup_example
res(example, just_pass_exception_up=True)
res.call(example, just_pass_exception_up=True)

def evaluateExpr(self, ast, from_top=False):
def format_return(res, resname="out",
Expand Down
8 changes: 4 additions & 4 deletions RASP_support/FunctionalSupport.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def get_sorted_full_parents(self):
self._sort_full_parents()
return copy(self._sorted_full_parents)

def __call__(self, w, topcall=True, just_pass_exception_up=False):
def call(self, w, topcall=True, just_pass_exception_up=False):
if (not isinstance(w, Iterable)) or (not w):
raise RASPTypeError(
"RASP sequences/selectors expect non-empty iterables, got: "
Expand All @@ -201,11 +201,11 @@ def __call__(self, w, topcall=True, just_pass_exception_up=False):
# further back as they use memoization
for unf in self.get_sorted_full_parents():
# evaluate
unf(w, topcall=False,
unf.call(w, topcall=False,
just_pass_exception_up=just_pass_exception_up)

j_p_e_u = just_pass_exception_up
args = tuple(p(w,
args = tuple(p.call(w,
topcall=False,
just_pass_exception_up=j_p_e_u)
for p in self.parents_tuple)
Expand All @@ -232,7 +232,7 @@ def __call__(self, w, topcall=True, just_pass_exception_up=False):
a, b, tb = sys.exc_info()
tt = traceback.extract_tb(tb)
last_call = max([i for i, t in enumerate(tt)
if "__call__" in str(t)])
if "in call" in str(t)])
print(''.join(traceback.format_list(tt[last_call+1:])))

# traceback.print_exception(a,b,tb)
Expand Down
6 changes: 3 additions & 3 deletions RASP_support/REPL.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,19 @@ def print_named_val(self, name, val, ntabs=0, extra_first_pref=""):
optional_exampledesc = name + \
"("+formatstr(self.sequence_running_example)+") ="
print_seq(self.selector_running_example,
val(self.sequence_running_example),
val.call(self.sequence_running_example),
still_on_prev_line=True,
extra_pref=pref,
lastpref_if_shortprint=optional_exampledesc)
else:
print(pref, "\t Example:", name + "(" +
formatstr(self.sequence_running_example) + ") =",
val(self.sequence_running_example))
val.call(self.sequence_running_example))
elif isinstance(val, UnfinishedSelect):
print(pref, extra_first_pref, " selector:", name)
if self.show_selector_examples:
print(pref, "\t Example:")
print_select(self.selector_running_example, val(
print_select(self.selector_running_example, val.call(
self.selector_running_example), extra_pref=pref)
elif isinstance(val, RASPFunction):
print(pref, extra_first_pref, " "+str(val))
Expand Down

0 comments on commit 57ecaf2

Please sign in to comment.