Implement unary minus

This commit is contained in:
Konrad Hinsen 2013-04-16 17:43:40 +02:00
parent 1bcce13e1d
commit 41a9ce28f0
2 changed files with 14 additions and 2 deletions

View File

@ -812,7 +812,6 @@ class HyASTCompiler(object):
@builds("+")
@builds("%")
@builds("-")
@builds("/")
@builds("//")
@builds("*")
@ -851,6 +850,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 []