scripts: Prefer .a for single entry namedtuples

- CsvInt.x -> CsvInt.a
- CsvFloat.x -> CsvFloat.a
- Rev.x -> Rev.a

This matches CsvFrac.a (paired with CsvFrac.b), and avoids confusion
with x/y variables such as Tile.x and Tile.y.

The other contender was .v, since these are cs*v* related types, but
sticking with .a gets the point across that the name really doesn't have
any meaning.

There's also some irony that we're forcing namedtuples to have
meaningless names, but it is useful to have a quick accessor for the
internal value.
This commit is contained in:
Christopher Haster
2025-04-12 01:40:16 -05:00
parent 98b16a9013
commit c63ed79c5f
9 changed files with 396 additions and 396 deletions
+38 -38
View File
@@ -34,54 +34,54 @@ SECTIONS = ['.text', '.rodata', '.data']
# integer fields # integer fields
class CsvInt(co.namedtuple('CsvInt', 'x')): class CsvInt(co.namedtuple('CsvInt', 'a')):
__slots__ = () __slots__ = ()
def __new__(cls, x=0): def __new__(cls, a=0):
if isinstance(x, CsvInt): if isinstance(a, CsvInt):
return x return a
if isinstance(x, str): if isinstance(a, str):
try: try:
x = int(x, 0) a = int(a, 0)
except ValueError: except ValueError:
# also accept +-∞ and +-inf # also accept +-∞ and +-inf
if re.match('^\s*\+?\s*(?:∞|inf)\s*$', x): if re.match('^\s*\+?\s*(?:∞|inf)\s*$', a):
x = mt.inf a = mt.inf
elif re.match('^\s*-\s*(?:∞|inf)\s*$', x): elif re.match('^\s*-\s*(?:∞|inf)\s*$', a):
x = -mt.inf a = -mt.inf
else: else:
raise raise
if not (isinstance(x, int) or mt.isinf(x)): if not (isinstance(a, int) or mt.isinf(a)):
x = int(x) a = int(a)
return super().__new__(cls, x) return super().__new__(cls, a)
def __repr__(self): def __repr__(self):
return '%s(%r)' % (self.__class__.__name__, self.x) return '%s(%r)' % (self.__class__.__name__, self.a)
def __str__(self): def __str__(self):
if self.x == mt.inf: if self.a == mt.inf:
return '' return ''
elif self.x == -mt.inf: elif self.a == -mt.inf:
return '-∞' return '-∞'
else: else:
return str(self.x) return str(self.a)
def __bool__(self): def __bool__(self):
return bool(self.x) return bool(self.a)
def __int__(self): def __int__(self):
assert not mt.isinf(self.x) assert not mt.isinf(self.a)
return self.x return self.a
def __float__(self): def __float__(self):
return float(self.x) return float(self.a)
none = '%7s' % '-' none = '%7s' % '-'
def table(self): def table(self):
return '%7s' % (self,) return '%7s' % (self,)
def diff(self, other): def diff(self, other):
new = self.x if self else 0 new = self.a if self else 0
old = other.x if other else 0 old = other.a if other else 0
diff = new - old diff = new - old
if diff == +mt.inf: if diff == +mt.inf:
return '%7s' % '+∞' return '%7s' % '+∞'
@@ -91,8 +91,8 @@ class CsvInt(co.namedtuple('CsvInt', 'x')):
return '%+7d' % diff return '%+7d' % diff
def ratio(self, other): def ratio(self, other):
new = self.x if self else 0 new = self.a if self else 0
old = other.x if other else 0 old = other.a if other else 0
if mt.isinf(new) and mt.isinf(old): if mt.isinf(new) and mt.isinf(old):
return 0.0 return 0.0
elif mt.isinf(new): elif mt.isinf(new):
@@ -107,22 +107,22 @@ class CsvInt(co.namedtuple('CsvInt', 'x')):
return (new-old) / old return (new-old) / old
def __pos__(self): def __pos__(self):
return self.__class__(+self.x) return self.__class__(+self.a)
def __neg__(self): def __neg__(self):
return self.__class__(-self.x) return self.__class__(-self.a)
def __abs__(self): def __abs__(self):
return self.__class__(abs(self.x)) return self.__class__(abs(self.a))
def __add__(self, other): def __add__(self, other):
return self.__class__(self.x + other.x) return self.__class__(self.a + other.a)
def __sub__(self, other): def __sub__(self, other):
return self.__class__(self.x - other.x) return self.__class__(self.a - other.a)
def __mul__(self, other): def __mul__(self, other):
return self.__class__(self.x * other.x) return self.__class__(self.a * other.a)
def __truediv__(self, other): def __truediv__(self, other):
if not other: if not other:
@@ -130,10 +130,10 @@ class CsvInt(co.namedtuple('CsvInt', 'x')):
return self.__class__(+mt.inf) return self.__class__(+mt.inf)
else: else:
return self.__class__(-mt.inf) return self.__class__(-mt.inf)
return self.__class__(self.x // other.x) return self.__class__(self.a // other.a)
def __mod__(self, other): def __mod__(self, other):
return self.__class__(self.x % other.x) return self.__class__(self.a % other.a)
# code size results # code size results
class CodeResult(co.namedtuple('CodeResult', [ class CodeResult(co.namedtuple('CodeResult', [
@@ -507,17 +507,17 @@ def collect_code(obj_paths, *,
# common folding/tabling/read/write code # common folding/tabling/read/write code
class Rev(co.namedtuple('Rev', 'x')): class Rev(co.namedtuple('Rev', 'a')):
__slots__ = () __slots__ = ()
# yes we need all of these because we're a namedtuple # yes we need all of these because we're a namedtuple
def __lt__(self, other): def __lt__(self, other):
return self.x > other.x return self.a > other.a
def __gt__(self, other): def __gt__(self, other):
return self.x < other.x return self.a < other.a
def __le__(self, other): def __le__(self, other):
return self.x >= other.x return self.a >= other.a
def __ge__(self, other): def __ge__(self, other):
return self.x <= other.x return self.a <= other.a
def fold(Result, results, *, def fold(Result, results, *,
by=None, by=None,
+49 -49
View File
@@ -36,54 +36,54 @@ GCOV_PATH = ['gcov']
# integer fields # integer fields
class CsvInt(co.namedtuple('CsvInt', 'x')): class CsvInt(co.namedtuple('CsvInt', 'a')):
__slots__ = () __slots__ = ()
def __new__(cls, x=0): def __new__(cls, a=0):
if isinstance(x, CsvInt): if isinstance(a, CsvInt):
return x return a
if isinstance(x, str): if isinstance(a, str):
try: try:
x = int(x, 0) a = int(a, 0)
except ValueError: except ValueError:
# also accept +-∞ and +-inf # also accept +-∞ and +-inf
if re.match('^\s*\+?\s*(?:∞|inf)\s*$', x): if re.match('^\s*\+?\s*(?:∞|inf)\s*$', a):
x = mt.inf a = mt.inf
elif re.match('^\s*-\s*(?:∞|inf)\s*$', x): elif re.match('^\s*-\s*(?:∞|inf)\s*$', a):
x = -mt.inf a = -mt.inf
else: else:
raise raise
if not (isinstance(x, int) or mt.isinf(x)): if not (isinstance(a, int) or mt.isinf(a)):
x = int(x) a = int(a)
return super().__new__(cls, x) return super().__new__(cls, a)
def __repr__(self): def __repr__(self):
return '%s(%r)' % (self.__class__.__name__, self.x) return '%s(%r)' % (self.__class__.__name__, self.a)
def __str__(self): def __str__(self):
if self.x == mt.inf: if self.a == mt.inf:
return '' return ''
elif self.x == -mt.inf: elif self.a == -mt.inf:
return '-∞' return '-∞'
else: else:
return str(self.x) return str(self.a)
def __bool__(self): def __bool__(self):
return bool(self.x) return bool(self.a)
def __int__(self): def __int__(self):
assert not mt.isinf(self.x) assert not mt.isinf(self.a)
return self.x return self.a
def __float__(self): def __float__(self):
return float(self.x) return float(self.a)
none = '%7s' % '-' none = '%7s' % '-'
def table(self): def table(self):
return '%7s' % (self,) return '%7s' % (self,)
def diff(self, other): def diff(self, other):
new = self.x if self else 0 new = self.a if self else 0
old = other.x if other else 0 old = other.a if other else 0
diff = new - old diff = new - old
if diff == +mt.inf: if diff == +mt.inf:
return '%7s' % '+∞' return '%7s' % '+∞'
@@ -93,8 +93,8 @@ class CsvInt(co.namedtuple('CsvInt', 'x')):
return '%+7d' % diff return '%+7d' % diff
def ratio(self, other): def ratio(self, other):
new = self.x if self else 0 new = self.a if self else 0
old = other.x if other else 0 old = other.a if other else 0
if mt.isinf(new) and mt.isinf(old): if mt.isinf(new) and mt.isinf(old):
return 0.0 return 0.0
elif mt.isinf(new): elif mt.isinf(new):
@@ -109,22 +109,22 @@ class CsvInt(co.namedtuple('CsvInt', 'x')):
return (new-old) / old return (new-old) / old
def __pos__(self): def __pos__(self):
return self.__class__(+self.x) return self.__class__(+self.a)
def __neg__(self): def __neg__(self):
return self.__class__(-self.x) return self.__class__(-self.a)
def __abs__(self): def __abs__(self):
return self.__class__(abs(self.x)) return self.__class__(abs(self.a))
def __add__(self, other): def __add__(self, other):
return self.__class__(self.x + other.x) return self.__class__(self.a + other.a)
def __sub__(self, other): def __sub__(self, other):
return self.__class__(self.x - other.x) return self.__class__(self.a - other.a)
def __mul__(self, other): def __mul__(self, other):
return self.__class__(self.x * other.x) return self.__class__(self.a * other.a)
def __truediv__(self, other): def __truediv__(self, other):
if not other: if not other:
@@ -132,10 +132,10 @@ class CsvInt(co.namedtuple('CsvInt', 'x')):
return self.__class__(+mt.inf) return self.__class__(+mt.inf)
else: else:
return self.__class__(-mt.inf) return self.__class__(-mt.inf)
return self.__class__(self.x // other.x) return self.__class__(self.a // other.a)
def __mod__(self, other): def __mod__(self, other):
return self.__class__(self.x % other.x) return self.__class__(self.a % other.a)
# fractional fields, a/b # fractional fields, a/b
class CsvFrac(co.namedtuple('CsvFrac', 'a,b')): class CsvFrac(co.namedtuple('CsvFrac', 'a,b')):
@@ -150,7 +150,7 @@ class CsvFrac(co.namedtuple('CsvFrac', 'a,b')):
return super().__new__(cls, CsvInt(a), CsvInt(b)) return super().__new__(cls, CsvInt(a), CsvInt(b))
def __repr__(self): def __repr__(self):
return '%s(%r, %r)' % (self.__class__.__name__, self.a.x, self.b.x) return '%s(%r, %r)' % (self.__class__.__name__, self.a.a, self.b.a)
def __str__(self): def __str__(self):
return '%s/%s' % (self.a, self.b) return '%s/%s' % (self.a, self.b)
@@ -169,12 +169,12 @@ class CsvFrac(co.namedtuple('CsvFrac', 'a,b')):
return '%11s' % (self,) return '%11s' % (self,)
def notes(self): def notes(self):
if self.b.x == 0 and self.a.x == 0: if self.b.a == 0 and self.a.a == 0:
t = 1.0 t = 1.0
elif self.b.x == 0: elif self.b.a == 0:
t = mt.copysign(mt.inf, self.a.x) t = mt.copysign(mt.inf, self.a.a)
else: else:
t = self.a.x / self.b.x t = self.a.a / self.b.a
return ['%' if t == +mt.inf return ['%' if t == +mt.inf
else '-∞%' if t == -mt.inf else '-∞%' if t == -mt.inf
else '%.1f%%' % (100*t)] else '%.1f%%' % (100*t)]
@@ -189,8 +189,8 @@ class CsvFrac(co.namedtuple('CsvFrac', 'a,b')):
def ratio(self, other): def ratio(self, other):
new_a, new_b = self if self else (CsvInt(0), CsvInt(0)) new_a, new_b = self if self else (CsvInt(0), CsvInt(0))
old_a, old_b = other if other else (CsvInt(0), CsvInt(0)) old_a, old_b = other if other else (CsvInt(0), CsvInt(0))
new = new_a.x/new_b.x if new_b.x else 1.0 new = new_a.a/new_b.a if new_b.a else 1.0
old = old_a.x/old_b.x if old_b.x else 1.0 old = old_a.a/old_b.a if old_b.a else 1.0
return new - old return new - old
def __pos__(self): def __pos__(self):
@@ -218,16 +218,16 @@ class CsvFrac(co.namedtuple('CsvFrac', 'a,b')):
return self.__class__(self.a % other.a, self.b % other.b) return self.__class__(self.a % other.a, self.b % other.b)
def __eq__(self, other): def __eq__(self, other):
self_a, self_b = self if self.b.x else (CsvInt(1), CsvInt(1)) self_a, self_b = self if self.b.a else (CsvInt(1), CsvInt(1))
other_a, other_b = other if other.b.x else (CsvInt(1), CsvInt(1)) other_a, other_b = other if other.b.a else (CsvInt(1), CsvInt(1))
return self_a * other_b == other_a * self_b return self_a * other_b == other_a * self_b
def __ne__(self, other): def __ne__(self, other):
return not self.__eq__(other) return not self.__eq__(other)
def __lt__(self, other): def __lt__(self, other):
self_a, self_b = self if self.b.x else (CsvInt(1), CsvInt(1)) self_a, self_b = self if self.b.a else (CsvInt(1), CsvInt(1))
other_a, other_b = other if other.b.x else (CsvInt(1), CsvInt(1)) other_a, other_b = other if other.b.a else (CsvInt(1), CsvInt(1))
return self_a * other_b < other_a * self_b return self_a * other_b < other_a * self_b
def __gt__(self, other): def __gt__(self, other):
@@ -367,17 +367,17 @@ def collect_cov(gcda_paths, *,
# common folding/tabling/read/write code # common folding/tabling/read/write code
class Rev(co.namedtuple('Rev', 'x')): class Rev(co.namedtuple('Rev', 'a')):
__slots__ = () __slots__ = ()
# yes we need all of these because we're a namedtuple # yes we need all of these because we're a namedtuple
def __lt__(self, other): def __lt__(self, other):
return self.x > other.x return self.a > other.a
def __gt__(self, other): def __gt__(self, other):
return self.x < other.x return self.a < other.a
def __le__(self, other): def __le__(self, other):
return self.x >= other.x return self.a >= other.a
def __ge__(self, other): def __ge__(self, other):
return self.x <= other.x return self.a <= other.a
def fold(Result, results, *, def fold(Result, results, *,
by=None, by=None,
+81 -81
View File
@@ -27,54 +27,54 @@ import sys
# various field types # various field types
# integer fields # integer fields
class CsvInt(co.namedtuple('CsvInt', 'x')): class CsvInt(co.namedtuple('CsvInt', 'a')):
__slots__ = () __slots__ = ()
def __new__(cls, x=0): def __new__(cls, a=0):
if isinstance(x, CsvInt): if isinstance(a, CsvInt):
return x return a
if isinstance(x, str): if isinstance(a, str):
try: try:
x = int(x, 0) a = int(a, 0)
except ValueError: except ValueError:
# also accept +-∞ and +-inf # also accept +-∞ and +-inf
if re.match('^\s*\+?\s*(?:∞|inf)\s*$', x): if re.match('^\s*\+?\s*(?:∞|inf)\s*$', a):
x = mt.inf a = mt.inf
elif re.match('^\s*-\s*(?:∞|inf)\s*$', x): elif re.match('^\s*-\s*(?:∞|inf)\s*$', a):
x = -mt.inf a = -mt.inf
else: else:
raise raise
if not (isinstance(x, int) or mt.isinf(x)): if not (isinstance(a, int) or mt.isinf(a)):
x = int(x) a = int(a)
return super().__new__(cls, x) return super().__new__(cls, a)
def __repr__(self): def __repr__(self):
return '%s(%r)' % (self.__class__.__name__, self.x) return '%s(%r)' % (self.__class__.__name__, self.a)
def __str__(self): def __str__(self):
if self.x == mt.inf: if self.a == mt.inf:
return '' return ''
elif self.x == -mt.inf: elif self.a == -mt.inf:
return '-∞' return '-∞'
else: else:
return str(self.x) return str(self.a)
def __bool__(self): def __bool__(self):
return bool(self.x) return bool(self.a)
def __int__(self): def __int__(self):
assert not mt.isinf(self.x) assert not mt.isinf(self.a)
return self.x return self.a
def __float__(self): def __float__(self):
return float(self.x) return float(self.a)
none = '%7s' % '-' none = '%7s' % '-'
def table(self): def table(self):
return '%7s' % (self,) return '%7s' % (self,)
def diff(self, other): def diff(self, other):
new = self.x if self else 0 new = self.a if self else 0
old = other.x if other else 0 old = other.a if other else 0
diff = new - old diff = new - old
if diff == +mt.inf: if diff == +mt.inf:
return '%7s' % '+∞' return '%7s' % '+∞'
@@ -84,8 +84,8 @@ class CsvInt(co.namedtuple('CsvInt', 'x')):
return '%+7d' % diff return '%+7d' % diff
def ratio(self, other): def ratio(self, other):
new = self.x if self else 0 new = self.a if self else 0
old = other.x if other else 0 old = other.a if other else 0
if mt.isinf(new) and mt.isinf(old): if mt.isinf(new) and mt.isinf(old):
return 0.0 return 0.0
elif mt.isinf(new): elif mt.isinf(new):
@@ -100,22 +100,22 @@ class CsvInt(co.namedtuple('CsvInt', 'x')):
return (new-old) / old return (new-old) / old
def __pos__(self): def __pos__(self):
return self.__class__(+self.x) return self.__class__(+self.a)
def __neg__(self): def __neg__(self):
return self.__class__(-self.x) return self.__class__(-self.a)
def __abs__(self): def __abs__(self):
return self.__class__(abs(self.x)) return self.__class__(abs(self.a))
def __add__(self, other): def __add__(self, other):
return self.__class__(self.x + other.x) return self.__class__(self.a + other.a)
def __sub__(self, other): def __sub__(self, other):
return self.__class__(self.x - other.x) return self.__class__(self.a - other.a)
def __mul__(self, other): def __mul__(self, other):
return self.__class__(self.x * other.x) return self.__class__(self.a * other.a)
def __truediv__(self, other): def __truediv__(self, other):
if not other: if not other:
@@ -123,59 +123,59 @@ class CsvInt(co.namedtuple('CsvInt', 'x')):
return self.__class__(+mt.inf) return self.__class__(+mt.inf)
else: else:
return self.__class__(-mt.inf) return self.__class__(-mt.inf)
return self.__class__(self.x // other.x) return self.__class__(self.a // other.a)
def __mod__(self, other): def __mod__(self, other):
return self.__class__(self.x % other.x) return self.__class__(self.a % other.a)
# float fields # float fields
class CsvFloat(co.namedtuple('CsvFloat', 'x')): class CsvFloat(co.namedtuple('CsvFloat', 'a')):
__slots__ = () __slots__ = ()
def __new__(cls, x=0.0): def __new__(cls, a=0.0):
if isinstance(x, CsvFloat): if isinstance(a, CsvFloat):
return x return a
if isinstance(x, str): if isinstance(a, str):
try: try:
x = float(x) a = float(a)
except ValueError: except ValueError:
# also accept +-∞ and +-inf # also accept +-∞ and +-inf
if re.match('^\s*\+?\s*(?:∞|inf)\s*$', x): if re.match('^\s*\+?\s*(?:∞|inf)\s*$', a):
x = mt.inf a = mt.inf
elif re.match('^\s*-\s*(?:∞|inf)\s*$', x): elif re.match('^\s*-\s*(?:∞|inf)\s*$', a):
x = -mt.inf a = -mt.inf
else: else:
raise raise
if not isinstance(x, float): if not isinstance(a, float):
x = float(x) a = float(a)
return super().__new__(cls, x) return super().__new__(cls, a)
def __repr__(self): def __repr__(self):
return '%s(%r)' % (self.__class__.__name__, self.x) return '%s(%r)' % (self.__class__.__name__, self.a)
def __str__(self): def __str__(self):
if self.x == mt.inf: if self.a == mt.inf:
return '' return ''
elif self.x == -mt.inf: elif self.a == -mt.inf:
return '-∞' return '-∞'
else: else:
return '%.1f' % self.x return '%.1f' % self.a
def __bool__(self): def __bool__(self):
return bool(self.x) return bool(self.a)
def __int__(self): def __int__(self):
return int(self.x) return int(self.a)
def __float__(self): def __float__(self):
return float(self.x) return float(self.a)
none = '%7s' % '-' none = '%7s' % '-'
def table(self): def table(self):
return '%7s' % (self,) return '%7s' % (self,)
def diff(self, other): def diff(self, other):
new = self.x if self else 0 new = self.a if self else 0
old = other.x if other else 0 old = other.a if other else 0
diff = new - old diff = new - old
if diff == +mt.inf: if diff == +mt.inf:
return '%7s' % '+∞' return '%7s' % '+∞'
@@ -185,8 +185,8 @@ class CsvFloat(co.namedtuple('CsvFloat', 'x')):
return '%+7.1f' % diff return '%+7.1f' % diff
def ratio(self, other): def ratio(self, other):
new = self.x if self else 0 new = self.a if self else 0
old = other.x if other else 0 old = other.a if other else 0
if mt.isinf(new) and mt.isinf(old): if mt.isinf(new) and mt.isinf(old):
return 0.0 return 0.0
elif mt.isinf(new): elif mt.isinf(new):
@@ -201,22 +201,22 @@ class CsvFloat(co.namedtuple('CsvFloat', 'x')):
return (new-old) / old return (new-old) / old
def __pos__(self): def __pos__(self):
return self.__class__(+self.x) return self.__class__(+self.a)
def __neg__(self): def __neg__(self):
return self.__class__(-self.x) return self.__class__(-self.a)
def __abs__(self): def __abs__(self):
return self.__class__(abs(self.x)) return self.__class__(abs(self.a))
def __add__(self, other): def __add__(self, other):
return self.__class__(self.x + other.x) return self.__class__(self.a + other.a)
def __sub__(self, other): def __sub__(self, other):
return self.__class__(self.x - other.x) return self.__class__(self.a - other.a)
def __mul__(self, other): def __mul__(self, other):
return self.__class__(self.x * other.x) return self.__class__(self.a * other.a)
def __truediv__(self, other): def __truediv__(self, other):
if not other: if not other:
@@ -224,10 +224,10 @@ class CsvFloat(co.namedtuple('CsvFloat', 'x')):
return self.__class__(+mt.inf) return self.__class__(+mt.inf)
else: else:
return self.__class__(-mt.inf) return self.__class__(-mt.inf)
return self.__class__(self.x / other.x) return self.__class__(self.a / other.a)
def __mod__(self, other): def __mod__(self, other):
return self.__class__(self.x % other.x) return self.__class__(self.a % other.a)
# fractional fields, a/b # fractional fields, a/b
class CsvFrac(co.namedtuple('CsvFrac', 'a,b')): class CsvFrac(co.namedtuple('CsvFrac', 'a,b')):
@@ -242,7 +242,7 @@ class CsvFrac(co.namedtuple('CsvFrac', 'a,b')):
return super().__new__(cls, CsvInt(a), CsvInt(b)) return super().__new__(cls, CsvInt(a), CsvInt(b))
def __repr__(self): def __repr__(self):
return '%s(%r, %r)' % (self.__class__.__name__, self.a.x, self.b.x) return '%s(%r, %r)' % (self.__class__.__name__, self.a.a, self.b.a)
def __str__(self): def __str__(self):
return '%s/%s' % (self.a, self.b) return '%s/%s' % (self.a, self.b)
@@ -261,12 +261,12 @@ class CsvFrac(co.namedtuple('CsvFrac', 'a,b')):
return '%11s' % (self,) return '%11s' % (self,)
def notes(self): def notes(self):
if self.b.x == 0 and self.a.x == 0: if self.b.a == 0 and self.a.a == 0:
t = 1.0 t = 1.0
elif self.b.x == 0: elif self.b.a == 0:
t = mt.copysign(mt.inf, self.a.x) t = mt.copysign(mt.inf, self.a.a)
else: else:
t = self.a.x / self.b.x t = self.a.a / self.b.a
return ['%' if t == +mt.inf return ['%' if t == +mt.inf
else '-∞%' if t == -mt.inf else '-∞%' if t == -mt.inf
else '%.1f%%' % (100*t)] else '%.1f%%' % (100*t)]
@@ -281,8 +281,8 @@ class CsvFrac(co.namedtuple('CsvFrac', 'a,b')):
def ratio(self, other): def ratio(self, other):
new_a, new_b = self if self else (CsvInt(0), CsvInt(0)) new_a, new_b = self if self else (CsvInt(0), CsvInt(0))
old_a, old_b = other if other else (CsvInt(0), CsvInt(0)) old_a, old_b = other if other else (CsvInt(0), CsvInt(0))
new = new_a.x/new_b.x if new_b.x else 1.0 new = new_a.a/new_b.a if new_b.a else 1.0
old = old_a.x/old_b.x if old_b.x else 1.0 old = old_a.a/old_b.a if old_b.a else 1.0
return new - old return new - old
def __pos__(self): def __pos__(self):
@@ -310,16 +310,16 @@ class CsvFrac(co.namedtuple('CsvFrac', 'a,b')):
return self.__class__(self.a % other.a, self.b % other.b) return self.__class__(self.a % other.a, self.b % other.b)
def __eq__(self, other): def __eq__(self, other):
self_a, self_b = self if self.b.x else (CsvInt(1), CsvInt(1)) self_a, self_b = self if self.b.a else (CsvInt(1), CsvInt(1))
other_a, other_b = other if other.b.x else (CsvInt(1), CsvInt(1)) other_a, other_b = other if other.b.a else (CsvInt(1), CsvInt(1))
return self_a * other_b == other_a * self_b return self_a * other_b == other_a * self_b
def __ne__(self, other): def __ne__(self, other):
return not self.__eq__(other) return not self.__eq__(other)
def __lt__(self, other): def __lt__(self, other):
self_a, self_b = self if self.b.x else (CsvInt(1), CsvInt(1)) self_a, self_b = self if self.b.a else (CsvInt(1), CsvInt(1))
other_a, other_b = other if other.b.x else (CsvInt(1), CsvInt(1)) other_a, other_b = other if other.b.a else (CsvInt(1), CsvInt(1))
return self_a * other_b < other_a * self_b return self_a * other_b < other_a * self_b
def __gt__(self, other): def __gt__(self, other):
@@ -1612,17 +1612,17 @@ def homogenize(Result, results, *,
# common folding/tabling/read/write code # common folding/tabling/read/write code
class Rev(co.namedtuple('Rev', 'x')): class Rev(co.namedtuple('Rev', 'a')):
__slots__ = () __slots__ = ()
# yes we need all of these because we're a namedtuple # yes we need all of these because we're a namedtuple
def __lt__(self, other): def __lt__(self, other):
return self.x > other.x return self.a > other.a
def __gt__(self, other): def __gt__(self, other):
return self.x < other.x return self.a < other.a
def __le__(self, other): def __le__(self, other):
return self.x >= other.x return self.a >= other.a
def __ge__(self, other): def __ge__(self, other):
return self.x <= other.x return self.a <= other.a
def fold(Result, results, *, def fold(Result, results, *,
by=None, by=None,
+38 -38
View File
@@ -30,54 +30,54 @@ OBJDUMP_PATH = ['objdump']
# integer fields # integer fields
class CsvInt(co.namedtuple('CsvInt', 'x')): class CsvInt(co.namedtuple('CsvInt', 'a')):
__slots__ = () __slots__ = ()
def __new__(cls, x=0): def __new__(cls, a=0):
if isinstance(x, CsvInt): if isinstance(a, CsvInt):
return x return a
if isinstance(x, str): if isinstance(a, str):
try: try:
x = int(x, 0) a = int(a, 0)
except ValueError: except ValueError:
# also accept +-∞ and +-inf # also accept +-∞ and +-inf
if re.match('^\s*\+?\s*(?:∞|inf)\s*$', x): if re.match('^\s*\+?\s*(?:∞|inf)\s*$', a):
x = mt.inf a = mt.inf
elif re.match('^\s*-\s*(?:∞|inf)\s*$', x): elif re.match('^\s*-\s*(?:∞|inf)\s*$', a):
x = -mt.inf a = -mt.inf
else: else:
raise raise
if not (isinstance(x, int) or mt.isinf(x)): if not (isinstance(a, int) or mt.isinf(a)):
x = int(x) a = int(a)
return super().__new__(cls, x) return super().__new__(cls, a)
def __repr__(self): def __repr__(self):
return '%s(%r)' % (self.__class__.__name__, self.x) return '%s(%r)' % (self.__class__.__name__, self.a)
def __str__(self): def __str__(self):
if self.x == mt.inf: if self.a == mt.inf:
return '' return ''
elif self.x == -mt.inf: elif self.a == -mt.inf:
return '-∞' return '-∞'
else: else:
return str(self.x) return str(self.a)
def __bool__(self): def __bool__(self):
return bool(self.x) return bool(self.a)
def __int__(self): def __int__(self):
assert not mt.isinf(self.x) assert not mt.isinf(self.a)
return self.x return self.a
def __float__(self): def __float__(self):
return float(self.x) return float(self.a)
none = '%7s' % '-' none = '%7s' % '-'
def table(self): def table(self):
return '%7s' % (self,) return '%7s' % (self,)
def diff(self, other): def diff(self, other):
new = self.x if self else 0 new = self.a if self else 0
old = other.x if other else 0 old = other.a if other else 0
diff = new - old diff = new - old
if diff == +mt.inf: if diff == +mt.inf:
return '%7s' % '+∞' return '%7s' % '+∞'
@@ -87,8 +87,8 @@ class CsvInt(co.namedtuple('CsvInt', 'x')):
return '%+7d' % diff return '%+7d' % diff
def ratio(self, other): def ratio(self, other):
new = self.x if self else 0 new = self.a if self else 0
old = other.x if other else 0 old = other.a if other else 0
if mt.isinf(new) and mt.isinf(old): if mt.isinf(new) and mt.isinf(old):
return 0.0 return 0.0
elif mt.isinf(new): elif mt.isinf(new):
@@ -103,22 +103,22 @@ class CsvInt(co.namedtuple('CsvInt', 'x')):
return (new-old) / old return (new-old) / old
def __pos__(self): def __pos__(self):
return self.__class__(+self.x) return self.__class__(+self.a)
def __neg__(self): def __neg__(self):
return self.__class__(-self.x) return self.__class__(-self.a)
def __abs__(self): def __abs__(self):
return self.__class__(abs(self.x)) return self.__class__(abs(self.a))
def __add__(self, other): def __add__(self, other):
return self.__class__(self.x + other.x) return self.__class__(self.a + other.a)
def __sub__(self, other): def __sub__(self, other):
return self.__class__(self.x - other.x) return self.__class__(self.a - other.a)
def __mul__(self, other): def __mul__(self, other):
return self.__class__(self.x * other.x) return self.__class__(self.a * other.a)
def __truediv__(self, other): def __truediv__(self, other):
if not other: if not other:
@@ -126,10 +126,10 @@ class CsvInt(co.namedtuple('CsvInt', 'x')):
return self.__class__(+mt.inf) return self.__class__(+mt.inf)
else: else:
return self.__class__(-mt.inf) return self.__class__(-mt.inf)
return self.__class__(self.x // other.x) return self.__class__(self.a // other.a)
def __mod__(self, other): def __mod__(self, other):
return self.__class__(self.x % other.x) return self.__class__(self.a % other.a)
# ctx size results # ctx size results
class CtxResult(co.namedtuple('CtxResult', [ class CtxResult(co.namedtuple('CtxResult', [
@@ -720,17 +720,17 @@ def collect_ctx(obj_paths, *,
# common folding/tabling/read/write code # common folding/tabling/read/write code
class Rev(co.namedtuple('Rev', 'x')): class Rev(co.namedtuple('Rev', 'a')):
__slots__ = () __slots__ = ()
# yes we need all of these because we're a namedtuple # yes we need all of these because we're a namedtuple
def __lt__(self, other): def __lt__(self, other):
return self.x > other.x return self.a > other.a
def __gt__(self, other): def __gt__(self, other):
return self.x < other.x return self.a < other.a
def __le__(self, other): def __le__(self, other):
return self.x >= other.x return self.a >= other.a
def __ge__(self, other): def __ge__(self, other):
return self.x <= other.x return self.a <= other.a
def fold(Result, results, *, def fold(Result, results, *,
by=None, by=None,
+38 -38
View File
@@ -34,54 +34,54 @@ SECTIONS = ['.data', '.bss']
# integer fields # integer fields
class CsvInt(co.namedtuple('CsvInt', 'x')): class CsvInt(co.namedtuple('CsvInt', 'a')):
__slots__ = () __slots__ = ()
def __new__(cls, x=0): def __new__(cls, a=0):
if isinstance(x, CsvInt): if isinstance(a, CsvInt):
return x return a
if isinstance(x, str): if isinstance(a, str):
try: try:
x = int(x, 0) a = int(a, 0)
except ValueError: except ValueError:
# also accept +-∞ and +-inf # also accept +-∞ and +-inf
if re.match('^\s*\+?\s*(?:∞|inf)\s*$', x): if re.match('^\s*\+?\s*(?:∞|inf)\s*$', a):
x = mt.inf a = mt.inf
elif re.match('^\s*-\s*(?:∞|inf)\s*$', x): elif re.match('^\s*-\s*(?:∞|inf)\s*$', a):
x = -mt.inf a = -mt.inf
else: else:
raise raise
if not (isinstance(x, int) or mt.isinf(x)): if not (isinstance(a, int) or mt.isinf(a)):
x = int(x) a = int(a)
return super().__new__(cls, x) return super().__new__(cls, a)
def __repr__(self): def __repr__(self):
return '%s(%r)' % (self.__class__.__name__, self.x) return '%s(%r)' % (self.__class__.__name__, self.a)
def __str__(self): def __str__(self):
if self.x == mt.inf: if self.a == mt.inf:
return '' return ''
elif self.x == -mt.inf: elif self.a == -mt.inf:
return '-∞' return '-∞'
else: else:
return str(self.x) return str(self.a)
def __bool__(self): def __bool__(self):
return bool(self.x) return bool(self.a)
def __int__(self): def __int__(self):
assert not mt.isinf(self.x) assert not mt.isinf(self.a)
return self.x return self.a
def __float__(self): def __float__(self):
return float(self.x) return float(self.a)
none = '%7s' % '-' none = '%7s' % '-'
def table(self): def table(self):
return '%7s' % (self,) return '%7s' % (self,)
def diff(self, other): def diff(self, other):
new = self.x if self else 0 new = self.a if self else 0
old = other.x if other else 0 old = other.a if other else 0
diff = new - old diff = new - old
if diff == +mt.inf: if diff == +mt.inf:
return '%7s' % '+∞' return '%7s' % '+∞'
@@ -91,8 +91,8 @@ class CsvInt(co.namedtuple('CsvInt', 'x')):
return '%+7d' % diff return '%+7d' % diff
def ratio(self, other): def ratio(self, other):
new = self.x if self else 0 new = self.a if self else 0
old = other.x if other else 0 old = other.a if other else 0
if mt.isinf(new) and mt.isinf(old): if mt.isinf(new) and mt.isinf(old):
return 0.0 return 0.0
elif mt.isinf(new): elif mt.isinf(new):
@@ -107,22 +107,22 @@ class CsvInt(co.namedtuple('CsvInt', 'x')):
return (new-old) / old return (new-old) / old
def __pos__(self): def __pos__(self):
return self.__class__(+self.x) return self.__class__(+self.a)
def __neg__(self): def __neg__(self):
return self.__class__(-self.x) return self.__class__(-self.a)
def __abs__(self): def __abs__(self):
return self.__class__(abs(self.x)) return self.__class__(abs(self.a))
def __add__(self, other): def __add__(self, other):
return self.__class__(self.x + other.x) return self.__class__(self.a + other.a)
def __sub__(self, other): def __sub__(self, other):
return self.__class__(self.x - other.x) return self.__class__(self.a - other.a)
def __mul__(self, other): def __mul__(self, other):
return self.__class__(self.x * other.x) return self.__class__(self.a * other.a)
def __truediv__(self, other): def __truediv__(self, other):
if not other: if not other:
@@ -130,10 +130,10 @@ class CsvInt(co.namedtuple('CsvInt', 'x')):
return self.__class__(+mt.inf) return self.__class__(+mt.inf)
else: else:
return self.__class__(-mt.inf) return self.__class__(-mt.inf)
return self.__class__(self.x // other.x) return self.__class__(self.a // other.a)
def __mod__(self, other): def __mod__(self, other):
return self.__class__(self.x % other.x) return self.__class__(self.a % other.a)
# data size results # data size results
class DataResult(co.namedtuple('DataResult', [ class DataResult(co.namedtuple('DataResult', [
@@ -507,17 +507,17 @@ def collect_data(obj_paths, *,
# common folding/tabling/read/write code # common folding/tabling/read/write code
class Rev(co.namedtuple('Rev', 'x')): class Rev(co.namedtuple('Rev', 'a')):
__slots__ = () __slots__ = ()
# yes we need all of these because we're a namedtuple # yes we need all of these because we're a namedtuple
def __lt__(self, other): def __lt__(self, other):
return self.x > other.x return self.a > other.a
def __gt__(self, other): def __gt__(self, other):
return self.x < other.x return self.a < other.a
def __le__(self, other): def __le__(self, other):
return self.x >= other.x return self.a >= other.a
def __ge__(self, other): def __ge__(self, other):
return self.x <= other.x return self.a <= other.a
def fold(Result, results, *, def fold(Result, results, *,
by=None, by=None,
+38 -38
View File
@@ -44,54 +44,54 @@ THRESHOLD = (0.5, 0.85)
# integer fields # integer fields
class CsvInt(co.namedtuple('CsvInt', 'x')): class CsvInt(co.namedtuple('CsvInt', 'a')):
__slots__ = () __slots__ = ()
def __new__(cls, x=0): def __new__(cls, a=0):
if isinstance(x, CsvInt): if isinstance(a, CsvInt):
return x return a
if isinstance(x, str): if isinstance(a, str):
try: try:
x = int(x, 0) a = int(a, 0)
except ValueError: except ValueError:
# also accept +-∞ and +-inf # also accept +-∞ and +-inf
if re.match('^\s*\+?\s*(?:∞|inf)\s*$', x): if re.match('^\s*\+?\s*(?:∞|inf)\s*$', a):
x = mt.inf a = mt.inf
elif re.match('^\s*-\s*(?:∞|inf)\s*$', x): elif re.match('^\s*-\s*(?:∞|inf)\s*$', a):
x = -mt.inf a = -mt.inf
else: else:
raise raise
if not (isinstance(x, int) or mt.isinf(x)): if not (isinstance(a, int) or mt.isinf(a)):
x = int(x) a = int(a)
return super().__new__(cls, x) return super().__new__(cls, a)
def __repr__(self): def __repr__(self):
return '%s(%r)' % (self.__class__.__name__, self.x) return '%s(%r)' % (self.__class__.__name__, self.a)
def __str__(self): def __str__(self):
if self.x == mt.inf: if self.a == mt.inf:
return '' return ''
elif self.x == -mt.inf: elif self.a == -mt.inf:
return '-∞' return '-∞'
else: else:
return str(self.x) return str(self.a)
def __bool__(self): def __bool__(self):
return bool(self.x) return bool(self.a)
def __int__(self): def __int__(self):
assert not mt.isinf(self.x) assert not mt.isinf(self.a)
return self.x return self.a
def __float__(self): def __float__(self):
return float(self.x) return float(self.a)
none = '%7s' % '-' none = '%7s' % '-'
def table(self): def table(self):
return '%7s' % (self,) return '%7s' % (self,)
def diff(self, other): def diff(self, other):
new = self.x if self else 0 new = self.a if self else 0
old = other.x if other else 0 old = other.a if other else 0
diff = new - old diff = new - old
if diff == +mt.inf: if diff == +mt.inf:
return '%7s' % '+∞' return '%7s' % '+∞'
@@ -101,8 +101,8 @@ class CsvInt(co.namedtuple('CsvInt', 'x')):
return '%+7d' % diff return '%+7d' % diff
def ratio(self, other): def ratio(self, other):
new = self.x if self else 0 new = self.a if self else 0
old = other.x if other else 0 old = other.a if other else 0
if mt.isinf(new) and mt.isinf(old): if mt.isinf(new) and mt.isinf(old):
return 0.0 return 0.0
elif mt.isinf(new): elif mt.isinf(new):
@@ -117,22 +117,22 @@ class CsvInt(co.namedtuple('CsvInt', 'x')):
return (new-old) / old return (new-old) / old
def __pos__(self): def __pos__(self):
return self.__class__(+self.x) return self.__class__(+self.a)
def __neg__(self): def __neg__(self):
return self.__class__(-self.x) return self.__class__(-self.a)
def __abs__(self): def __abs__(self):
return self.__class__(abs(self.x)) return self.__class__(abs(self.a))
def __add__(self, other): def __add__(self, other):
return self.__class__(self.x + other.x) return self.__class__(self.a + other.a)
def __sub__(self, other): def __sub__(self, other):
return self.__class__(self.x - other.x) return self.__class__(self.a - other.a)
def __mul__(self, other): def __mul__(self, other):
return self.__class__(self.x * other.x) return self.__class__(self.a * other.a)
def __truediv__(self, other): def __truediv__(self, other):
if not other: if not other:
@@ -140,10 +140,10 @@ class CsvInt(co.namedtuple('CsvInt', 'x')):
return self.__class__(+mt.inf) return self.__class__(+mt.inf)
else: else:
return self.__class__(-mt.inf) return self.__class__(-mt.inf)
return self.__class__(self.x // other.x) return self.__class__(self.a // other.a)
def __mod__(self, other): def __mod__(self, other):
return self.__class__(self.x % other.x) return self.__class__(self.a % other.a)
# perf results # perf results
class PerfResult(co.namedtuple('PerfResult', [ class PerfResult(co.namedtuple('PerfResult', [
@@ -821,17 +821,17 @@ def collect_perf(perf_paths, *,
# common folding/tabling/read/write code # common folding/tabling/read/write code
class Rev(co.namedtuple('Rev', 'x')): class Rev(co.namedtuple('Rev', 'a')):
__slots__ = () __slots__ = ()
# yes we need all of these because we're a namedtuple # yes we need all of these because we're a namedtuple
def __lt__(self, other): def __lt__(self, other):
return self.x > other.x return self.a > other.a
def __gt__(self, other): def __gt__(self, other):
return self.x < other.x return self.a < other.a
def __le__(self, other): def __le__(self, other):
return self.x >= other.x return self.a >= other.a
def __ge__(self, other): def __ge__(self, other):
return self.x <= other.x return self.a <= other.a
def fold(Result, results, *, def fold(Result, results, *,
by=None, by=None,
+38 -38
View File
@@ -35,54 +35,54 @@ THRESHOLD = (0.5, 0.85)
# integer fields # integer fields
class CsvInt(co.namedtuple('CsvInt', 'x')): class CsvInt(co.namedtuple('CsvInt', 'a')):
__slots__ = () __slots__ = ()
def __new__(cls, x=0): def __new__(cls, a=0):
if isinstance(x, CsvInt): if isinstance(a, CsvInt):
return x return a
if isinstance(x, str): if isinstance(a, str):
try: try:
x = int(x, 0) a = int(a, 0)
except ValueError: except ValueError:
# also accept +-∞ and +-inf # also accept +-∞ and +-inf
if re.match('^\s*\+?\s*(?:∞|inf)\s*$', x): if re.match('^\s*\+?\s*(?:∞|inf)\s*$', a):
x = mt.inf a = mt.inf
elif re.match('^\s*-\s*(?:∞|inf)\s*$', x): elif re.match('^\s*-\s*(?:∞|inf)\s*$', a):
x = -mt.inf a = -mt.inf
else: else:
raise raise
if not (isinstance(x, int) or mt.isinf(x)): if not (isinstance(a, int) or mt.isinf(a)):
x = int(x) a = int(a)
return super().__new__(cls, x) return super().__new__(cls, a)
def __repr__(self): def __repr__(self):
return '%s(%r)' % (self.__class__.__name__, self.x) return '%s(%r)' % (self.__class__.__name__, self.a)
def __str__(self): def __str__(self):
if self.x == mt.inf: if self.a == mt.inf:
return '' return ''
elif self.x == -mt.inf: elif self.a == -mt.inf:
return '-∞' return '-∞'
else: else:
return str(self.x) return str(self.a)
def __bool__(self): def __bool__(self):
return bool(self.x) return bool(self.a)
def __int__(self): def __int__(self):
assert not mt.isinf(self.x) assert not mt.isinf(self.a)
return self.x return self.a
def __float__(self): def __float__(self):
return float(self.x) return float(self.a)
none = '%7s' % '-' none = '%7s' % '-'
def table(self): def table(self):
return '%7s' % (self,) return '%7s' % (self,)
def diff(self, other): def diff(self, other):
new = self.x if self else 0 new = self.a if self else 0
old = other.x if other else 0 old = other.a if other else 0
diff = new - old diff = new - old
if diff == +mt.inf: if diff == +mt.inf:
return '%7s' % '+∞' return '%7s' % '+∞'
@@ -92,8 +92,8 @@ class CsvInt(co.namedtuple('CsvInt', 'x')):
return '%+7d' % diff return '%+7d' % diff
def ratio(self, other): def ratio(self, other):
new = self.x if self else 0 new = self.a if self else 0
old = other.x if other else 0 old = other.a if other else 0
if mt.isinf(new) and mt.isinf(old): if mt.isinf(new) and mt.isinf(old):
return 0.0 return 0.0
elif mt.isinf(new): elif mt.isinf(new):
@@ -108,22 +108,22 @@ class CsvInt(co.namedtuple('CsvInt', 'x')):
return (new-old) / old return (new-old) / old
def __pos__(self): def __pos__(self):
return self.__class__(+self.x) return self.__class__(+self.a)
def __neg__(self): def __neg__(self):
return self.__class__(-self.x) return self.__class__(-self.a)
def __abs__(self): def __abs__(self):
return self.__class__(abs(self.x)) return self.__class__(abs(self.a))
def __add__(self, other): def __add__(self, other):
return self.__class__(self.x + other.x) return self.__class__(self.a + other.a)
def __sub__(self, other): def __sub__(self, other):
return self.__class__(self.x - other.x) return self.__class__(self.a - other.a)
def __mul__(self, other): def __mul__(self, other):
return self.__class__(self.x * other.x) return self.__class__(self.a * other.a)
def __truediv__(self, other): def __truediv__(self, other):
if not other: if not other:
@@ -131,10 +131,10 @@ class CsvInt(co.namedtuple('CsvInt', 'x')):
return self.__class__(+mt.inf) return self.__class__(+mt.inf)
else: else:
return self.__class__(-mt.inf) return self.__class__(-mt.inf)
return self.__class__(self.x // other.x) return self.__class__(self.a // other.a)
def __mod__(self, other): def __mod__(self, other):
return self.__class__(self.x % other.x) return self.__class__(self.a % other.a)
# perf results # perf results
class PerfBdResult(co.namedtuple('PerfBdResult', [ class PerfBdResult(co.namedtuple('PerfBdResult', [
@@ -795,17 +795,17 @@ def collect_perfbd(elf_path, trace_paths, *,
# common folding/tabling/read/write code # common folding/tabling/read/write code
class Rev(co.namedtuple('Rev', 'x')): class Rev(co.namedtuple('Rev', 'a')):
__slots__ = () __slots__ = ()
# yes we need all of these because we're a namedtuple # yes we need all of these because we're a namedtuple
def __lt__(self, other): def __lt__(self, other):
return self.x > other.x return self.a > other.a
def __gt__(self, other): def __gt__(self, other):
return self.x < other.x return self.a < other.a
def __le__(self, other): def __le__(self, other):
return self.x >= other.x return self.a >= other.a
def __ge__(self, other): def __ge__(self, other):
return self.x <= other.x return self.a <= other.a
def fold(Result, results, *, def fold(Result, results, *,
by=None, by=None,
+38 -38
View File
@@ -30,54 +30,54 @@ OBJDUMP_PATH = ['objdump']
# integer fields # integer fields
class CsvInt(co.namedtuple('CsvInt', 'x')): class CsvInt(co.namedtuple('CsvInt', 'a')):
__slots__ = () __slots__ = ()
def __new__(cls, x=0): def __new__(cls, a=0):
if isinstance(x, CsvInt): if isinstance(a, CsvInt):
return x return a
if isinstance(x, str): if isinstance(a, str):
try: try:
x = int(x, 0) a = int(a, 0)
except ValueError: except ValueError:
# also accept +-∞ and +-inf # also accept +-∞ and +-inf
if re.match('^\s*\+?\s*(?:∞|inf)\s*$', x): if re.match('^\s*\+?\s*(?:∞|inf)\s*$', a):
x = mt.inf a = mt.inf
elif re.match('^\s*-\s*(?:∞|inf)\s*$', x): elif re.match('^\s*-\s*(?:∞|inf)\s*$', a):
x = -mt.inf a = -mt.inf
else: else:
raise raise
if not (isinstance(x, int) or mt.isinf(x)): if not (isinstance(a, int) or mt.isinf(a)):
x = int(x) a = int(a)
return super().__new__(cls, x) return super().__new__(cls, a)
def __repr__(self): def __repr__(self):
return '%s(%r)' % (self.__class__.__name__, self.x) return '%s(%r)' % (self.__class__.__name__, self.a)
def __str__(self): def __str__(self):
if self.x == mt.inf: if self.a == mt.inf:
return '' return ''
elif self.x == -mt.inf: elif self.a == -mt.inf:
return '-∞' return '-∞'
else: else:
return str(self.x) return str(self.a)
def __bool__(self): def __bool__(self):
return bool(self.x) return bool(self.a)
def __int__(self): def __int__(self):
assert not mt.isinf(self.x) assert not mt.isinf(self.a)
return self.x return self.a
def __float__(self): def __float__(self):
return float(self.x) return float(self.a)
none = '%7s' % '-' none = '%7s' % '-'
def table(self): def table(self):
return '%7s' % (self,) return '%7s' % (self,)
def diff(self, other): def diff(self, other):
new = self.x if self else 0 new = self.a if self else 0
old = other.x if other else 0 old = other.a if other else 0
diff = new - old diff = new - old
if diff == +mt.inf: if diff == +mt.inf:
return '%7s' % '+∞' return '%7s' % '+∞'
@@ -87,8 +87,8 @@ class CsvInt(co.namedtuple('CsvInt', 'x')):
return '%+7d' % diff return '%+7d' % diff
def ratio(self, other): def ratio(self, other):
new = self.x if self else 0 new = self.a if self else 0
old = other.x if other else 0 old = other.a if other else 0
if mt.isinf(new) and mt.isinf(old): if mt.isinf(new) and mt.isinf(old):
return 0.0 return 0.0
elif mt.isinf(new): elif mt.isinf(new):
@@ -103,22 +103,22 @@ class CsvInt(co.namedtuple('CsvInt', 'x')):
return (new-old) / old return (new-old) / old
def __pos__(self): def __pos__(self):
return self.__class__(+self.x) return self.__class__(+self.a)
def __neg__(self): def __neg__(self):
return self.__class__(-self.x) return self.__class__(-self.a)
def __abs__(self): def __abs__(self):
return self.__class__(abs(self.x)) return self.__class__(abs(self.a))
def __add__(self, other): def __add__(self, other):
return self.__class__(self.x + other.x) return self.__class__(self.a + other.a)
def __sub__(self, other): def __sub__(self, other):
return self.__class__(self.x - other.x) return self.__class__(self.a - other.a)
def __mul__(self, other): def __mul__(self, other):
return self.__class__(self.x * other.x) return self.__class__(self.a * other.a)
def __truediv__(self, other): def __truediv__(self, other):
if not other: if not other:
@@ -126,10 +126,10 @@ class CsvInt(co.namedtuple('CsvInt', 'x')):
return self.__class__(+mt.inf) return self.__class__(+mt.inf)
else: else:
return self.__class__(-mt.inf) return self.__class__(-mt.inf)
return self.__class__(self.x // other.x) return self.__class__(self.a // other.a)
def __mod__(self, other): def __mod__(self, other):
return self.__class__(self.x % other.x) return self.__class__(self.a % other.a)
# stack size results # stack size results
class StackResult(co.namedtuple('StackResult', [ class StackResult(co.namedtuple('StackResult', [
@@ -463,17 +463,17 @@ def collect_stack(ci_paths, *,
# common folding/tabling/read/write code # common folding/tabling/read/write code
class Rev(co.namedtuple('Rev', 'x')): class Rev(co.namedtuple('Rev', 'a')):
__slots__ = () __slots__ = ()
# yes we need all of these because we're a namedtuple # yes we need all of these because we're a namedtuple
def __lt__(self, other): def __lt__(self, other):
return self.x > other.x return self.a > other.a
def __gt__(self, other): def __gt__(self, other):
return self.x < other.x return self.a < other.a
def __le__(self, other): def __le__(self, other):
return self.x >= other.x return self.a >= other.a
def __ge__(self, other): def __ge__(self, other):
return self.x <= other.x return self.a <= other.a
def fold(Result, results, *, def fold(Result, results, *,
by=None, by=None,
+38 -38
View File
@@ -30,54 +30,54 @@ OBJDUMP_PATH = ['objdump']
# integer fields # integer fields
class CsvInt(co.namedtuple('CsvInt', 'x')): class CsvInt(co.namedtuple('CsvInt', 'a')):
__slots__ = () __slots__ = ()
def __new__(cls, x=0): def __new__(cls, a=0):
if isinstance(x, CsvInt): if isinstance(a, CsvInt):
return x return a
if isinstance(x, str): if isinstance(a, str):
try: try:
x = int(x, 0) a = int(a, 0)
except ValueError: except ValueError:
# also accept +-∞ and +-inf # also accept +-∞ and +-inf
if re.match('^\s*\+?\s*(?:∞|inf)\s*$', x): if re.match('^\s*\+?\s*(?:∞|inf)\s*$', a):
x = mt.inf a = mt.inf
elif re.match('^\s*-\s*(?:∞|inf)\s*$', x): elif re.match('^\s*-\s*(?:∞|inf)\s*$', a):
x = -mt.inf a = -mt.inf
else: else:
raise raise
if not (isinstance(x, int) or mt.isinf(x)): if not (isinstance(a, int) or mt.isinf(a)):
x = int(x) a = int(a)
return super().__new__(cls, x) return super().__new__(cls, a)
def __repr__(self): def __repr__(self):
return '%s(%r)' % (self.__class__.__name__, self.x) return '%s(%r)' % (self.__class__.__name__, self.a)
def __str__(self): def __str__(self):
if self.x == mt.inf: if self.a == mt.inf:
return '' return ''
elif self.x == -mt.inf: elif self.a == -mt.inf:
return '-∞' return '-∞'
else: else:
return str(self.x) return str(self.a)
def __bool__(self): def __bool__(self):
return bool(self.x) return bool(self.a)
def __int__(self): def __int__(self):
assert not mt.isinf(self.x) assert not mt.isinf(self.a)
return self.x return self.a
def __float__(self): def __float__(self):
return float(self.x) return float(self.a)
none = '%7s' % '-' none = '%7s' % '-'
def table(self): def table(self):
return '%7s' % (self,) return '%7s' % (self,)
def diff(self, other): def diff(self, other):
new = self.x if self else 0 new = self.a if self else 0
old = other.x if other else 0 old = other.a if other else 0
diff = new - old diff = new - old
if diff == +mt.inf: if diff == +mt.inf:
return '%7s' % '+∞' return '%7s' % '+∞'
@@ -87,8 +87,8 @@ class CsvInt(co.namedtuple('CsvInt', 'x')):
return '%+7d' % diff return '%+7d' % diff
def ratio(self, other): def ratio(self, other):
new = self.x if self else 0 new = self.a if self else 0
old = other.x if other else 0 old = other.a if other else 0
if mt.isinf(new) and mt.isinf(old): if mt.isinf(new) and mt.isinf(old):
return 0.0 return 0.0
elif mt.isinf(new): elif mt.isinf(new):
@@ -103,22 +103,22 @@ class CsvInt(co.namedtuple('CsvInt', 'x')):
return (new-old) / old return (new-old) / old
def __pos__(self): def __pos__(self):
return self.__class__(+self.x) return self.__class__(+self.a)
def __neg__(self): def __neg__(self):
return self.__class__(-self.x) return self.__class__(-self.a)
def __abs__(self): def __abs__(self):
return self.__class__(abs(self.x)) return self.__class__(abs(self.a))
def __add__(self, other): def __add__(self, other):
return self.__class__(self.x + other.x) return self.__class__(self.a + other.a)
def __sub__(self, other): def __sub__(self, other):
return self.__class__(self.x - other.x) return self.__class__(self.a - other.a)
def __mul__(self, other): def __mul__(self, other):
return self.__class__(self.x * other.x) return self.__class__(self.a * other.a)
def __truediv__(self, other): def __truediv__(self, other):
if not other: if not other:
@@ -126,10 +126,10 @@ class CsvInt(co.namedtuple('CsvInt', 'x')):
return self.__class__(+mt.inf) return self.__class__(+mt.inf)
else: else:
return self.__class__(-mt.inf) return self.__class__(-mt.inf)
return self.__class__(self.x // other.x) return self.__class__(self.a // other.a)
def __mod__(self, other): def __mod__(self, other):
return self.__class__(self.x % other.x) return self.__class__(self.a % other.a)
# struct size results # struct size results
class StructResult(co.namedtuple('StructResult', [ class StructResult(co.namedtuple('StructResult', [
@@ -601,17 +601,17 @@ def collect_structs(obj_paths, *,
# common folding/tabling/read/write code # common folding/tabling/read/write code
class Rev(co.namedtuple('Rev', 'x')): class Rev(co.namedtuple('Rev', 'a')):
__slots__ = () __slots__ = ()
# yes we need all of these because we're a namedtuple # yes we need all of these because we're a namedtuple
def __lt__(self, other): def __lt__(self, other):
return self.x > other.x return self.a > other.a
def __gt__(self, other): def __gt__(self, other):
return self.x < other.x return self.a < other.a
def __le__(self, other): def __le__(self, other):
return self.x >= other.x return self.a >= other.a
def __ge__(self, other): def __ge__(self, other):
return self.x <= other.x return self.a <= other.a
def fold(Result, results, *, def fold(Result, results, *,
by=None, by=None,