Adding in eval

This commit is contained in:
Paul Tagliamonte 2012-12-18 22:29:52 -05:00
parent 8bc58b0c50
commit deb0f5820b

View File

@ -6,8 +6,27 @@ import imp
def _add_native_methods(mod): def _add_native_methods(mod):
def shim(): def shim():
from hy.lang.bool import HYBool from hy.lang.bool import HYBool
from hy.lex.tokenize import tokenize as _hy_tok
import sys
def _print(*args, **kwargs): 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): def _plus(*args):
@ -92,6 +111,7 @@ def _add_native_methods(mod):
natives = { natives = {
"print": _print,
"puts": _print, "puts": _print,
"+": _plus, "+": _plus,
"-": _subtract, "-": _subtract,
@ -102,7 +122,9 @@ def _add_native_methods(mod):
">=": _ge, ">=": _ge,
"<": _lt, "<": _lt,
"<=": _le, "<=": _le,
"!=": _ne "!=": _ne,
"eval": _eval,
"lex": _lex
} }
for native in natives: for native in natives: