Add in for loops.
This commit is contained in:
parent
f51c0eee12
commit
e6d094fd40
4
bin/hy
4
bin/hy
@ -1,2 +1,6 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
from hy.importer import import_file_to_module
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import_file_to_module("<STDIN>", sys.argv[1])
|
||||||
|
@ -66,7 +66,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):
|
||||||
el = tree.pop()
|
el = tree.pop(0)
|
||||||
ret.append(ast.Return(value=el,
|
ret.append(ast.Return(value=el,
|
||||||
lineno=el.lineno,
|
lineno=el.lineno,
|
||||||
col_offset=el.col_offset))
|
col_offset=el.col_offset))
|
||||||
@ -170,6 +170,21 @@ class HyASTCompiler(object):
|
|||||||
col_offset=expression.start_column,
|
col_offset=expression.start_column,
|
||||||
targets=[name], value=what)
|
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)
|
@builds(HyList)
|
||||||
def compile_list(self, expr):
|
def compile_list(self, expr):
|
||||||
return ast.List(
|
return ast.List(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user