From deb0f5820b7d187fe3debf601c7a7308a62d3e58 Mon Sep 17 00:00:00 2001 From: Paul Tagliamonte Date: Tue, 18 Dec 2012 22:29:52 -0500 Subject: [PATCH] Adding in eval --- hy/compiler/modfaker.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/hy/compiler/modfaker.py b/hy/compiler/modfaker.py index 74e7fb6..dcbe72a 100644 --- a/hy/compiler/modfaker.py +++ b/hy/compiler/modfaker.py @@ -6,8 +6,27 @@ import imp def _add_native_methods(mod): def shim(): from hy.lang.bool import HYBool + from hy.lex.tokenize import tokenize as _hy_tok + import sys + + def _print(*args, **kwargs): - print(" ".join([str(x) for x in args])) + sys.stdout.write(" ".join([str(x) for x in args]) + "\n") + sys.stdout.flush() + + + def _lex(*args): + ret = [] + for thing in args: + ret.append(_hy_tok(thing)) + return ret + + + def _eval(*args): + for node in _lex(*args): + for tree in node: + tree.set_namespace(globals()) + tree() def _plus(*args): @@ -92,6 +111,7 @@ def _add_native_methods(mod): natives = { + "print": _print, "puts": _print, "+": _plus, "-": _subtract, @@ -102,7 +122,9 @@ def _add_native_methods(mod): ">=": _ge, "<": _lt, "<=": _le, - "!=": _ne + "!=": _ne, + "eval": _eval, + "lex": _lex } for native in natives: