Adding in more better voodoo.

This commit is contained in:
Paul Tagliamonte 2012-12-16 16:52:52 -05:00
parent f36fa0f6de
commit 8994f4fbb9
5 changed files with 21 additions and 10 deletions

View File

@ -23,6 +23,7 @@ def _add_native_methods(mod):
eval(shim.__code__, mod.__dict__)
def forge_module(name, fpath, forest):
mod = imp.new_module(name)
mod.__file__ = fpath

View File

@ -14,7 +14,11 @@ def _fn(obj):
meth = args[1]
def _(*args, **kwargs):
# meth validation
for i in range(0, len(sig)):
name = sig[i]
value = args[i]
obj.namespace[name] = value
return meth(*args, **kwargs)
return _

9
hy/lang/symbol.py Normal file
View File

@ -0,0 +1,9 @@
from hy.lang.hyobj import HYObject
class HYSymbol(unicode, HYObject):
def __init__(self, string):
self += string
def eval(self, *args, **kwargs):
return self.namespace[self]

View File

@ -1,6 +1,7 @@
from hy.lang.expression import HYExpression
from hy.lex.errors import LexException
from hy.lang.string import HYString
from hy.lang.symbol import HYSymbol
from hy.lex.machine import Machine
from hy.lang.list import HYList
@ -56,13 +57,13 @@ class Expression(State):
def exit(self):
if self.bulk:
self.nodes.append(HYString(self.bulk))
self.nodes.append(HYSymbol(self.bulk))
self.machine.nodes.append(self.nodes)
def commit(self):
if self.bulk.strip() != "":
self.nodes.append(HYString(self.bulk))
self.nodes.append(HYSymbol(self.bulk))
self.bulk = ""
def p(self, x):
@ -82,12 +83,12 @@ class List(State):
def exit(self):
if self.bulk:
self.nodes.append(HYString(self.bulk))
self.nodes.append(HYSymbol(self.bulk))
self.machine.nodes.append(self.nodes)
def commit(self):
if self.bulk.strip() != "":
self.nodes.append(HYString(self.bulk))
self.nodes.append(HYSymbol(self.bulk))
self.bulk = ""
def p(self, x):

View File

@ -5,10 +5,6 @@ from hy.lex.tokenize import tokenize
m = forge_module(
'test',
'test.hy',
tokenize('(def two (fn [] (print (+ 1 1))))(def x 1)')
tokenize('(def two (fn [x] (print x)))(two "Hello")')
)
print m.two
m.two()
print m.x