Merge branch 'unary_minus' of github.com:khinsen/hy

This commit is contained in:
Paul R. Tagliamonte 2013-04-16 23:07:32 -04:00
commit 3f362bc318
2 changed files with 14 additions and 2 deletions

View File

@ -809,7 +809,6 @@ class HyASTCompiler(object):
@builds("+")
@builds("%")
@builds("-")
@builds("/")
@builds("//")
@builds("*")
@ -848,6 +847,18 @@ class HyASTCompiler(object):
left = calc
return calc
@builds("-")
@checkargs(min=1)
def compile_maths_expression_sub(self, expression):
if len(expression) > 2:
return self.compile_maths_expression(expression)
else:
arg = expression[1]
return ast.UnaryOp(op=ast.USub(),
operand=self.compile(arg),
lineno=arg.start_line,
col_offset=arg.start_column)
@builds("+=")
@builds("/=")
@builds("//=")

View File

@ -17,7 +17,8 @@
(setv test_sub (fn []
"NATIVE: Test subtraction"
(assert (= 4 (- 8 4)))))
(assert (= 4 (- 8 4)))
(assert (= -8 (- 8)))))
(setv test_add (fn []