diff --git a/hy/compiler.py b/hy/compiler.py index 5265963..0b79f5b 100644 --- a/hy/compiler.py +++ b/hy/compiler.py @@ -86,15 +86,18 @@ class HyASTCompiler(object): def compile_do_expression(self, expr): return [self.compile(x) for x in expr[1:]] + def _code_branch(self, branch): + if isinstance(branch, list): + return self._mangle_branch(branch) + return self._mangle_branch([branch]) + @builds("if") def compile_if_expression(self, expr): expr.pop(0) - lw = lambda w: (self._mangle_branch(w) - if isinstance(w, list) else self._mangle_branch([w])) return ast.If(test=self.compile(expr.pop(0)), - body=lw(self.compile(expr.pop(0))), - orelse=lw(self.compile(expr.pop(0))), + body=self._code_branch(self.compile(expr.pop(0))), + orelse=self._code_branch(self.compile(expr.pop(0))), lineno=expr.start_line, col_offset=expr.start_column) @@ -260,7 +263,7 @@ class HyASTCompiler(object): kwonlyargs=[], kw_defaults=[], defaults=[]), - body=self._mangle_branch([ + body=self._code_branch([ self.compile(x) for x in expression]), decorator_list=[]) diff --git a/tests/native_tests/language.hy b/tests/native_tests/language.hy index 3ae92bf..3c59757 100644 --- a/tests/native_tests/language.hy +++ b/tests/native_tests/language.hy @@ -28,9 +28,25 @@ (assert (>= 5 5 5 5 ))) -; implement null -;(defn test_is [] -; "NATIVE: test is" -; (def a null) -; (assert (is a null)) -; (assert (is-not a "b"))) +(defn test_is [] + "NATIVE: test is can deal with None" + (def a null) + (assert (is a null)) + (assert (is-not a "b"))) + + +(defn test_branching [] + "NATIVE: test if branching" + (if true + (assert (= 1 1)) + (assert (= 2 1)))) + + +(defn test_branching_with_do [] + "NATIVE: test if branching (multiline)" + (if false + (assert (= 2 1)) + (do + (assert (= 1 1)) + (assert (= 1 1)) + (assert (= 1 1)))))