blueloveTH 2 年 前
コミット
9625134e32
3 ファイル変更21 行追加7 行削除
  1. 7 7
      python/_long.py
  2. 2 0
      src/vm.h
  3. 12 0
      tests/09_long.py

+ 7 - 7
python/_long.py

@@ -175,15 +175,15 @@ class long:
         else:
             assert type(other) is long
         if self.sign == other.sign:
-            return long(ulong_add(self.digits, other.digits), self.sign)
+            return long((ulong_add(self.digits, other.digits), self.sign))
         else:
             cmp = ulong_cmp(self.digits, other.digits)
             if cmp == 0:
                 return long(0)
             if cmp > 0:
-                return long(ulong_sub(self.digits, other.digits), self.sign)
+                return long((ulong_sub(self.digits, other.digits), self.sign))
             else:
-                return long(ulong_sub(other.digits, self.digits), other.sign)
+                return long((ulong_sub(other.digits, self.digits), other.sign))
             
     def __radd__(self, other):
         return self.__add__(other)
@@ -194,15 +194,15 @@ class long:
         else:
             assert type(other) is long
         if self.sign != other.sign:
-            return long(ulong_add(self.digits, other.digits), self.sign)
+            return long((ulong_add(self.digits, other.digits), self.sign))
         else:
             cmp = ulong_cmp(self.digits, other.digits)
             if cmp == 0:
                 return long(0)
             if cmp > 0:
-                return long(ulong_sub(self.digits, other.digits), self.sign)
+                return long((ulong_sub(self.digits, other.digits), self.sign))
             else:
-                return long(ulong_sub(other.digits, self.digits), -other.sign)
+                return long((ulong_sub(other.digits, self.digits), -other.sign))
             
     def __rsub__(self, other):
         return self.__sub__(other)
@@ -270,7 +270,7 @@ class long:
         raise NotImplementedError
     
     def __neg__(self):
-        return long(self.digits, -self.sign)
+        return long((self.digits, -self.sign))
     
     def __cmp__(self, other):
         if type(other) is int:

+ 2 - 0
src/vm.h

@@ -114,6 +114,7 @@ public:
     PyObject* None;
     PyObject* True;
     PyObject* False;
+    PyObject* NotImplemented;   // unused
     PyObject* Ellipsis;
     PyObject* builtins;         // builtins module
     PyObject* StopIteration;
@@ -1125,6 +1126,7 @@ inline void VM::init_builtin_types(){
     tp_star_wrapper = _new_type_object("_star_wrapper");
 
     this->None = heap._new<Dummy>(_new_type_object("NoneType"), {});
+    this->NotImplemented = heap._new<Dummy>(_new_type_object("NotImplementedType"), {});
     this->Ellipsis = heap._new<Dummy>(_new_type_object("ellipsis"), {});
     this->True = heap._new<Dummy>(tp_bool, {});
     this->False = heap._new<Dummy>(tp_bool, {});

+ 12 - 0
tests/09_long.py

@@ -0,0 +1,12 @@
+assert long(123) == long('123') == 123
+
+a = long(2)
+assert a ** 0 == 1
+assert a ** 60 == 1152921504606846976
+
+assert a + 1 == 3
+assert a - 1 == 1
+assert a * 2 == 4
+assert a // 2 == 1
+
+assert -a == -2