adding in decorators
This commit is contained in:
parent
3dba5f7aff
commit
b1c3a758f9
@ -169,6 +169,15 @@ class HyASTCompiler(object):
|
||||
slice=ast.Index(value=sli),
|
||||
ctx=ast.Load())
|
||||
|
||||
@builds("decorate_with")
|
||||
def compile_decorate_expression(self, expr):
|
||||
expr.pop(0) # decorate-with
|
||||
fn = self.compile(expr.pop(-1))
|
||||
if type(fn) != ast.FunctionDef:
|
||||
raise TypeError("Decorated a non-function")
|
||||
fn.decorator_list = [self.compile(x) for x in expr]
|
||||
return fn
|
||||
|
||||
@builds("=")
|
||||
@builds("!=")
|
||||
@builds("<")
|
||||
@ -180,16 +189,11 @@ class HyASTCompiler(object):
|
||||
@builds("is_not")
|
||||
@builds("not_in")
|
||||
def compile_compare_op_expression(self, expression):
|
||||
ops = {"=": ast.Eq,
|
||||
"!=": ast.NotEq,
|
||||
"<": ast.Lt,
|
||||
"<=": ast.LtE,
|
||||
">": ast.Gt,
|
||||
">=": ast.GtE,
|
||||
"is": ast.Is,
|
||||
"is_not": ast.IsNot,
|
||||
"in": ast.In,
|
||||
"not_in": ast.NotIn}
|
||||
ops = {"=": ast.Eq, "!=": ast.NotEq,
|
||||
"<": ast.Lt, "<=": ast.LtE,
|
||||
">": ast.Gt, ">=": ast.GtE,
|
||||
"is": ast.Is, "is_not": ast.IsNot,
|
||||
"in": ast.In, "not_in": ast.NotIn}
|
||||
|
||||
inv = expression.pop(0)
|
||||
op = ops[inv]
|
||||
|
@ -1,5 +1,6 @@
|
||||
#
|
||||
|
||||
|
||||
import hy
|
||||
from .native_tests.math import *
|
||||
from .native_tests.language import *
|
||||
|
@ -1,5 +1,6 @@
|
||||
;
|
||||
|
||||
|
||||
(import sys)
|
||||
(import-from os.path exists isdir isfile)
|
||||
|
||||
@ -8,6 +9,7 @@
|
||||
"NATIVE: test sys.argv"
|
||||
(assert (isinstance sys.argv list)))
|
||||
|
||||
|
||||
(defn test-lists []
|
||||
"NATIVE: test lists work right"
|
||||
(assert (= [1 2 3 4] (+ [1 2] [3 4]))))
|
||||
@ -88,3 +90,16 @@
|
||||
(assert (is (exists ".") true))
|
||||
(assert (is (isdir ".") true))
|
||||
(assert (is (isfile ".") false)))
|
||||
|
||||
|
||||
(defn foodec [func]
|
||||
(lambda [] (+ 1 1)))
|
||||
|
||||
|
||||
(decorate-with foodec
|
||||
(defn tfunction []
|
||||
(* 2 2)))
|
||||
|
||||
|
||||
(defn test-decorators []
|
||||
(assert (= (tfunction) 2)))
|
||||
|
Loading…
x
Reference in New Issue
Block a user