Merge branch 'master' into pr/263

This commit is contained in:
Paul Tagliamonte 2013-07-23 00:07:11 -04:00
commit 7aa000b6a0
3 changed files with 29 additions and 6 deletions

View File

@ -392,7 +392,7 @@ In python we might see::
The same thing in Hy::
=> (defn optional_arg [pos1 pos2 &optional keyword1 [keyword2 88]]
=> (defn optional_arg [pos1 pos2 &optional keyword1 [keyword2 42]]
... [pos1 pos2 keyword1 keyword2])
=> (optional_arg 1 2)
[1 2 None 42]

View File

@ -1200,11 +1200,18 @@ class HyASTCompiler(object):
thing = self._storeize(self.compile(args.pop(0)))
body = self._compile_branch(expr)
body += body.expr_as_stmt()
if not body.stmts:
body += ast.Pass(lineno=expr.start_line,
col_offset=expr.start_column)
var = self.get_anon_var()
name = ast.Name(id=ast_str(var), arg=ast_str(var),
ctx=ast.Store(),
lineno=expr.start_line,
col_offset=expr.start_column)
# Store the result of the body in a tempvar
body += ast.Assign(targets=[name],
value=body.force_expr,
lineno=expr.start_line,
col_offset=expr.start_column)
the_with = ast.With(context_expr=ctx.force_expr,
lineno=expr.start_line,
@ -1216,7 +1223,16 @@ class HyASTCompiler(object):
the_with.items = [ast.withitem(context_expr=ctx.force_expr,
optional_vars=thing)]
return ctx + the_with
ret = ctx + the_with
# And make our expression context our temp variable
expr_name = ast.Name(id=ast_str(var), arg=ast_str(var),
ctx=ast.Load(),
lineno=expr.start_line,
col_offset=expr.start_column)
ret += Result(expr=expr_name, temp_variables=[expr_name, name])
return ret
@builds(",")
def compile_tuple(self, expr):

View File

@ -411,6 +411,13 @@
(with [(open "README.md" "r")] (do)))
(defn test-with-return []
"NATIVE: test that with returns stuff"
(defn read-file [filename]
(with [fd (open filename "r")] (.read fd)))
(assert (!= 0 (len (read-file "README.md")))))
(defn test-for-doodle []
"NATIVE: test for-do"
(do (do (do (do (do (do (do (do (do (setv (, x y) (, 0 0)))))))))))