nitg: add support for unary - as an extern method
authorAlexis Laferrière <alexis.laf@xymus.net>
Tue, 10 Jun 2014 15:06:03 +0000 (11:06 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Tue, 10 Jun 2014 15:06:15 +0000 (11:06 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

src/nitni/nitni_base.nit
tests/sav/test_ffi_c_operators.res
tests/test_ffi_c_operators.nit

index 391a2b0..dd2fe10 100644 (file)
@@ -30,6 +30,7 @@ redef class MMethod
 
                if nit_name == "+" then return "_plus"
                if nit_name == "-" then return "_minus"
+               if nit_name == "unary -" then return "_unary_minus"
                if nit_name == "*" then return "_star"
                if nit_name == "/" then return "_slash"
                if nit_name == "%" then return "_percent"
index 3174cb7..ecc608f 100644 (file)
@@ -1,6 +1,6 @@
 # This file is part of NIT ( http://www.nitlanguage.org ).
 #
-# Copyright 2011-2013 Alexis Laferrière <alexis.laf@xymus.net>
+# Copyright 2011-2014 Alexis Laferrière <alexis.laf@xymus.net>
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -33,6 +33,11 @@ class A
                return new_A( s - o );
        `}
 
+       fun -: A import value, A `{
+               int s = A_value(recv);
+               return new_A(-s);
+       `}
+
        fun *( by : Int ) : A import value, A `{
                int s = A_value( recv );
 
@@ -158,3 +163,4 @@ print a[ 52 ] # 52
 a[ 74 ] = new A( 96 )
 print a # 96
 
+print(-(new A(123)))