Fix up the native-macros to use compiler imports
This commit is contained in:
parent
31c14e4167
commit
5a74fff7e6
@ -343,12 +343,21 @@ class HyASTCompiler(object):
|
|||||||
"""Convert the Result's imports to statements"""
|
"""Convert the Result's imports to statements"""
|
||||||
ret = Result()
|
ret = Result()
|
||||||
for module, names in self.imports.items():
|
for module, names in self.imports.items():
|
||||||
|
if None in names:
|
||||||
|
ret += self.compile([
|
||||||
|
HyExpression([
|
||||||
|
HySymbol("import"),
|
||||||
|
HySymbol(module),
|
||||||
|
]).replace(expr)
|
||||||
|
])
|
||||||
|
names = sorted(name for name in names if name)
|
||||||
|
if names:
|
||||||
ret += self.compile([
|
ret += self.compile([
|
||||||
HyExpression([
|
HyExpression([
|
||||||
HySymbol("import"),
|
HySymbol("import"),
|
||||||
HyList([
|
HyList([
|
||||||
HySymbol(module),
|
HySymbol(module),
|
||||||
HyList([HySymbol(name) for name in sorted(names)])
|
HyList([HySymbol(name) for name in names])
|
||||||
])
|
])
|
||||||
]).replace(expr)
|
]).replace(expr)
|
||||||
])
|
])
|
||||||
@ -1608,19 +1617,19 @@ class HyASTCompiler(object):
|
|||||||
"for macro name" % type(name).__name__))
|
"for macro name" % type(name).__name__))
|
||||||
name = HyString(name).replace(name)
|
name = HyString(name).replace(name)
|
||||||
new_expression = HyExpression([
|
new_expression = HyExpression([
|
||||||
HySymbol("do"),
|
|
||||||
HyExpression([
|
|
||||||
HySymbol("import"),
|
|
||||||
HySymbol("hy.macros"),
|
|
||||||
]),
|
|
||||||
HyExpression([
|
|
||||||
HySymbol("with_decorator"),
|
HySymbol("with_decorator"),
|
||||||
HyExpression([HySymbol("hy.macros.macro"), name]),
|
HyExpression([HySymbol("hy.macros.macro"), name]),
|
||||||
HyExpression([HySymbol("fn")] + expression),
|
HyExpression([HySymbol("fn")] + expression),
|
||||||
]),
|
|
||||||
]).replace(expression)
|
]).replace(expression)
|
||||||
hy.importer.hy_eval(new_expression, {})
|
|
||||||
return self.compile(new_expression)
|
# Compile-time hack: we want to get our new macro now
|
||||||
|
hy.importer.hy_eval(new_expression, {'hy': hy})
|
||||||
|
|
||||||
|
# We really want to have a `hy` import to get hy.macro in
|
||||||
|
ret = self.compile(new_expression)
|
||||||
|
ret.add_imports('hy', [None])
|
||||||
|
|
||||||
|
return ret
|
||||||
|
|
||||||
@builds(HyInteger)
|
@builds(HyInteger)
|
||||||
def compile_integer(self, number):
|
def compile_integer(self, number):
|
||||||
|
Loading…
Reference in New Issue
Block a user