Skip to content

Commit

Permalink
[refactor] Rename now that UserExit is not control flow.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Chu committed Jul 6, 2019
1 parent e19a904 commit 08b8b44
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
12 changes: 5 additions & 7 deletions core/main_loop.py
Expand Up @@ -87,14 +87,12 @@ def Interactive(opts, ex, c_parser, display, errfmt):
ui.PrintAst([node], opts)
break

is_control_flow, is_fatal = ex.ExecuteAndCatch(node)
is_return, _ = ex.ExecuteAndCatch(node)

status = ex.LastStatus()
if is_control_flow: # e.g. 'exit' in the middle of a script
if is_return:
done = True
break
if is_fatal: # e.g. divide by zero
break

break # QUIT LOOP after one iteration.

Expand Down Expand Up @@ -157,10 +155,10 @@ def Batch(ex, c_parser, arena, nodes_out=None):

#log('parsed %s', node)

is_control_flow, is_fatal = ex.ExecuteAndCatch(node)
is_return, is_fatal = ex.ExecuteAndCatch(node)
status = ex.LastStatus()
# e.g. divide by zero or 'exit' in the middle of a script
if is_control_flow or is_fatal:
# e.g. 'return' in middle of script, or divide by zero
if is_return or is_fatal:
break

return status
Expand Down
10 changes: 5 additions & 5 deletions osh/cmd_exec.py
Expand Up @@ -1193,14 +1193,14 @@ def ExecuteAndCatch(self, node, fork_external=True):
- _Eval() for eval builtin
- _RunFunc() for function call
"""
is_control_flow = False
is_return = False
is_fatal = False
try:
status = self._Execute(node, fork_external=fork_external)
except _ControlFlow as e:
# Return at top level is OK, unlike in bash.
if e.IsReturn():
is_control_flow = True
is_return = True
status = e.StatusCode()
else:
# Invalid control flow
Expand Down Expand Up @@ -1234,7 +1234,7 @@ def ExecuteAndCatch(self, node, fork_external=True):
self.dumper.MaybeDump(status)

self.mem.SetLastStatus(status)
return is_control_flow, is_fatal
return is_return, is_fatal

def MaybeRunExitTrap(self):
"""If an EXIT trap exists, run it.
Expand All @@ -1247,8 +1247,8 @@ def MaybeRunExitTrap(self):
"""
handler = self.traps.get('EXIT')
if handler:
is_control_flow, is_fatal = self.ExecuteAndCatch(handler.node)
return is_control_flow # explicit exit/return in the trap handler!
is_return, is_fatal = self.ExecuteAndCatch(handler.node)
return is_return # explicit 'return' in the trap handler!
else:
return False # nothing run, don't use its status

Expand Down

0 comments on commit 08b8b44

Please sign in to comment.