Add in for loops.

This commit is contained in:
Paul R. Tagliamonte 2013-03-06 22:09:13 -05:00
parent f51c0eee12
commit e6d094fd40
2 changed files with 20 additions and 1 deletions

4
bin/hy
View File

@ -1,2 +1,6 @@
#!/usr/bin/env python
from hy.importer import import_file_to_module
import sys
import_file_to_module("<STDIN>", sys.argv[1])

View File

@ -66,7 +66,7 @@ class HyASTCompiler(object):
if self.returnable and len(tree) > 0:
el = tree[0]
if not isinstance(el, ast.stmt):
el = tree.pop()
el = tree.pop(0)
ret.append(ast.Return(value=el,
lineno=el.lineno,
col_offset=el.col_offset))
@ -170,6 +170,21 @@ class HyASTCompiler(object):
col_offset=expression.start_column,
targets=[name], value=what)
@builds("for")
def compile_for_expression(self, expression):
expression.pop(0) # for
name, iterable = expression.pop(0)
target = self.compile_symbol(name)
target.ctx = ast.Store()
return ast.For(
lineno=expression.start_line,
col_offset=expression.start_column,
target=target,
iter=self.compile(iterable),
body=self._mangle_branch([self.compile(x) for x in expression]),
orelse=[])
@builds(HyList)
def compile_list(self, expr):
return ast.List(