Adding in s'more testing.
This commit is contained in:
parent
8994f4fbb9
commit
c8937f8f07
@ -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:
|
||||
|
11
hy/lang/importer.py
Normal file
11
hy/lang/importer.py
Normal 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
|
@ -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]
|
||||
|
6
test.hy
Normal file
6
test.hy
Normal 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
12
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])
|
||||
|
Loading…
Reference in New Issue
Block a user