Frickn' awesome.
This commit is contained in:
parent
c8937f8f07
commit
c55f501d2e
@ -1,5 +1,5 @@
|
||||
import imp
|
||||
from hy.lex.tokenize import tokenize
|
||||
import imp
|
||||
|
||||
|
||||
def _add_native_methods(mod):
|
||||
@ -35,12 +35,13 @@ def _add_native_methods(mod):
|
||||
ret /= x
|
||||
return ret
|
||||
|
||||
|
||||
natives = {
|
||||
"print": _print,
|
||||
"+": _plus,
|
||||
"-": _subtract,
|
||||
"*": _mult,
|
||||
"/": _divide
|
||||
"/": _divide,
|
||||
}
|
||||
|
||||
for native in natives:
|
||||
|
@ -23,7 +23,19 @@ def _fn(obj):
|
||||
return _
|
||||
|
||||
|
||||
def _import(obj):
|
||||
ns = obj.namespace
|
||||
fd = obj.get_invocation()
|
||||
args = fd['args']
|
||||
mods = args[0]
|
||||
|
||||
for module in mods:
|
||||
mod = __import__(module)
|
||||
obj.namespace[module] = mod
|
||||
|
||||
|
||||
builtins = {
|
||||
"def": _define,
|
||||
"fn": _fn,
|
||||
"import": _import
|
||||
}
|
||||
|
@ -35,4 +35,4 @@ class HYExpression(list, HYObject):
|
||||
for child in self.get_children():
|
||||
things.append(child())
|
||||
|
||||
return self.namespace[fn](*things)
|
||||
return self.lookup(fn)(*things)
|
||||
|
@ -12,3 +12,19 @@ class HYObject(object):
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
return self.eval(*args, **kwargs)
|
||||
|
||||
def lookup(self, fn):
|
||||
callee = None
|
||||
|
||||
if fn in self.namespace:
|
||||
callee = self.namespace[fn]
|
||||
|
||||
if "." in fn:
|
||||
lon, short = fn.rsplit(".", 1)
|
||||
holder = self.lookup(lon)
|
||||
callee = getattr(holder, short)
|
||||
|
||||
if callee:
|
||||
return callee
|
||||
|
||||
raise Exception
|
||||
|
@ -8,4 +8,4 @@ class HYSymbol(unicode, HYObject):
|
||||
def eval(self, *args, **kwargs):
|
||||
if self.isdigit():
|
||||
return float(self)
|
||||
return self.namespace[self]
|
||||
return self.lookup(self)
|
||||
|
Loading…
Reference in New Issue
Block a user