From c8937f8f07e039611ef3d505567eb7d4f1e94f52 Mon Sep 17 00:00:00 2001 From: Paul Tagliamonte Date: Sun, 16 Dec 2012 17:14:31 -0500 Subject: [PATCH] Adding in s'more testing. --- hy/compiler/modfaker.py | 29 +++++++++++++++++++++++++++-- hy/lang/importer.py | 11 +++++++++++ hy/lang/symbol.py | 2 ++ test.hy | 6 ++++++ test.py | 12 +++--------- 5 files changed, 49 insertions(+), 11 deletions(-) create mode 100644 hy/lang/importer.py create mode 100644 test.hy diff --git a/hy/compiler/modfaker.py b/hy/compiler/modfaker.py index ce03946..cdbed9f 100644 --- a/hy/compiler/modfaker.py +++ b/hy/compiler/modfaker.py @@ -7,15 +7,40 @@ def _add_native_methods(mod): def _print(*args, **kwargs): print " ".join([str(x) for x in args]) + def _plus(*args): ret = 0 for x in args: - ret += int(x) + ret += x + return ret + + + def _subtract(*args): + ret = 0 + for x in args: + ret -= x + return ret + + + def _mult(*args): + ret = 1 + for x in args: + ret *= x + return ret + + + def _divide(*args): + ret = 1 + for x in args: + ret /= x return ret natives = { "print": _print, - "+": _plus + "+": _plus, + "-": _subtract, + "*": _mult, + "/": _divide } for native in natives: diff --git a/hy/lang/importer.py b/hy/lang/importer.py new file mode 100644 index 0000000..bd0642e --- /dev/null +++ b/hy/lang/importer.py @@ -0,0 +1,11 @@ +from hy.compiler.modfaker import forge_module +from hy.lex.tokenize import tokenize + + +def _hy_import_file(name, fd): + m = forge_module( + name, + fd, + tokenize(open(fd, 'r').read()) + ) + return m diff --git a/hy/lang/symbol.py b/hy/lang/symbol.py index 952b986..ccb8d14 100644 --- a/hy/lang/symbol.py +++ b/hy/lang/symbol.py @@ -6,4 +6,6 @@ class HYSymbol(unicode, HYObject): self += string def eval(self, *args, **kwargs): + if self.isdigit(): + return float(self) return self.namespace[self] diff --git a/test.hy b/test.hy new file mode 100644 index 0000000..7a5ef01 --- /dev/null +++ b/test.hy @@ -0,0 +1,6 @@ +; vim: tabstop=2 expandtab shiftwidth=2 softtabstop=2 filetype=lisp + +(def square (fn [x] + (* x x))) + +(print (square 2)) diff --git a/test.py b/test.py index ea68234..c77f926 100644 --- a/test.py +++ b/test.py @@ -1,10 +1,4 @@ -from hy.compiler.modfaker import forge_module -from hy.lex.tokenize import tokenize - - -m = forge_module( - 'test', - 'test.hy', - tokenize('(def two (fn [x] (print x)))(two "Hello")') -) +from hy.lang.importer import _hy_import_file +import sys +mod = _hy_import_file('test', sys.argv[1])