diff --git a/hy/compiler/ast27.py b/hy/compiler/ast27.py new file mode 100644 index 0000000..cbdbbce --- /dev/null +++ b/hy/compiler/ast27.py @@ -0,0 +1,21 @@ +# output ast for cpython 2.7 + +from hy.lang.builtins import builtins +# check compiler/modfaker for other crap + +offset = 0 +def _new_fn_name(): + global offset + offset += 1 + return "_hy_fn_%s" % (offset) + +# body=[Print(dest=None, +# values=[BinOp(left=Num(n=1), op=Add(), right=Num(n=1))], +# nl=True)] +# body=[Expr(value=BinOp(left=Num(n=1), op=Add(), right=Num(n=1)))] + + + +def forge_ast(name, forest): + for tree in forest: + print tree diff --git a/hy/lang/builtins.py b/hy/lang/builtins.py index 6aa3cf1..f46a0a4 100644 --- a/hy/lang/builtins.py +++ b/hy/lang/builtins.py @@ -1,6 +1,7 @@ # import sys from hy.lang.internals import HYNamespaceCOW +from hy.lang.string import HYString def _define(obj, lns): @@ -17,10 +18,15 @@ def _loop(obj, lns): arg.eval(lns.clone()) -def _fn(obj, lns): +def _fn(obj, lns, name=None): fd = obj.get_invocation() args = fd['args'] sig = args[0] + + docstring = None + if isinstance(args[1], HYString): + docstring = args.pop(1) + meth = args[1] def _(*args, **kwargs): @@ -32,6 +38,12 @@ def _fn(obj, lns): ret = meth.eval(l, *args, **kwargs) return ret + + _.__name__ = "hyfn" + if name: + _.__name__ = name + + _.__doc__ = docstring return _ diff --git a/hy/lang/expression.py b/hy/lang/expression.py index 6a63981..fc4e0fa 100644 --- a/hy/lang/expression.py +++ b/hy/lang/expression.py @@ -18,7 +18,7 @@ class HYExpression(HYObject, list): return { "function": fn, - "args": args + "args": args, } def peek(self):