Merge branch 'bugfix/fn-do' of git://github.com/olasd/hy
This commit is contained in:
commit
3cd35e3ca6
@ -67,7 +67,7 @@ class HyASTCompiler(object):
|
|||||||
|
|
||||||
if self.returnable and len(tree) > 0:
|
if self.returnable and len(tree) > 0:
|
||||||
el = tree[0]
|
el = tree[0]
|
||||||
if not isinstance(el, ast.stmt):
|
if not isinstance(el, (ast.stmt, list)):
|
||||||
el = tree.pop(0)
|
el = tree.pop(0)
|
||||||
ret.append(ast.Return(value=el,
|
ret.append(ast.Return(value=el,
|
||||||
lineno=el.lineno,
|
lineno=el.lineno,
|
||||||
|
@ -85,6 +85,17 @@
|
|||||||
(assert (= 1 1))
|
(assert (= 1 1))
|
||||||
(assert (= 1 1)))))
|
(assert (= 1 1)))))
|
||||||
|
|
||||||
|
(defn test-branching-expr-count-with-do []
|
||||||
|
"NATIVE: make sure we execute the right number of expressions in the branch"
|
||||||
|
(setv counter 0)
|
||||||
|
(if false
|
||||||
|
(assert (= 2 1))
|
||||||
|
(do
|
||||||
|
(setv counter (+ counter 1))
|
||||||
|
(setv counter (+ counter 1))
|
||||||
|
(setv counter (+ counter 1))))
|
||||||
|
(assert (= counter 3)))
|
||||||
|
|
||||||
|
|
||||||
(defn test-cond []
|
(defn test-cond []
|
||||||
"NATIVE: test if cond sorta works."
|
"NATIVE: test if cond sorta works."
|
||||||
@ -229,3 +240,38 @@
|
|||||||
[2 4]))
|
[2 4]))
|
||||||
(assert (= (list-comp (, x y) (x (range 2) y (range 2)))
|
(assert (= (list-comp (, x y) (x (range 2) y (range 2)))
|
||||||
[(, 0 0) (, 0 1) (, 1 0) (, 1 1)])))
|
[(, 0 0) (, 0 1) (, 1 0) (, 1 1)])))
|
||||||
|
|
||||||
|
(defn test-defn-order []
|
||||||
|
"NATIVE: test defn evaluation order"
|
||||||
|
(setv acc [])
|
||||||
|
(defn my-fun []
|
||||||
|
(.append acc "Foo")
|
||||||
|
(.append acc "Bar")
|
||||||
|
(.append acc "Baz"))
|
||||||
|
(my-fun)
|
||||||
|
(assert (= acc ["Foo" "Bar" "Baz"])))
|
||||||
|
|
||||||
|
(defn test-defn-return []
|
||||||
|
"NATIVE: test defn return"
|
||||||
|
(defn my-fun [x]
|
||||||
|
(+ x 1))
|
||||||
|
(assert (= 43 (my-fun 42))))
|
||||||
|
|
||||||
|
(defn test-defn-do []
|
||||||
|
"NATIVE: test defn evaluation order with do"
|
||||||
|
(setv acc [])
|
||||||
|
(defn my-fun []
|
||||||
|
(do
|
||||||
|
(.append acc "Foo")
|
||||||
|
(.append acc "Bar")
|
||||||
|
(.append acc "Baz")))
|
||||||
|
(my-fun)
|
||||||
|
(assert (= acc ["Foo" "Bar" "Baz"])))
|
||||||
|
|
||||||
|
(defn test-defn-do-return []
|
||||||
|
"NATIVE: test defn return with do"
|
||||||
|
(defn my-fun [x]
|
||||||
|
(do
|
||||||
|
(+ x 42) ; noop
|
||||||
|
(+ x 1)))
|
||||||
|
(assert (= 43 (my-fun 42))))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user