From 8a70d5c90fe248c1e303d94005ca5d8a3b8a579e Mon Sep 17 00:00:00 2001 From: Kodi Arfer Date: Sun, 17 Jun 2018 10:10:53 -0700 Subject: [PATCH] Fold _branch into the compiler --- hy/compiler.py | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/hy/compiler.py b/hy/compiler.py index 7a67aa7..36d1c7e 100755 --- a/hy/compiler.py +++ b/hy/compiler.py @@ -272,26 +272,6 @@ class Result(object): ) -def _branch(results): - """Make a branch out of a list of Result objects - - This generates a Result from the given sequence of Results, forcing each - expression context as a statement before the next result is used. - - We keep the expression context of the last argument for the returned Result - """ - results = list(results) - ret = Result() - for result in results[:-1]: - ret += result - ret += result.expr_as_stmt() - - for result in results[-1:]: - ret += result - - return ret - - def is_unpack(kind, x): return (isinstance(x, HyExpression) and len(x) > 0 @@ -452,7 +432,20 @@ class HyASTCompiler(object): return compiled_exprs, ret, keywords def _compile_branch(self, exprs): - return _branch(self.compile(expr) for expr in exprs) + """Make a branch out of an iterable of Result objects + + This generates a Result from the given sequence of Results, forcing each + expression context as a statement before the next result is used. + + We keep the expression context of the last argument for the returned Result + """ + ret = Result() + for x in map(self.compile, exprs[:-1]): + ret += x + ret += x.expr_as_stmt() + if exprs: + ret += self.compile(exprs[-1]) + return ret def _storeize(self, expr, name, func=None): """Return a new `name` object with an ast.Store() context"""