diff --git a/hy/compiler.py b/hy/compiler.py index 3901c8b..ad14379 100644 --- a/hy/compiler.py +++ b/hy/compiler.py @@ -197,8 +197,8 @@ class HyASTCompiler(object): def compile_eval(self, expr): expr.pop(0) return self.compile(HyExpression([ - HySymbol("hy_eval")] + expr + [HyExpression([HySymbol("globals")]) - ]).replace(expr)) + HySymbol("hy_eval")] + expr + [ + HyExpression([HySymbol("locals")])]).replace(expr)) @builds("do") @builds("progn") diff --git a/hy/importer.py b/hy/importer.py index 94ed984..ee9c405 100644 --- a/hy/importer.py +++ b/hy/importer.py @@ -51,21 +51,21 @@ def import_file_to_hst(fpath): def import_file_to_ast(fpath): tree = import_file_to_hst(fpath) - ast = hy_compile(tree) - return ast + _ast = hy_compile(tree) + return _ast def import_string_to_ast(buff): tree = import_buffer_to_hst(StringIO(buff)) - ast = hy_compile(tree) - return ast + _ast = hy_compile(tree) + return _ast def import_file_to_module(name, fpath): - ast = import_file_to_ast(fpath) + _ast = import_file_to_ast(fpath) mod = imp.new_module(name) mod.__file__ = fpath - eval(compile(ast, fpath, "exec"), mod.__dict__) + eval(compile(_ast, fpath, "exec"), mod.__dict__) return mod diff --git a/tests/native_tests/language.hy b/tests/native_tests/language.hy index c835605..4a62524 100644 --- a/tests/native_tests/language.hy +++ b/tests/native_tests/language.hy @@ -511,6 +511,19 @@ ((fn [] 1)))))) +(defn test-eval [] + "NATIVE: test eval" + (import-from hy.importer hy-eval) ; XXX: Fix this!!!!! + (import-from hy HyExpression HyInteger HySymbol) + (assert (= 2 (eval (quote (+ 1 1))))) + (setf x 2) + (assert (= 4 (eval (quote (+ x 2))))) + (setf test-payload (quote (+ x 2))) + (setf x 4) + (assert (= 6 (eval test-payload)))) + + + ; FEATURE: native hy-eval ; ; - related to bug #64