diff --git a/scripts/code.py b/scripts/code.py index bb91e87a..f4d8f48c 100755 --- a/scripts/code.py +++ b/scripts/code.py @@ -48,7 +48,8 @@ class RInt(co.namedtuple('RInt', 'x')): x = -mt.inf else: raise - assert isinstance(x, int) or mt.isinf(x), x + if not (isinstance(x, int) or mt.isinf(x)): + x = int(x) return super().__new__(cls, x) def __str__(self): @@ -59,6 +60,9 @@ class RInt(co.namedtuple('RInt', 'x')): else: return str(self.x) + def __bool__(self): + return bool(self.x) + def __int__(self): assert not mt.isinf(self.x) return self.x @@ -97,6 +101,15 @@ class RInt(co.namedtuple('RInt', 'x')): else: return (new-old) / old + def __pos__(self): + return self.__class__(+self.x) + + def __neg__(self): + return self.__class__(-self.x) + + def __abs__(self): + return self.__class__(abs(self.x)) + def __add__(self, other): return self.__class__(self.x + other.x) @@ -106,6 +119,12 @@ class RInt(co.namedtuple('RInt', 'x')): def __mul__(self, other): return self.__class__(self.x * other.x) + def __div__(self, other): + return self.__class__(self.x // other.x) + + def __mod__(self, other): + return self.__class__(self.x % other.x) + # code size results class CodeResult(co.namedtuple('CodeResult', [ 'file', 'function', diff --git a/scripts/cov.py b/scripts/cov.py index 9344b420..d3f8f756 100755 --- a/scripts/cov.py +++ b/scripts/cov.py @@ -49,7 +49,8 @@ class RInt(co.namedtuple('RInt', 'x')): x = -mt.inf else: raise - assert isinstance(x, int) or mt.isinf(x), x + if not (isinstance(x, int) or mt.isinf(x)): + x = int(x) return super().__new__(cls, x) def __str__(self): @@ -60,6 +61,9 @@ class RInt(co.namedtuple('RInt', 'x')): else: return str(self.x) + def __bool__(self): + return bool(self.x) + def __int__(self): assert not mt.isinf(self.x) return self.x @@ -98,6 +102,15 @@ class RInt(co.namedtuple('RInt', 'x')): else: return (new-old) / old + def __pos__(self): + return self.__class__(+self.x) + + def __neg__(self): + return self.__class__(-self.x) + + def __abs__(self): + return self.__class__(abs(self.x)) + def __add__(self, other): return self.__class__(self.x + other.x) @@ -107,6 +120,12 @@ class RInt(co.namedtuple('RInt', 'x')): def __mul__(self, other): return self.__class__(self.x * other.x) + def __div__(self, other): + return self.__class__(self.x // other.x) + + def __mod__(self, other): + return self.__class__(self.x % other.x) + # fractional fields, a/b class RFrac(co.namedtuple('RFrac', 'a,b')): __slots__ = () @@ -122,6 +141,12 @@ class RFrac(co.namedtuple('RFrac', 'a,b')): def __str__(self): return '%s/%s' % (self.a, self.b) + def __bool__(self): + return bool(self.a) + + def __int__(self): + return int(self.a) + def __float__(self): return float(self.a) @@ -149,6 +174,15 @@ class RFrac(co.namedtuple('RFrac', 'a,b')): old = old_a.x/old_b.x if old_b.x else 1.0 return new - old + def __pos__(self): + return self.__class__(+self.a, +self.b) + + def __neg__(self): + return self.__class__(-self.a, -self.b) + + def __abs__(self): + return self.__class__(abs(self.a), abs(self.b)) + def __add__(self, other): return self.__class__(self.a + other.a, self.b + other.b) @@ -156,7 +190,13 @@ class RFrac(co.namedtuple('RFrac', 'a,b')): return self.__class__(self.a - other.a, self.b - other.b) def __mul__(self, other): - return self.__class__(self.a * other.a, self.b + other.b) + return self.__class__(self.a * other.a, self.b * other.b) + + def __div__(self, other): + return self.__class__(self.a // other.a, self.b // other.b) + + def __mod__(self, other): + return self.__class__(self.a % other.a, self.b % other.b) def __eq__(self, other): self_a, self_b = self if self.b.x else (RInt(1), RInt(1)) diff --git a/scripts/data.py b/scripts/data.py index 58b561aa..dc830da4 100755 --- a/scripts/data.py +++ b/scripts/data.py @@ -48,7 +48,8 @@ class RInt(co.namedtuple('RInt', 'x')): x = -mt.inf else: raise - assert isinstance(x, int) or mt.isinf(x), x + if not (isinstance(x, int) or mt.isinf(x)): + x = int(x) return super().__new__(cls, x) def __str__(self): @@ -59,6 +60,9 @@ class RInt(co.namedtuple('RInt', 'x')): else: return str(self.x) + def __bool__(self): + return bool(self.x) + def __int__(self): assert not mt.isinf(self.x) return self.x @@ -97,6 +101,15 @@ class RInt(co.namedtuple('RInt', 'x')): else: return (new-old) / old + def __pos__(self): + return self.__class__(+self.x) + + def __neg__(self): + return self.__class__(-self.x) + + def __abs__(self): + return self.__class__(abs(self.x)) + def __add__(self, other): return self.__class__(self.x + other.x) @@ -106,6 +119,12 @@ class RInt(co.namedtuple('RInt', 'x')): def __mul__(self, other): return self.__class__(self.x * other.x) + def __div__(self, other): + return self.__class__(self.x // other.x) + + def __mod__(self, other): + return self.__class__(self.x % other.x) + # data size results class DataResult(co.namedtuple('DataResult', [ 'file', 'function', diff --git a/scripts/perf.py b/scripts/perf.py index 9ddf5eb6..1038464f 100755 --- a/scripts/perf.py +++ b/scripts/perf.py @@ -57,7 +57,8 @@ class RInt(co.namedtuple('RInt', 'x')): x = -mt.inf else: raise - assert isinstance(x, int) or mt.isinf(x), x + if not (isinstance(x, int) or mt.isinf(x)): + x = int(x) return super().__new__(cls, x) def __str__(self): @@ -68,6 +69,9 @@ class RInt(co.namedtuple('RInt', 'x')): else: return str(self.x) + def __bool__(self): + return bool(self.x) + def __int__(self): assert not mt.isinf(self.x) return self.x @@ -106,6 +110,15 @@ class RInt(co.namedtuple('RInt', 'x')): else: return (new-old) / old + def __pos__(self): + return self.__class__(+self.x) + + def __neg__(self): + return self.__class__(-self.x) + + def __abs__(self): + return self.__class__(abs(self.x)) + def __add__(self, other): return self.__class__(self.x + other.x) @@ -115,6 +128,12 @@ class RInt(co.namedtuple('RInt', 'x')): def __mul__(self, other): return self.__class__(self.x * other.x) + def __div__(self, other): + return self.__class__(self.x // other.x) + + def __mod__(self, other): + return self.__class__(self.x % other.x) + # perf results class PerfResult(co.namedtuple('PerfResult', [ 'file', 'function', 'line', diff --git a/scripts/perfbd.py b/scripts/perfbd.py index f0c5dad9..4a5baf61 100755 --- a/scripts/perfbd.py +++ b/scripts/perfbd.py @@ -48,7 +48,8 @@ class RInt(co.namedtuple('RInt', 'x')): x = -mt.inf else: raise - assert isinstance(x, int) or mt.isinf(x), x + if not (isinstance(x, int) or mt.isinf(x)): + x = int(x) return super().__new__(cls, x) def __str__(self): @@ -59,6 +60,9 @@ class RInt(co.namedtuple('RInt', 'x')): else: return str(self.x) + def __bool__(self): + return bool(self.x) + def __int__(self): assert not mt.isinf(self.x) return self.x @@ -97,6 +101,15 @@ class RInt(co.namedtuple('RInt', 'x')): else: return (new-old) / old + def __pos__(self): + return self.__class__(+self.x) + + def __neg__(self): + return self.__class__(-self.x) + + def __abs__(self): + return self.__class__(abs(self.x)) + def __add__(self, other): return self.__class__(self.x + other.x) @@ -106,6 +119,12 @@ class RInt(co.namedtuple('RInt', 'x')): def __mul__(self, other): return self.__class__(self.x * other.x) + def __div__(self, other): + return self.__class__(self.x // other.x) + + def __mod__(self, other): + return self.__class__(self.x % other.x) + # perf results class PerfBdResult(co.namedtuple('PerfBdResult', [ 'file', 'function', 'line', diff --git a/scripts/stack.py b/scripts/stack.py index 8d2b6341..58fc8b0b 100755 --- a/scripts/stack.py +++ b/scripts/stack.py @@ -38,7 +38,8 @@ class RInt(co.namedtuple('RInt', 'x')): x = -mt.inf else: raise - assert isinstance(x, int) or mt.isinf(x), x + if not (isinstance(x, int) or mt.isinf(x)): + x = int(x) return super().__new__(cls, x) def __str__(self): @@ -49,6 +50,9 @@ class RInt(co.namedtuple('RInt', 'x')): else: return str(self.x) + def __bool__(self): + return bool(self.x) + def __int__(self): assert not mt.isinf(self.x) return self.x @@ -87,6 +91,15 @@ class RInt(co.namedtuple('RInt', 'x')): else: return (new-old) / old + def __pos__(self): + return self.__class__(+self.x) + + def __neg__(self): + return self.__class__(-self.x) + + def __abs__(self): + return self.__class__(abs(self.x)) + def __add__(self, other): return self.__class__(self.x + other.x) @@ -96,6 +109,12 @@ class RInt(co.namedtuple('RInt', 'x')): def __mul__(self, other): return self.__class__(self.x * other.x) + def __div__(self, other): + return self.__class__(self.x // other.x) + + def __mod__(self, other): + return self.__class__(self.x % other.x) + # size results class StackResult(co.namedtuple('StackResult', [ 'file', 'function', 'frame', 'limit', 'children'])): diff --git a/scripts/structs.py b/scripts/structs.py index 9a33712a..c290fa6e 100755 --- a/scripts/structs.py +++ b/scripts/structs.py @@ -43,7 +43,8 @@ class RInt(co.namedtuple('RInt', 'x')): x = -mt.inf else: raise - assert isinstance(x, int) or mt.isinf(x), x + if not (isinstance(x, int) or mt.isinf(x)): + x = int(x) return super().__new__(cls, x) def __str__(self): @@ -54,6 +55,9 @@ class RInt(co.namedtuple('RInt', 'x')): else: return str(self.x) + def __bool__(self): + return bool(self.x) + def __int__(self): assert not mt.isinf(self.x) return self.x @@ -92,6 +96,15 @@ class RInt(co.namedtuple('RInt', 'x')): else: return (new-old) / old + def __pos__(self): + return self.__class__(+self.x) + + def __neg__(self): + return self.__class__(-self.x) + + def __abs__(self): + return self.__class__(abs(self.x)) + def __add__(self, other): return self.__class__(self.x + other.x) @@ -101,6 +114,12 @@ class RInt(co.namedtuple('RInt', 'x')): def __mul__(self, other): return self.__class__(self.x * other.x) + def __div__(self, other): + return self.__class__(self.x // other.x) + + def __mod__(self, other): + return self.__class__(self.x % other.x) + # struct size results class StructResult(co.namedtuple('StructResult', [ 'file', 'struct',