moving to locals; fixing _ast vs ast, adding tests
This commit is contained in:
parent
73be6afd3a
commit
8cc26ba1bf
@ -197,8 +197,8 @@ class HyASTCompiler(object):
|
|||||||
def compile_eval(self, expr):
|
def compile_eval(self, expr):
|
||||||
expr.pop(0)
|
expr.pop(0)
|
||||||
return self.compile(HyExpression([
|
return self.compile(HyExpression([
|
||||||
HySymbol("hy_eval")] + expr + [HyExpression([HySymbol("globals")])
|
HySymbol("hy_eval")] + expr + [
|
||||||
]).replace(expr))
|
HyExpression([HySymbol("locals")])]).replace(expr))
|
||||||
|
|
||||||
@builds("do")
|
@builds("do")
|
||||||
@builds("progn")
|
@builds("progn")
|
||||||
|
@ -51,21 +51,21 @@ def import_file_to_hst(fpath):
|
|||||||
|
|
||||||
def import_file_to_ast(fpath):
|
def import_file_to_ast(fpath):
|
||||||
tree = import_file_to_hst(fpath)
|
tree = import_file_to_hst(fpath)
|
||||||
ast = hy_compile(tree)
|
_ast = hy_compile(tree)
|
||||||
return ast
|
return _ast
|
||||||
|
|
||||||
|
|
||||||
def import_string_to_ast(buff):
|
def import_string_to_ast(buff):
|
||||||
tree = import_buffer_to_hst(StringIO(buff))
|
tree = import_buffer_to_hst(StringIO(buff))
|
||||||
ast = hy_compile(tree)
|
_ast = hy_compile(tree)
|
||||||
return ast
|
return _ast
|
||||||
|
|
||||||
|
|
||||||
def import_file_to_module(name, fpath):
|
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 = imp.new_module(name)
|
||||||
mod.__file__ = fpath
|
mod.__file__ = fpath
|
||||||
eval(compile(ast, fpath, "exec"), mod.__dict__)
|
eval(compile(_ast, fpath, "exec"), mod.__dict__)
|
||||||
return mod
|
return mod
|
||||||
|
|
||||||
|
|
||||||
|
@ -511,6 +511,19 @@
|
|||||||
((fn [] 1))))))
|
((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
|
; FEATURE: native hy-eval
|
||||||
;
|
;
|
||||||
; - related to bug #64
|
; - related to bug #64
|
||||||
|
Loading…
Reference in New Issue
Block a user