diff --git a/hy/compiler/ast27.py b/hy/compiler/ast27.py index 9ef0437..66da473 100644 --- a/hy/compiler/ast27.py +++ b/hy/compiler/ast27.py @@ -1,5 +1,6 @@ # output ast for cpython 2.7 import ast +import imp from hy.lang.expression import HYExpression from hy.lang.number import HYNumber @@ -40,11 +41,6 @@ def _ast_binop(node, children, obj): def _ast_cmp(node, children, obj): - # Compare(left=Num(n=1), ops=[LtE()], comparators=[Num(n=2)]) - # Compare(left=Num(n=1), ops=[Gt(), Gt()], - # comparators=[Num(n=2), Num(n=3)]) - - # opscmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn inv = node.get_invocation() ops = { "==": ast.Eq, "<=": ast.LtE, ">=": ast.GtE, ">": ast.Gt, "<": ast.Lt, @@ -297,3 +293,11 @@ def forge_ast(name, forest): statements.append(ret) return ast.fix_missing_locations(ast.Module(body=statements)) + + +def forge_module(name, fpath, forest): + mod = imp.new_module(name) + mod.__file__ = fpath + ast = forge_ast(name, forest) + eval(compile(ast, fpath, "exec"), mod.__dict__) + return mod diff --git a/hy/lang/importer.py b/hy/lang/importer.py index 39401b3..7cf2a24 100644 --- a/hy/lang/importer.py +++ b/hy/lang/importer.py @@ -1,4 +1,6 @@ -from hy.compiler.modfaker import forge_module +# from hy.compiler.modfaker import forge_module +from hy.compiler.ast27 import forge_module + from hy.lex.tokenize import tokenize import sys import imp