Adding in s'more testing.

This commit is contained in:
Paul Tagliamonte 2012-12-16 17:14:31 -05:00
parent 8994f4fbb9
commit c8937f8f07
5 changed files with 49 additions and 11 deletions

View File

@ -7,15 +7,40 @@ def _add_native_methods(mod):
def _print(*args, **kwargs): def _print(*args, **kwargs):
print " ".join([str(x) for x in args]) print " ".join([str(x) for x in args])
def _plus(*args): def _plus(*args):
ret = 0 ret = 0
for x in args: 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 return ret
natives = { natives = {
"print": _print, "print": _print,
"+": _plus "+": _plus,
"-": _subtract,
"*": _mult,
"/": _divide
} }
for native in natives: for native in natives:

11
hy/lang/importer.py Normal file
View File

@ -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

View File

@ -6,4 +6,6 @@ class HYSymbol(unicode, HYObject):
self += string self += string
def eval(self, *args, **kwargs): def eval(self, *args, **kwargs):
if self.isdigit():
return float(self)
return self.namespace[self] return self.namespace[self]

6
test.hy Normal file
View File

@ -0,0 +1,6 @@
; vim: tabstop=2 expandtab shiftwidth=2 softtabstop=2 filetype=lisp
(def square (fn [x]
(* x x)))
(print (square 2))

12
test.py
View File

@ -1,10 +1,4 @@
from hy.compiler.modfaker import forge_module from hy.lang.importer import _hy_import_file
from hy.lex.tokenize import tokenize import sys
m = forge_module(
'test',
'test.hy',
tokenize('(def two (fn [x] (print x)))(two "Hello")')
)
mod = _hy_import_file('test', sys.argv[1])