Implement unary minus
This commit is contained in:
parent
1bcce13e1d
commit
41a9ce28f0
@ -812,7 +812,6 @@ class HyASTCompiler(object):
|
|||||||
|
|
||||||
@builds("+")
|
@builds("+")
|
||||||
@builds("%")
|
@builds("%")
|
||||||
@builds("-")
|
|
||||||
@builds("/")
|
@builds("/")
|
||||||
@builds("//")
|
@builds("//")
|
||||||
@builds("*")
|
@builds("*")
|
||||||
@ -851,6 +850,18 @@ class HyASTCompiler(object):
|
|||||||
left = calc
|
left = calc
|
||||||
return 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("/=")
|
@builds("/=")
|
||||||
@builds("//=")
|
@builds("//=")
|
||||||
|
@ -17,7 +17,8 @@
|
|||||||
|
|
||||||
(setv test_sub (fn []
|
(setv test_sub (fn []
|
||||||
"NATIVE: Test subtraction"
|
"NATIVE: Test subtraction"
|
||||||
(assert (= 4 (- 8 4)))))
|
(assert (= 4 (- 8 4)))
|
||||||
|
(assert (= -8 (- 8)))))
|
||||||
|
|
||||||
|
|
||||||
(setv test_add (fn []
|
(setv test_add (fn []
|
||||||
|
Loading…
x
Reference in New Issue
Block a user