scripts: Renamed RInt (and friends) -> CsvInt (and friends)
This prefix was extremely arbitrary anyways. The prefix Csv* has slightly more meaning than R*, since these scripts interact with .csv files quite a bit, and it avoids confusion with rbyd-related things such as Rattr, Ralt, etc.
This commit is contained in:
+4
-4
@@ -34,10 +34,10 @@ SECTIONS = ['.text', '.rodata', '.data']
|
|||||||
|
|
||||||
|
|
||||||
# integer fields
|
# integer fields
|
||||||
class RInt(co.namedtuple('RInt', 'x')):
|
class CsvInt(co.namedtuple('CsvInt', 'x')):
|
||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
def __new__(cls, x=0):
|
def __new__(cls, x=0):
|
||||||
if isinstance(x, RInt):
|
if isinstance(x, CsvInt):
|
||||||
return x
|
return x
|
||||||
if isinstance(x, str):
|
if isinstance(x, str):
|
||||||
try:
|
try:
|
||||||
@@ -143,12 +143,12 @@ class CodeResult(co.namedtuple('CodeResult', [
|
|||||||
_by = ['file', 'function']
|
_by = ['file', 'function']
|
||||||
_fields = ['size']
|
_fields = ['size']
|
||||||
_sort = ['size']
|
_sort = ['size']
|
||||||
_types = {'size': RInt}
|
_types = {'size': CsvInt}
|
||||||
|
|
||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
def __new__(cls, file='', function='', size=0):
|
def __new__(cls, file='', function='', size=0):
|
||||||
return super().__new__(cls, file, function,
|
return super().__new__(cls, file, function,
|
||||||
RInt(size))
|
CsvInt(size))
|
||||||
|
|
||||||
def __add__(self, other):
|
def __add__(self, other):
|
||||||
return CodeResult(self.file, self.function,
|
return CodeResult(self.file, self.function,
|
||||||
|
|||||||
+21
-21
@@ -36,10 +36,10 @@ GCOV_PATH = ['gcov']
|
|||||||
|
|
||||||
|
|
||||||
# integer fields
|
# integer fields
|
||||||
class RInt(co.namedtuple('RInt', 'x')):
|
class CsvInt(co.namedtuple('CsvInt', 'x')):
|
||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
def __new__(cls, x=0):
|
def __new__(cls, x=0):
|
||||||
if isinstance(x, RInt):
|
if isinstance(x, CsvInt):
|
||||||
return x
|
return x
|
||||||
if isinstance(x, str):
|
if isinstance(x, str):
|
||||||
try:
|
try:
|
||||||
@@ -138,16 +138,16 @@ class RInt(co.namedtuple('RInt', 'x')):
|
|||||||
return self.__class__(self.x % other.x)
|
return self.__class__(self.x % other.x)
|
||||||
|
|
||||||
# fractional fields, a/b
|
# fractional fields, a/b
|
||||||
class RFrac(co.namedtuple('RFrac', 'a,b')):
|
class CsvFrac(co.namedtuple('CsvFrac', 'a,b')):
|
||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
def __new__(cls, a=0, b=None):
|
def __new__(cls, a=0, b=None):
|
||||||
if isinstance(a, RFrac) and b is None:
|
if isinstance(a, CsvFrac) and b is None:
|
||||||
return a
|
return a
|
||||||
if isinstance(a, str) and b is None:
|
if isinstance(a, str) and b is None:
|
||||||
a, b = a.split('/', 1)
|
a, b = a.split('/', 1)
|
||||||
if b is None:
|
if b is None:
|
||||||
b = a
|
b = a
|
||||||
return super().__new__(cls, RInt(a), RInt(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.x, self.b.x)
|
||||||
@@ -180,15 +180,15 @@ class RFrac(co.namedtuple('RFrac', 'a,b')):
|
|||||||
else '%.1f%%' % (100*t)]
|
else '%.1f%%' % (100*t)]
|
||||||
|
|
||||||
def diff(self, other):
|
def diff(self, other):
|
||||||
new_a, new_b = self if self else (RInt(0), RInt(0))
|
new_a, new_b = self if self else (CsvInt(0), CsvInt(0))
|
||||||
old_a, old_b = other if other else (RInt(0), RInt(0))
|
old_a, old_b = other if other else (CsvInt(0), CsvInt(0))
|
||||||
return '%11s' % ('%s/%s' % (
|
return '%11s' % ('%s/%s' % (
|
||||||
new_a.diff(old_a).strip(),
|
new_a.diff(old_a).strip(),
|
||||||
new_b.diff(old_b).strip()))
|
new_b.diff(old_b).strip()))
|
||||||
|
|
||||||
def ratio(self, other):
|
def ratio(self, other):
|
||||||
new_a, new_b = self if self else (RInt(0), RInt(0))
|
new_a, new_b = self if self else (CsvInt(0), CsvInt(0))
|
||||||
old_a, old_b = other if other else (RInt(0), RInt(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.x/new_b.x if new_b.x else 1.0
|
||||||
old = old_a.x/old_b.x if old_b.x else 1.0
|
old = old_a.x/old_b.x if old_b.x else 1.0
|
||||||
return new - old
|
return new - old
|
||||||
@@ -218,16 +218,16 @@ class RFrac(co.namedtuple('RFrac', '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 (RInt(1), RInt(1))
|
self_a, self_b = self if self.b.x else (CsvInt(1), CsvInt(1))
|
||||||
other_a, other_b = other if other.b.x else (RInt(1), RInt(1))
|
other_a, other_b = other if other.b.x 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 (RInt(1), RInt(1))
|
self_a, self_b = self if self.b.x else (CsvInt(1), CsvInt(1))
|
||||||
other_a, other_b = other if other.b.x else (RInt(1), RInt(1))
|
other_a, other_b = other if other.b.x 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):
|
||||||
@@ -248,15 +248,15 @@ class CovResult(co.namedtuple('CovResult', [
|
|||||||
_fields = ['calls', 'hits', 'funcs', 'lines', 'branches']
|
_fields = ['calls', 'hits', 'funcs', 'lines', 'branches']
|
||||||
_sort = ['funcs', 'lines', 'branches', 'hits', 'calls']
|
_sort = ['funcs', 'lines', 'branches', 'hits', 'calls']
|
||||||
_types = {
|
_types = {
|
||||||
'calls': RInt, 'hits': RInt,
|
'calls': CsvInt, 'hits': CsvInt,
|
||||||
'funcs': RFrac, 'lines': RFrac, 'branches': RFrac}
|
'funcs': CsvFrac, 'lines': CsvFrac, 'branches': CsvFrac}
|
||||||
|
|
||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
def __new__(cls, file='', function='', line=0,
|
def __new__(cls, file='', function='', line=0,
|
||||||
calls=0, hits=0, funcs=0, lines=0, branches=0):
|
calls=0, hits=0, funcs=0, lines=0, branches=0):
|
||||||
return super().__new__(cls, file, function, int(RInt(line)),
|
return super().__new__(cls, file, function, int(CsvInt(line)),
|
||||||
RInt(calls), RInt(hits),
|
CsvInt(calls), CsvInt(hits),
|
||||||
RFrac(funcs), RFrac(lines), RFrac(branches))
|
CsvFrac(funcs), CsvFrac(lines), CsvFrac(branches))
|
||||||
|
|
||||||
def __add__(self, other):
|
def __add__(self, other):
|
||||||
return CovResult(self.file, self.function, self.line,
|
return CovResult(self.file, self.function, self.line,
|
||||||
@@ -340,7 +340,7 @@ def collect_cov(gcda_paths, *,
|
|||||||
results.append(CovResult(
|
results.append(CovResult(
|
||||||
file_name, func_name, func['start_line'],
|
file_name, func_name, func['start_line'],
|
||||||
func['execution_count'], 0,
|
func['execution_count'], 0,
|
||||||
RFrac(1 if func['execution_count'] > 0 else 0, 1),
|
CsvFrac(1 if func['execution_count'] > 0 else 0, 1),
|
||||||
0,
|
0,
|
||||||
0))
|
0))
|
||||||
|
|
||||||
@@ -356,8 +356,8 @@ def collect_cov(gcda_paths, *,
|
|||||||
file_name, func_name, line['line_number'],
|
file_name, func_name, line['line_number'],
|
||||||
0, line['count'],
|
0, line['count'],
|
||||||
0,
|
0,
|
||||||
RFrac(1 if line['count'] > 0 else 0, 1),
|
CsvFrac(1 if line['count'] > 0 else 0, 1),
|
||||||
RFrac(
|
CsvFrac(
|
||||||
sum(1 if branch['count'] > 0 else 0
|
sum(1 if branch['count'] > 0 else 0
|
||||||
for branch in line['branches']),
|
for branch in line['branches']),
|
||||||
len(line['branches']))))
|
len(line['branches']))))
|
||||||
|
|||||||
+161
-160
@@ -27,10 +27,10 @@ import sys
|
|||||||
# various field types
|
# various field types
|
||||||
|
|
||||||
# integer fields
|
# integer fields
|
||||||
class RInt(co.namedtuple('RInt', 'x')):
|
class CsvInt(co.namedtuple('CsvInt', 'x')):
|
||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
def __new__(cls, x=0):
|
def __new__(cls, x=0):
|
||||||
if isinstance(x, RInt):
|
if isinstance(x, CsvInt):
|
||||||
return x
|
return x
|
||||||
if isinstance(x, str):
|
if isinstance(x, str):
|
||||||
try:
|
try:
|
||||||
@@ -129,10 +129,10 @@ class RInt(co.namedtuple('RInt', 'x')):
|
|||||||
return self.__class__(self.x % other.x)
|
return self.__class__(self.x % other.x)
|
||||||
|
|
||||||
# float fields
|
# float fields
|
||||||
class RFloat(co.namedtuple('RFloat', 'x')):
|
class CsvFloat(co.namedtuple('CsvFloat', 'x')):
|
||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
def __new__(cls, x=0.0):
|
def __new__(cls, x=0.0):
|
||||||
if isinstance(x, RFloat):
|
if isinstance(x, CsvFloat):
|
||||||
return x
|
return x
|
||||||
if isinstance(x, str):
|
if isinstance(x, str):
|
||||||
try:
|
try:
|
||||||
@@ -230,16 +230,16 @@ class RFloat(co.namedtuple('RFloat', 'x')):
|
|||||||
return self.__class__(self.x % other.x)
|
return self.__class__(self.x % other.x)
|
||||||
|
|
||||||
# fractional fields, a/b
|
# fractional fields, a/b
|
||||||
class RFrac(co.namedtuple('RFrac', 'a,b')):
|
class CsvFrac(co.namedtuple('CsvFrac', 'a,b')):
|
||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
def __new__(cls, a=0, b=None):
|
def __new__(cls, a=0, b=None):
|
||||||
if isinstance(a, RFrac) and b is None:
|
if isinstance(a, CsvFrac) and b is None:
|
||||||
return a
|
return a
|
||||||
if isinstance(a, str) and b is None:
|
if isinstance(a, str) and b is None:
|
||||||
a, b = a.split('/', 1)
|
a, b = a.split('/', 1)
|
||||||
if b is None:
|
if b is None:
|
||||||
b = a
|
b = a
|
||||||
return super().__new__(cls, RInt(a), RInt(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.x, self.b.x)
|
||||||
@@ -272,15 +272,15 @@ class RFrac(co.namedtuple('RFrac', 'a,b')):
|
|||||||
else '%.1f%%' % (100*t)]
|
else '%.1f%%' % (100*t)]
|
||||||
|
|
||||||
def diff(self, other):
|
def diff(self, other):
|
||||||
new_a, new_b = self if self else (RInt(0), RInt(0))
|
new_a, new_b = self if self else (CsvInt(0), CsvInt(0))
|
||||||
old_a, old_b = other if other else (RInt(0), RInt(0))
|
old_a, old_b = other if other else (CsvInt(0), CsvInt(0))
|
||||||
return '%11s' % ('%s/%s' % (
|
return '%11s' % ('%s/%s' % (
|
||||||
new_a.diff(old_a).strip(),
|
new_a.diff(old_a).strip(),
|
||||||
new_b.diff(old_b).strip()))
|
new_b.diff(old_b).strip()))
|
||||||
|
|
||||||
def ratio(self, other):
|
def ratio(self, other):
|
||||||
new_a, new_b = self if self else (RInt(0), RInt(0))
|
new_a, new_b = self if self else (CsvInt(0), CsvInt(0))
|
||||||
old_a, old_b = other if other else (RInt(0), RInt(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.x/new_b.x if new_b.x else 1.0
|
||||||
old = old_a.x/old_b.x if old_b.x else 1.0
|
old = old_a.x/old_b.x if old_b.x else 1.0
|
||||||
return new - old
|
return new - old
|
||||||
@@ -310,16 +310,16 @@ class RFrac(co.namedtuple('RFrac', '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 (RInt(1), RInt(1))
|
self_a, self_b = self if self.b.x else (CsvInt(1), CsvInt(1))
|
||||||
other_a, other_b = other if other.b.x else (RInt(1), RInt(1))
|
other_a, other_b = other if other.b.x 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 (RInt(1), RInt(1))
|
self_a, self_b = self if self.b.x else (CsvInt(1), CsvInt(1))
|
||||||
other_a, other_b = other if other.b.x else (RInt(1), RInt(1))
|
other_a, other_b = other if other.b.x 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):
|
||||||
@@ -333,39 +333,40 @@ class RFrac(co.namedtuple('RFrac', 'a,b')):
|
|||||||
|
|
||||||
|
|
||||||
# various fold operations
|
# various fold operations
|
||||||
class RSum:
|
class CsvSum:
|
||||||
def __call__(self, xs):
|
def __call__(self, xs):
|
||||||
return sum(xs[1:], start=xs[0])
|
return sum(xs[1:], start=xs[0])
|
||||||
|
|
||||||
class RProd:
|
class CsvProd:
|
||||||
def __call__(self, xs):
|
def __call__(self, xs):
|
||||||
return mt.prod(xs[1:], start=xs[0])
|
return mt.prod(xs[1:], start=xs[0])
|
||||||
|
|
||||||
class RMin:
|
class CsvMin:
|
||||||
def __call__(self, xs):
|
def __call__(self, xs):
|
||||||
return min(xs)
|
return min(xs)
|
||||||
|
|
||||||
class RMax:
|
class CsvMax:
|
||||||
def __call__(self, xs):
|
def __call__(self, xs):
|
||||||
return max(xs)
|
return max(xs)
|
||||||
|
|
||||||
class RAvg:
|
class CsvAvg:
|
||||||
def __call__(self, xs):
|
def __call__(self, xs):
|
||||||
return RFloat(sum(float(x) for x in xs) / len(xs))
|
return CsvFloat(sum(float(x) for x in xs) / len(xs))
|
||||||
|
|
||||||
class RStddev:
|
class CsvStddev:
|
||||||
def __call__(self, xs):
|
def __call__(self, xs):
|
||||||
avg = sum(float(x) for x in xs) / len(xs)
|
avg = sum(float(x) for x in xs) / len(xs)
|
||||||
return RFloat(mt.sqrt(sum((float(x) - avg)**2 for x in xs) / len(xs)))
|
return CsvFloat(mt.sqrt(
|
||||||
|
sum((float(x) - avg)**2 for x in xs) / len(xs)))
|
||||||
|
|
||||||
class RGMean:
|
class CsvGMean:
|
||||||
def __call__(self, xs):
|
def __call__(self, xs):
|
||||||
return RFloat(mt.prod(float(x) for x in xs)**(1/len(xs)))
|
return CsvFloat(mt.prod(float(x) for x in xs)**(1/len(xs)))
|
||||||
|
|
||||||
class RGStddev:
|
class CsvGStddev:
|
||||||
def __call__(self, xs):
|
def __call__(self, xs):
|
||||||
gmean = mt.prod(float(x) for x in xs)**(1/len(xs))
|
gmean = mt.prod(float(x) for x in xs)**(1/len(xs))
|
||||||
return RFloat(
|
return CsvFloat(
|
||||||
mt.exp(mt.sqrt(
|
mt.exp(mt.sqrt(
|
||||||
sum(mt.log(float(x)/gmean)**2 for x in xs) / len(xs)))
|
sum(mt.log(float(x)/gmean)**2 for x in xs) / len(xs)))
|
||||||
if gmean else mt.inf)
|
if gmean else mt.inf)
|
||||||
@@ -450,7 +451,7 @@ class Parser:
|
|||||||
self.discard()
|
self.discard()
|
||||||
|
|
||||||
# a lazily-evaluated field expression
|
# a lazily-evaluated field expression
|
||||||
class RExpr:
|
class CsvExpr:
|
||||||
# expr parsing/typechecking/etc errors
|
# expr parsing/typechecking/etc errors
|
||||||
class Error(Exception):
|
class Error(Exception):
|
||||||
pass
|
pass
|
||||||
@@ -481,7 +482,7 @@ class RExpr:
|
|||||||
def type(self, types={}):
|
def type(self, types={}):
|
||||||
t = self.a.type(types)
|
t = self.a.type(types)
|
||||||
if not all(t == v.type(types) for v in it.islice(self, 1, None)):
|
if not all(t == v.type(types) for v in it.islice(self, 1, None)):
|
||||||
raise RExpr.Error("mismatched types? %r" % self)
|
raise CsvExpr.Error("mismatched types? %r" % self)
|
||||||
return t
|
return t
|
||||||
|
|
||||||
def fold(self, types={}):
|
def fold(self, types={}):
|
||||||
@@ -498,10 +499,10 @@ class RExpr:
|
|||||||
return set()
|
return set()
|
||||||
|
|
||||||
def type(self, types={}):
|
def type(self, types={}):
|
||||||
return RInt
|
return CsvInt
|
||||||
|
|
||||||
def fold(self, types={}):
|
def fold(self, types={}):
|
||||||
return RSum, RInt
|
return CsvSum, CsvInt
|
||||||
|
|
||||||
def eval(self, fields={}):
|
def eval(self, fields={}):
|
||||||
return self.a
|
return self.a
|
||||||
@@ -511,10 +512,10 @@ class RExpr:
|
|||||||
return set()
|
return set()
|
||||||
|
|
||||||
def type(self, types={}):
|
def type(self, types={}):
|
||||||
return RFloat
|
return CsvFloat
|
||||||
|
|
||||||
def fold(self, types={}):
|
def fold(self, types={}):
|
||||||
return RSum, RFloat
|
return CsvSum, CsvFloat
|
||||||
|
|
||||||
def eval(self, fields={}):
|
def eval(self, fields={}):
|
||||||
return self.a
|
return self.a
|
||||||
@@ -526,17 +527,17 @@ class RExpr:
|
|||||||
|
|
||||||
def type(self, types={}):
|
def type(self, types={}):
|
||||||
if self.a not in types:
|
if self.a not in types:
|
||||||
raise RExpr.Error("untyped field? %s" % self.a)
|
raise CsvExpr.Error("untyped field? %s" % self.a)
|
||||||
return types[self.a]
|
return types[self.a]
|
||||||
|
|
||||||
def fold(self, types={}):
|
def fold(self, types={}):
|
||||||
if self.a not in types:
|
if self.a not in types:
|
||||||
raise RExpr.Error("unfoldable field? %s" % self.a)
|
raise CsvExpr.Error("unfoldable field? %s" % self.a)
|
||||||
return RSum, types[self.a]
|
return CsvSum, types[self.a]
|
||||||
|
|
||||||
def eval(self, fields={}):
|
def eval(self, fields={}):
|
||||||
if self.a not in fields:
|
if self.a not in fields:
|
||||||
raise RExpr.Error("unknown field? %s" % self.a)
|
raise CsvExpr.Error("unknown field? %s" % self.a)
|
||||||
return fields[self.a]
|
return fields[self.a]
|
||||||
|
|
||||||
# func expr helper
|
# func expr helper
|
||||||
@@ -560,31 +561,31 @@ class RExpr:
|
|||||||
class Int(Expr):
|
class Int(Expr):
|
||||||
"""Convert to an integer"""
|
"""Convert to an integer"""
|
||||||
def type(self, types={}):
|
def type(self, types={}):
|
||||||
return RInt
|
return CsvInt
|
||||||
|
|
||||||
def eval(self, fields={}):
|
def eval(self, fields={}):
|
||||||
return RInt(self.a.eval(fields))
|
return CsvInt(self.a.eval(fields))
|
||||||
|
|
||||||
@func('float', 'a')
|
@func('float', 'a')
|
||||||
class Float(Expr):
|
class Float(Expr):
|
||||||
"""Convert to a float"""
|
"""Convert to a float"""
|
||||||
def type(self, types={}):
|
def type(self, types={}):
|
||||||
return RFloat
|
return CsvFloat
|
||||||
|
|
||||||
def eval(self, fields={}):
|
def eval(self, fields={}):
|
||||||
return RFloat(self.a.eval(fields))
|
return CsvFloat(self.a.eval(fields))
|
||||||
|
|
||||||
@func('frac', 'a[, b]')
|
@func('frac', 'a[, b]')
|
||||||
class Frac(Expr):
|
class Frac(Expr):
|
||||||
"""Convert to a fraction"""
|
"""Convert to a fraction"""
|
||||||
def type(self, types={}):
|
def type(self, types={}):
|
||||||
return RFrac
|
return CsvFrac
|
||||||
|
|
||||||
def eval(self, fields={}):
|
def eval(self, fields={}):
|
||||||
if len(self) == 1:
|
if len(self) == 1:
|
||||||
return RFrac(self.a.eval(fields))
|
return CsvFrac(self.a.eval(fields))
|
||||||
else:
|
else:
|
||||||
return RFrac(self.a.eval(fields), self.b.eval(fields))
|
return CsvFrac(self.a.eval(fields), self.b.eval(fields))
|
||||||
|
|
||||||
# fold exprs
|
# fold exprs
|
||||||
@func('sum', 'a[, ...]')
|
@func('sum', 'a[, ...]')
|
||||||
@@ -592,7 +593,7 @@ class RExpr:
|
|||||||
"""Find the sum of this column or fields"""
|
"""Find the sum of this column or fields"""
|
||||||
def fold(self, types={}):
|
def fold(self, types={}):
|
||||||
if len(self) == 1:
|
if len(self) == 1:
|
||||||
return RSum, self.a.type(types)
|
return CsvSum, self.a.type(types)
|
||||||
else:
|
else:
|
||||||
return self.a.fold(types)
|
return self.a.fold(types)
|
||||||
|
|
||||||
@@ -600,7 +601,7 @@ class RExpr:
|
|||||||
if len(self) == 1:
|
if len(self) == 1:
|
||||||
return self.a.eval(fields)
|
return self.a.eval(fields)
|
||||||
else:
|
else:
|
||||||
return RSum()([v.eval(fields) for v in self])
|
return CsvSum()([v.eval(fields) for v in self])
|
||||||
|
|
||||||
@func('prod', 'a[, ...]')
|
@func('prod', 'a[, ...]')
|
||||||
class Prod(Expr):
|
class Prod(Expr):
|
||||||
@@ -622,7 +623,7 @@ class RExpr:
|
|||||||
"""Find the minimum of this column or fields"""
|
"""Find the minimum of this column or fields"""
|
||||||
def fold(self, types={}):
|
def fold(self, types={}):
|
||||||
if len(self) == 1:
|
if len(self) == 1:
|
||||||
return RMin, self.a.type(types)
|
return CsvMin, self.a.type(types)
|
||||||
else:
|
else:
|
||||||
return self.a.fold(types)
|
return self.a.fold(types)
|
||||||
|
|
||||||
@@ -630,14 +631,14 @@ class RExpr:
|
|||||||
if len(self) == 1:
|
if len(self) == 1:
|
||||||
return self.a.eval(fields)
|
return self.a.eval(fields)
|
||||||
else:
|
else:
|
||||||
return RMin()([v.eval(fields) for v in self])
|
return CsvMin()([v.eval(fields) for v in self])
|
||||||
|
|
||||||
@func('max', 'a[, ...]')
|
@func('max', 'a[, ...]')
|
||||||
class Max(Expr):
|
class Max(Expr):
|
||||||
"""Find the maximum of this column or fields"""
|
"""Find the maximum of this column or fields"""
|
||||||
def fold(self, types={}):
|
def fold(self, types={}):
|
||||||
if len(self) == 1:
|
if len(self) == 1:
|
||||||
return RMax, self.a.type(types)
|
return CsvMax, self.a.type(types)
|
||||||
else:
|
else:
|
||||||
return self.a.fold(types)
|
return self.a.fold(types)
|
||||||
|
|
||||||
@@ -645,7 +646,7 @@ class RExpr:
|
|||||||
if len(self) == 1:
|
if len(self) == 1:
|
||||||
return self.a.eval(fields)
|
return self.a.eval(fields)
|
||||||
else:
|
else:
|
||||||
return RMax()([v.eval(fields) for v in self])
|
return CsvMax()([v.eval(fields) for v in self])
|
||||||
|
|
||||||
@func('avg', 'a[, ...]')
|
@func('avg', 'a[, ...]')
|
||||||
class Avg(Expr):
|
class Avg(Expr):
|
||||||
@@ -654,11 +655,11 @@ class RExpr:
|
|||||||
if len(self) == 1:
|
if len(self) == 1:
|
||||||
return self.a.type(types)
|
return self.a.type(types)
|
||||||
else:
|
else:
|
||||||
return RFloat
|
return CsvFloat
|
||||||
|
|
||||||
def fold(self, types={}):
|
def fold(self, types={}):
|
||||||
if len(self) == 1:
|
if len(self) == 1:
|
||||||
return RAvg, RFloat
|
return CsvAvg, CsvFloat
|
||||||
else:
|
else:
|
||||||
return self.a.fold(types)
|
return self.a.fold(types)
|
||||||
|
|
||||||
@@ -666,7 +667,7 @@ class RExpr:
|
|||||||
if len(self) == 1:
|
if len(self) == 1:
|
||||||
return self.a.eval(fields)
|
return self.a.eval(fields)
|
||||||
else:
|
else:
|
||||||
return RAvg()([v.eval(fields) for v in self])
|
return CsvAvg()([v.eval(fields) for v in self])
|
||||||
|
|
||||||
@func('stddev', 'a[, ...]')
|
@func('stddev', 'a[, ...]')
|
||||||
class Stddev(Expr):
|
class Stddev(Expr):
|
||||||
@@ -675,11 +676,11 @@ class RExpr:
|
|||||||
if len(self) == 1:
|
if len(self) == 1:
|
||||||
return self.a.type(types)
|
return self.a.type(types)
|
||||||
else:
|
else:
|
||||||
return RFloat
|
return CsvFloat
|
||||||
|
|
||||||
def fold(self, types={}):
|
def fold(self, types={}):
|
||||||
if len(self) == 1:
|
if len(self) == 1:
|
||||||
return RStddev, RFloat
|
return CsvStddev, CsvFloat
|
||||||
else:
|
else:
|
||||||
return self.a.fold(types)
|
return self.a.fold(types)
|
||||||
|
|
||||||
@@ -687,7 +688,7 @@ class RExpr:
|
|||||||
if len(self) == 1:
|
if len(self) == 1:
|
||||||
return self.a.eval(fields)
|
return self.a.eval(fields)
|
||||||
else:
|
else:
|
||||||
return RStddev()([v.eval(fields) for v in self])
|
return CsvStddev()([v.eval(fields) for v in self])
|
||||||
|
|
||||||
@func('gmean', 'a[, ...]')
|
@func('gmean', 'a[, ...]')
|
||||||
class GMean(Expr):
|
class GMean(Expr):
|
||||||
@@ -696,11 +697,11 @@ class RExpr:
|
|||||||
if len(self) == 1:
|
if len(self) == 1:
|
||||||
return self.a.type(types)
|
return self.a.type(types)
|
||||||
else:
|
else:
|
||||||
return RFloat
|
return CsvFloat
|
||||||
|
|
||||||
def fold(self, types={}):
|
def fold(self, types={}):
|
||||||
if len(self) == 1:
|
if len(self) == 1:
|
||||||
return RGMean, RFloat
|
return CsvGMean, CsvFloat
|
||||||
else:
|
else:
|
||||||
return self.a.fold(types)
|
return self.a.fold(types)
|
||||||
|
|
||||||
@@ -708,7 +709,7 @@ class RExpr:
|
|||||||
if len(self) == 1:
|
if len(self) == 1:
|
||||||
return self.a.eval(fields)
|
return self.a.eval(fields)
|
||||||
else:
|
else:
|
||||||
return RGMean()([v.eval(fields) for v in self])
|
return CsvGMean()([v.eval(fields) for v in self])
|
||||||
|
|
||||||
@func('gstddev', 'a[, ...]')
|
@func('gstddev', 'a[, ...]')
|
||||||
class GStddev(Expr):
|
class GStddev(Expr):
|
||||||
@@ -717,11 +718,11 @@ class RExpr:
|
|||||||
if len(self) == 1:
|
if len(self) == 1:
|
||||||
return self.a.type(types)
|
return self.a.type(types)
|
||||||
else:
|
else:
|
||||||
return RFloat
|
return CsvFloat
|
||||||
|
|
||||||
def fold(self, types={}):
|
def fold(self, types={}):
|
||||||
if len(self) == 1:
|
if len(self) == 1:
|
||||||
return RGStddev, RFloat
|
return CsvGStddev, CsvFloat
|
||||||
else:
|
else:
|
||||||
return self.a.fold(types)
|
return self.a.fold(types)
|
||||||
|
|
||||||
@@ -729,32 +730,32 @@ class RExpr:
|
|||||||
if len(self) == 1:
|
if len(self) == 1:
|
||||||
return self.a.eval(fields)
|
return self.a.eval(fields)
|
||||||
else:
|
else:
|
||||||
return RGStddev()([v.eval(fields) for v in self])
|
return CsvGStddev()([v.eval(fields) for v in self])
|
||||||
|
|
||||||
# functions
|
# functions
|
||||||
@func('ratio', 'a')
|
@func('ratio', 'a')
|
||||||
class Ratio(Expr):
|
class Ratio(Expr):
|
||||||
"""Ratio of a fraction as a float"""
|
"""Ratio of a fraction as a float"""
|
||||||
def type(self, types={}):
|
def type(self, types={}):
|
||||||
return RFloat
|
return CsvFloat
|
||||||
|
|
||||||
def eval(self, fields={}):
|
def eval(self, fields={}):
|
||||||
v = RFrac(self.a.eval(fields))
|
v = CsvFrac(self.a.eval(fields))
|
||||||
if not float(v.b) and not float(v.a):
|
if not float(v.b) and not float(v.a):
|
||||||
return RFloat(1)
|
return CsvFloat(1)
|
||||||
elif not float(v.b):
|
elif not float(v.b):
|
||||||
return RFloat(mt.copysign(mt.inf, float(v.a)))
|
return CsvFloat(mt.copysign(mt.inf, float(v.a)))
|
||||||
else:
|
else:
|
||||||
return RFloat(float(v.a) / float(v.b))
|
return CsvFloat(float(v.a) / float(v.b))
|
||||||
|
|
||||||
@func('total', 'a')
|
@func('total', 'a')
|
||||||
class Total(Expr):
|
class Total(Expr):
|
||||||
"""Total part of a fraction"""
|
"""Total part of a fraction"""
|
||||||
def type(self, types={}):
|
def type(self, types={}):
|
||||||
return RInt
|
return CsvInt
|
||||||
|
|
||||||
def eval(self, fields={}):
|
def eval(self, fields={}):
|
||||||
return RFrac(self.a.eval(fields)).b
|
return CsvFrac(self.a.eval(fields)).b
|
||||||
|
|
||||||
@func('abs', 'a')
|
@func('abs', 'a')
|
||||||
class Abs(Expr):
|
class Abs(Expr):
|
||||||
@@ -766,32 +767,32 @@ class RExpr:
|
|||||||
class Ceil(Expr):
|
class Ceil(Expr):
|
||||||
"""Round up to nearest integer"""
|
"""Round up to nearest integer"""
|
||||||
def type(self, types={}):
|
def type(self, types={}):
|
||||||
return RFloat
|
return CsvFloat
|
||||||
|
|
||||||
def eval(self, fields={}):
|
def eval(self, fields={}):
|
||||||
return RFloat(mt.ceil(float(self.a.eval(fields))))
|
return CsvFloat(mt.ceil(float(self.a.eval(fields))))
|
||||||
|
|
||||||
@func('floor', 'a')
|
@func('floor', 'a')
|
||||||
class Floor(Expr):
|
class Floor(Expr):
|
||||||
"""Round down to nearest integer"""
|
"""Round down to nearest integer"""
|
||||||
def type(self, types={}):
|
def type(self, types={}):
|
||||||
return RFloat
|
return CsvFloat
|
||||||
|
|
||||||
def eval(self, fields={}):
|
def eval(self, fields={}):
|
||||||
return RFloat(mt.floor(float(self.a.eval(fields))))
|
return CsvFloat(mt.floor(float(self.a.eval(fields))))
|
||||||
|
|
||||||
@func('log', 'a[, b]')
|
@func('log', 'a[, b]')
|
||||||
class Log(Expr):
|
class Log(Expr):
|
||||||
"""Log of a with base e, or log of a with base b"""
|
"""Log of a with base e, or log of a with base b"""
|
||||||
def type(self, types={}):
|
def type(self, types={}):
|
||||||
return RFloat
|
return CsvFloat
|
||||||
|
|
||||||
def eval(self, fields={}):
|
def eval(self, fields={}):
|
||||||
if len(self) == 1:
|
if len(self) == 1:
|
||||||
return RFloat(mt.log(
|
return CsvFloat(mt.log(
|
||||||
float(self.a.eval(fields))))
|
float(self.a.eval(fields))))
|
||||||
else:
|
else:
|
||||||
return RFloat(mt.log(
|
return CsvFloat(mt.log(
|
||||||
float(self.a.eval(fields)),
|
float(self.a.eval(fields)),
|
||||||
float(self.b.eval(fields))))
|
float(self.b.eval(fields))))
|
||||||
|
|
||||||
@@ -799,14 +800,14 @@ class RExpr:
|
|||||||
class Pow(Expr):
|
class Pow(Expr):
|
||||||
"""e to the power of a, or a to the power of b"""
|
"""e to the power of a, or a to the power of b"""
|
||||||
def type(self, types={}):
|
def type(self, types={}):
|
||||||
return RFloat
|
return CsvFloat
|
||||||
|
|
||||||
def eval(self, fields={}):
|
def eval(self, fields={}):
|
||||||
if len(self) == 1:
|
if len(self) == 1:
|
||||||
return RFloat(mt.exp(
|
return CsvFloat(mt.exp(
|
||||||
float(self.a.eval(fields))))
|
float(self.a.eval(fields))))
|
||||||
else:
|
else:
|
||||||
return RFloat(mt.pow(
|
return CsvFloat(mt.pow(
|
||||||
float(self.a.eval(fields)),
|
float(self.a.eval(fields)),
|
||||||
float(self.b.eval(fields))))
|
float(self.b.eval(fields))))
|
||||||
|
|
||||||
@@ -814,70 +815,70 @@ class RExpr:
|
|||||||
class Sqrt(Expr):
|
class Sqrt(Expr):
|
||||||
"""Square root"""
|
"""Square root"""
|
||||||
def type(self, types={}):
|
def type(self, types={}):
|
||||||
return RFloat
|
return CsvFloat
|
||||||
|
|
||||||
def eval(self, fields={}):
|
def eval(self, fields={}):
|
||||||
return RFloat(mt.sqrt(float(self.a.eval(fields))))
|
return CsvFloat(mt.sqrt(float(self.a.eval(fields))))
|
||||||
|
|
||||||
@func('isint', 'a')
|
@func('isint', 'a')
|
||||||
class IsInt(Expr):
|
class IsInt(Expr):
|
||||||
"""1 if a is an integer, otherwise 0"""
|
"""1 if a is an integer, otherwise 0"""
|
||||||
def type(self, types={}):
|
def type(self, types={}):
|
||||||
return RInt
|
return CsvInt
|
||||||
|
|
||||||
def eval(self, fields={}):
|
def eval(self, fields={}):
|
||||||
if isinstance(self.a.eval(fields), RInt):
|
if isinstance(self.a.eval(fields), CsvInt):
|
||||||
return RInt(1)
|
return CsvInt(1)
|
||||||
else:
|
else:
|
||||||
return RInt(0)
|
return CsvInt(0)
|
||||||
|
|
||||||
@func('isfloat', 'a')
|
@func('isfloat', 'a')
|
||||||
class IsFloat(Expr):
|
class IsFloat(Expr):
|
||||||
"""1 if a is a float, otherwise 0"""
|
"""1 if a is a float, otherwise 0"""
|
||||||
def type(self, types={}):
|
def type(self, types={}):
|
||||||
return RInt
|
return CsvInt
|
||||||
|
|
||||||
def eval(self, fields={}):
|
def eval(self, fields={}):
|
||||||
if isinstance(self.a.eval(fields), RFloat):
|
if isinstance(self.a.eval(fields), CsvFloat):
|
||||||
return RInt(1)
|
return CsvInt(1)
|
||||||
else:
|
else:
|
||||||
return RInt(0)
|
return CsvInt(0)
|
||||||
|
|
||||||
@func('isfrac', 'a')
|
@func('isfrac', 'a')
|
||||||
class IsFrac(Expr):
|
class IsFrac(Expr):
|
||||||
"""1 if a is a fraction, otherwise 0"""
|
"""1 if a is a fraction, otherwise 0"""
|
||||||
def type(self, types={}):
|
def type(self, types={}):
|
||||||
return RInt
|
return CsvInt
|
||||||
|
|
||||||
def eval(self, fields={}):
|
def eval(self, fields={}):
|
||||||
if isinstance(self.a.eval(fields), RFrac):
|
if isinstance(self.a.eval(fields), CsvFrac):
|
||||||
return RInt(1)
|
return CsvInt(1)
|
||||||
else:
|
else:
|
||||||
return RInt(0)
|
return CsvInt(0)
|
||||||
|
|
||||||
@func('isinf', 'a')
|
@func('isinf', 'a')
|
||||||
class IsInf(Expr):
|
class IsInf(Expr):
|
||||||
"""1 if a is infinite, otherwise 0"""
|
"""1 if a is infinite, otherwise 0"""
|
||||||
def type(self, types={}):
|
def type(self, types={}):
|
||||||
return RInt
|
return CsvInt
|
||||||
|
|
||||||
def eval(self, fields={}):
|
def eval(self, fields={}):
|
||||||
if mt.isinf(self.a.eval(fields)):
|
if mt.isinf(self.a.eval(fields)):
|
||||||
return RInt(1)
|
return CsvInt(1)
|
||||||
else:
|
else:
|
||||||
return RInt(0)
|
return CsvInt(0)
|
||||||
|
|
||||||
@func('isnan')
|
@func('isnan')
|
||||||
class IsNan(Expr):
|
class IsNan(Expr):
|
||||||
"""1 if a is a NAN, otherwise 0"""
|
"""1 if a is a NAN, otherwise 0"""
|
||||||
def type(self, types={}):
|
def type(self, types={}):
|
||||||
return RInt
|
return CsvInt
|
||||||
|
|
||||||
def eval(self, fields={}):
|
def eval(self, fields={}):
|
||||||
if mt.isnan(self.a.eval(fields)):
|
if mt.isnan(self.a.eval(fields)):
|
||||||
return RInt(1)
|
return CsvInt(1)
|
||||||
else:
|
else:
|
||||||
return RInt(0)
|
return CsvInt(0)
|
||||||
|
|
||||||
# unary expr helper
|
# unary expr helper
|
||||||
def uop(op):
|
def uop(op):
|
||||||
@@ -911,13 +912,13 @@ class RExpr:
|
|||||||
class NotNot(Expr):
|
class NotNot(Expr):
|
||||||
"""1 if a is zero, otherwise 0"""
|
"""1 if a is zero, otherwise 0"""
|
||||||
def type(self, types={}):
|
def type(self, types={}):
|
||||||
return RInt
|
return CsvInt
|
||||||
|
|
||||||
def eval(self, fields={}):
|
def eval(self, fields={}):
|
||||||
if self.a.eval(fields):
|
if self.a.eval(fields):
|
||||||
return RInt(0)
|
return CsvInt(0)
|
||||||
else:
|
else:
|
||||||
return RInt(1)
|
return CsvInt(1)
|
||||||
|
|
||||||
# binary expr help
|
# binary expr help
|
||||||
def bop(op, prec):
|
def bop(op, prec):
|
||||||
@@ -981,54 +982,54 @@ class RExpr:
|
|||||||
"""1 if a equals b, otherwise 0"""
|
"""1 if a equals b, otherwise 0"""
|
||||||
def eval(self, fields={}):
|
def eval(self, fields={}):
|
||||||
if self.a.eval(fields) == self.b.eval(fields):
|
if self.a.eval(fields) == self.b.eval(fields):
|
||||||
return RInt(1)
|
return CsvInt(1)
|
||||||
else:
|
else:
|
||||||
return RInt(0)
|
return CsvInt(0)
|
||||||
|
|
||||||
@bop('!=', 4)
|
@bop('!=', 4)
|
||||||
class Ne(Expr):
|
class Ne(Expr):
|
||||||
"""1 if a does not equal b, otherwise 0"""
|
"""1 if a does not equal b, otherwise 0"""
|
||||||
def eval(self, fields={}):
|
def eval(self, fields={}):
|
||||||
if self.a.eval(fields) != self.b.eval(fields):
|
if self.a.eval(fields) != self.b.eval(fields):
|
||||||
return RInt(1)
|
return CsvInt(1)
|
||||||
else:
|
else:
|
||||||
return RInt(0)
|
return CsvInt(0)
|
||||||
|
|
||||||
@bop('<', 4)
|
@bop('<', 4)
|
||||||
class Lt(Expr):
|
class Lt(Expr):
|
||||||
"""1 if a is less than b"""
|
"""1 if a is less than b"""
|
||||||
def eval(self, fields={}):
|
def eval(self, fields={}):
|
||||||
if self.a.eval(fields) < self.b.eval(fields):
|
if self.a.eval(fields) < self.b.eval(fields):
|
||||||
return RInt(1)
|
return CsvInt(1)
|
||||||
else:
|
else:
|
||||||
return RInt(0)
|
return CsvInt(0)
|
||||||
|
|
||||||
@bop('<=', 4)
|
@bop('<=', 4)
|
||||||
class Le(Expr):
|
class Le(Expr):
|
||||||
"""1 if a is less than or equal to b"""
|
"""1 if a is less than or equal to b"""
|
||||||
def eval(self, fields={}):
|
def eval(self, fields={}):
|
||||||
if self.a.eval(fields) <= self.b.eval(fields):
|
if self.a.eval(fields) <= self.b.eval(fields):
|
||||||
return RInt(1)
|
return CsvInt(1)
|
||||||
else:
|
else:
|
||||||
return RInt(0)
|
return CsvInt(0)
|
||||||
|
|
||||||
@bop('>', 4)
|
@bop('>', 4)
|
||||||
class Gt(Expr):
|
class Gt(Expr):
|
||||||
"""1 if a is greater than b"""
|
"""1 if a is greater than b"""
|
||||||
def eval(self, fields={}):
|
def eval(self, fields={}):
|
||||||
if self.a.eval(fields) > self.b.eval(fields):
|
if self.a.eval(fields) > self.b.eval(fields):
|
||||||
return RInt(1)
|
return CsvInt(1)
|
||||||
else:
|
else:
|
||||||
return RInt(0)
|
return CsvInt(0)
|
||||||
|
|
||||||
@bop('>=', 4)
|
@bop('>=', 4)
|
||||||
class Ge(Expr):
|
class Ge(Expr):
|
||||||
"""1 if a is greater than or equal to b"""
|
"""1 if a is greater than or equal to b"""
|
||||||
def eval(self, fields={}):
|
def eval(self, fields={}):
|
||||||
if self.a.eval(fields) >= self.b.eval(fields):
|
if self.a.eval(fields) >= self.b.eval(fields):
|
||||||
return RInt(1)
|
return CsvInt(1)
|
||||||
else:
|
else:
|
||||||
return RInt(0)
|
return CsvInt(0)
|
||||||
|
|
||||||
@bop('&&', 3)
|
@bop('&&', 3)
|
||||||
class AndAnd(Expr):
|
class AndAnd(Expr):
|
||||||
@@ -1082,7 +1083,7 @@ class RExpr:
|
|||||||
t = self.b.type(types)
|
t = self.b.type(types)
|
||||||
u = self.c.type(types)
|
u = self.c.type(types)
|
||||||
if t != u:
|
if t != u:
|
||||||
raise RExpr.Error("mismatched types? %r" % self)
|
raise CsvExpr.Error("mismatched types? %r" % self)
|
||||||
return t
|
return t
|
||||||
|
|
||||||
def fold(self, types={}):
|
def fold(self, types={}):
|
||||||
@@ -1100,18 +1101,18 @@ class RExpr:
|
|||||||
def help(cls):
|
def help(cls):
|
||||||
print('uops:')
|
print('uops:')
|
||||||
for op in cls.uops.keys():
|
for op in cls.uops.keys():
|
||||||
print(' %-21s %s' % ('%sa' % op, RExpr.uops[op].__doc__))
|
print(' %-21s %s' % ('%sa' % op, CsvExpr.uops[op].__doc__))
|
||||||
print('bops:')
|
print('bops:')
|
||||||
for op in cls.bops.keys():
|
for op in cls.bops.keys():
|
||||||
print(' %-21s %s' % ('a %s b' % op, RExpr.bops[op].__doc__))
|
print(' %-21s %s' % ('a %s b' % op, CsvExpr.bops[op].__doc__))
|
||||||
print('tops:')
|
print('tops:')
|
||||||
for op in cls.tops.keys():
|
for op in cls.tops.keys():
|
||||||
print(' %-21s %s' % ('a %s b %s c' % op, RExpr.tops[op].__doc__))
|
print(' %-21s %s' % ('a %s b %s c' % op, CsvExpr.tops[op].__doc__))
|
||||||
print('funcs:')
|
print('funcs:')
|
||||||
for func in cls.funcs.keys():
|
for func in cls.funcs.keys():
|
||||||
print(' %-21s %s' % (
|
print(' %-21s %s' % (
|
||||||
'%s(%s)' % (func, RExpr.funcs[func]._fargs),
|
'%s(%s)' % (func, CsvExpr.funcs[func]._fargs),
|
||||||
RExpr.funcs[func].__doc__))
|
CsvExpr.funcs[func].__doc__))
|
||||||
|
|
||||||
# parse an expr
|
# parse an expr
|
||||||
def __init__(self, expr):
|
def __init__(self, expr):
|
||||||
@@ -1124,16 +1125,16 @@ class RExpr:
|
|||||||
p.chomp()
|
p.chomp()
|
||||||
a = p_expr(p)
|
a = p_expr(p)
|
||||||
if not p.match('\)'):
|
if not p.match('\)'):
|
||||||
raise RExpr.Error("mismatched parens? %s" % p)
|
raise CsvExpr.Error("mismatched parens? %s" % p)
|
||||||
p.chomp()
|
p.chomp()
|
||||||
|
|
||||||
# floats
|
# floats
|
||||||
elif p.match('[+-]?(?:[_0-9]*\.[_0-9eE]|nan)'):
|
elif p.match('[+-]?(?:[_0-9]*\.[_0-9eE]|nan)'):
|
||||||
a = RExpr.FloatLit(RFloat(p.chomp()))
|
a = CsvExpr.FloatLit(CsvFloat(p.chomp()))
|
||||||
|
|
||||||
# ints
|
# ints
|
||||||
elif p.match('[+-]?(?:[0-9][bBoOxX]?[_0-9a-fA-F]*|∞|inf)'):
|
elif p.match('[+-]?(?:[0-9][bBoOxX]?[_0-9a-fA-F]*|∞|inf)'):
|
||||||
a = RExpr.IntLit(RInt(p.chomp()))
|
a = CsvExpr.IntLit(CsvInt(p.chomp()))
|
||||||
|
|
||||||
# fields/functions
|
# fields/functions
|
||||||
elif p.match('[_a-zA-Z][_a-zA-Z0-9]*'):
|
elif p.match('[_a-zA-Z][_a-zA-Z0-9]*'):
|
||||||
@@ -1141,8 +1142,8 @@ class RExpr:
|
|||||||
|
|
||||||
if p.match('\('):
|
if p.match('\('):
|
||||||
p.chomp()
|
p.chomp()
|
||||||
if a not in RExpr.funcs:
|
if a not in CsvExpr.funcs:
|
||||||
raise RExpr.Error("unknown function? %s" % a)
|
raise CsvExpr.Error("unknown function? %s" % a)
|
||||||
args = []
|
args = []
|
||||||
while True:
|
while True:
|
||||||
b = p_expr(p)
|
b = p_expr(p)
|
||||||
@@ -1152,62 +1153,62 @@ class RExpr:
|
|||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
if not p.match('\)'):
|
if not p.match('\)'):
|
||||||
raise RExpr.Error("mismatched parens? %s" % p)
|
raise CsvExpr.Error("mismatched parens? %s" % p)
|
||||||
p.chomp()
|
p.chomp()
|
||||||
a = RExpr.funcs[a](*args)
|
a = CsvExpr.funcs[a](*args)
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
a = RExpr.Field(a)
|
a = CsvExpr.Field(a)
|
||||||
|
|
||||||
# unary ops
|
# unary ops
|
||||||
elif any(p.match(re.escape(op)) for op in RExpr.uops.keys()):
|
elif any(p.match(re.escape(op)) for op in CsvExpr.uops.keys()):
|
||||||
# sort by len to avoid ambiguities
|
# sort by len to avoid ambiguities
|
||||||
for op in sorted(RExpr.uops.keys(), reverse=True):
|
for op in sorted(CsvExpr.uops.keys(), reverse=True):
|
||||||
if p.match(re.escape(op)):
|
if p.match(re.escape(op)):
|
||||||
p.chomp()
|
p.chomp()
|
||||||
a = p_expr(p, mt.inf)
|
a = p_expr(p, mt.inf)
|
||||||
a = RExpr.uops[op](a)
|
a = CsvExpr.uops[op](a)
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
assert False
|
assert False
|
||||||
|
|
||||||
# unknown expr?
|
# unknown expr?
|
||||||
else:
|
else:
|
||||||
raise RExpr.Error("unknown expr? %s" % p)
|
raise CsvExpr.Error("unknown expr? %s" % p)
|
||||||
|
|
||||||
# parse tail
|
# parse tail
|
||||||
while True:
|
while True:
|
||||||
# binary ops
|
# binary ops
|
||||||
if any(p.match(re.escape(op))
|
if any(p.match(re.escape(op))
|
||||||
and prec < RExpr.bprecs[op]
|
and prec < CsvExpr.bprecs[op]
|
||||||
for op in RExpr.bops.keys()):
|
for op in CsvExpr.bops.keys()):
|
||||||
# sort by len to avoid ambiguities
|
# sort by len to avoid ambiguities
|
||||||
for op in sorted(RExpr.bops.keys(), reverse=True):
|
for op in sorted(CsvExpr.bops.keys(), reverse=True):
|
||||||
if (p.match(re.escape(op))
|
if (p.match(re.escape(op))
|
||||||
and prec < RExpr.bprecs[op]):
|
and prec < CsvExpr.bprecs[op]):
|
||||||
p.chomp()
|
p.chomp()
|
||||||
b = p_expr(p, RExpr.bprecs[op])
|
b = p_expr(p, CsvExpr.bprecs[op])
|
||||||
a = RExpr.bops[op](a, b)
|
a = CsvExpr.bops[op](a, b)
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
assert False
|
assert False
|
||||||
|
|
||||||
# ternary ops, these are intentionally right associative
|
# ternary ops, these are intentionally right associative
|
||||||
elif any(p.match(re.escape(op[0]))
|
elif any(p.match(re.escape(op[0]))
|
||||||
and prec <= RExpr.tprecs[op]
|
and prec <= CsvExpr.tprecs[op]
|
||||||
for op in RExpr.tops.keys()):
|
for op in CsvExpr.tops.keys()):
|
||||||
# sort by len to avoid ambiguities
|
# sort by len to avoid ambiguities
|
||||||
for op in sorted(RExpr.tops.keys(), reverse=True):
|
for op in sorted(CsvExpr.tops.keys(), reverse=True):
|
||||||
if (p.match(re.escape(op[0]))
|
if (p.match(re.escape(op[0]))
|
||||||
and prec <= RExpr.tprecs[op]):
|
and prec <= CsvExpr.tprecs[op]):
|
||||||
p.chomp()
|
p.chomp()
|
||||||
b = p_expr(p, RExpr.tprecs[op])
|
b = p_expr(p, CsvExpr.tprecs[op])
|
||||||
if not p.match(re.escape(op[1])):
|
if not p.match(re.escape(op[1])):
|
||||||
raise RExpr.Error(
|
raise CsvExpr.Error(
|
||||||
'mismatched ternary op? %s %s' % op)
|
'mismatched ternary op? %s %s' % op)
|
||||||
p.chomp()
|
p.chomp()
|
||||||
c = p_expr(p, RExpr.tprecs[op])
|
c = p_expr(p, CsvExpr.tprecs[op])
|
||||||
a = RExpr.tops[op](a, b, c)
|
a = CsvExpr.tops[op](a, b, c)
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
assert False
|
assert False
|
||||||
@@ -1220,9 +1221,9 @@ class RExpr:
|
|||||||
p = Parser(self.expr)
|
p = Parser(self.expr)
|
||||||
self.tree = p_expr(p)
|
self.tree = p_expr(p)
|
||||||
if p:
|
if p:
|
||||||
raise RExpr.Error("trailing expr? %s" % p)
|
raise CsvExpr.Error("trailing expr? %s" % p)
|
||||||
|
|
||||||
except (RExpr.Error, ValueError) as e:
|
except (CsvExpr.Error, ValueError) as e:
|
||||||
print('error: in expr: %s' % self.expr,
|
print('error: in expr: %s' % self.expr,
|
||||||
file=sys.stderr)
|
file=sys.stderr)
|
||||||
print('error: %s' % e,
|
print('error: %s' % e,
|
||||||
@@ -1233,7 +1234,7 @@ class RExpr:
|
|||||||
def fields(self):
|
def fields(self):
|
||||||
try:
|
try:
|
||||||
return self.tree.fields()
|
return self.tree.fields()
|
||||||
except RExpr.Error as e:
|
except CsvExpr.Error as e:
|
||||||
print('error: in expr: %s' % self.expr,
|
print('error: in expr: %s' % self.expr,
|
||||||
file=sys.stderr)
|
file=sys.stderr)
|
||||||
print('error: %s' % e,
|
print('error: %s' % e,
|
||||||
@@ -1244,7 +1245,7 @@ class RExpr:
|
|||||||
def type(self, types={}):
|
def type(self, types={}):
|
||||||
try:
|
try:
|
||||||
return self.tree.type(types)
|
return self.tree.type(types)
|
||||||
except RExpr.Error as e:
|
except CsvExpr.Error as e:
|
||||||
print('error: in expr: %s' % self.expr,
|
print('error: in expr: %s' % self.expr,
|
||||||
file=sys.stderr)
|
file=sys.stderr)
|
||||||
print('error: %s' % e,
|
print('error: %s' % e,
|
||||||
@@ -1255,7 +1256,7 @@ class RExpr:
|
|||||||
def fold(self, types={}):
|
def fold(self, types={}):
|
||||||
try:
|
try:
|
||||||
return self.tree.fold(types)
|
return self.tree.fold(types)
|
||||||
except RExpr.Error as e:
|
except CsvExpr.Error as e:
|
||||||
print('error: in expr: %s' % self.expr,
|
print('error: in expr: %s' % self.expr,
|
||||||
file=sys.stderr)
|
file=sys.stderr)
|
||||||
print('error: %s' % e,
|
print('error: %s' % e,
|
||||||
@@ -1266,7 +1267,7 @@ class RExpr:
|
|||||||
def eval(self, fields={}):
|
def eval(self, fields={}):
|
||||||
try:
|
try:
|
||||||
return self.tree.eval(fields)
|
return self.tree.eval(fields)
|
||||||
except RExpr.Error as e:
|
except CsvExpr.Error as e:
|
||||||
print('error: in expr: %s' % self.expr,
|
print('error: in expr: %s' % self.expr,
|
||||||
file=sys.stderr)
|
file=sys.stderr)
|
||||||
print('error: %s' % e,
|
print('error: %s' % e,
|
||||||
@@ -1465,7 +1466,7 @@ def compile(fields_, results,
|
|||||||
file=sys.stderr)
|
file=sys.stderr)
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
for t in [RInt, RFloat, RFrac]:
|
for t in [CsvInt, CsvFloat, CsvFrac]:
|
||||||
for r in results:
|
for r in results:
|
||||||
if prefix+k in r and r[prefix+k].strip():
|
if prefix+k in r and r[prefix+k].strip():
|
||||||
try:
|
try:
|
||||||
@@ -1487,7 +1488,7 @@ def compile(fields_, results,
|
|||||||
types___[k] = expr.type(types__)
|
types___[k] = expr.type(types__)
|
||||||
|
|
||||||
# foldcheck field exprs
|
# foldcheck field exprs
|
||||||
folds___ = {k: (RSum, t) for k, v in types__.items()}
|
folds___ = {k: (CsvSum, t) for k, v in types__.items()}
|
||||||
for k, expr in exprs.items():
|
for k, expr in exprs.items():
|
||||||
folds___[k] = expr.fold(types__)
|
folds___[k] = expr.fold(types__)
|
||||||
folds___ = {k: (f(), t) for k, (f, t) in folds___.items()}
|
folds___ = {k: (f(), t) for k, (f, t) in folds___.items()}
|
||||||
@@ -2184,7 +2185,7 @@ def main(csv_paths, *,
|
|||||||
return punescape_help()
|
return punescape_help()
|
||||||
# show expr help text?
|
# show expr help text?
|
||||||
if args.get('help_exprs'):
|
if args.get('help_exprs'):
|
||||||
return RExpr.help()
|
return CsvExpr.help()
|
||||||
|
|
||||||
if by is None and fields is None:
|
if by is None and fields is None:
|
||||||
print("error: needs --by or --fields to figure out fields",
|
print("error: needs --by or --fields to figure out fields",
|
||||||
@@ -2490,7 +2491,7 @@ if __name__ == "__main__":
|
|||||||
type=lambda x: (
|
type=lambda x: (
|
||||||
lambda k, v=None: (
|
lambda k, v=None: (
|
||||||
k.strip(),
|
k.strip(),
|
||||||
RExpr(v) if v is not None else None)
|
CsvExpr(v) if v is not None else None)
|
||||||
)(*x.split('=', 1)),
|
)(*x.split('=', 1)),
|
||||||
help="Show this field. Can include an expression of the form "
|
help="Show this field. Can include an expression of the form "
|
||||||
"field=expr.")
|
"field=expr.")
|
||||||
@@ -2527,7 +2528,7 @@ if __name__ == "__main__":
|
|||||||
type=lambda x: (
|
type=lambda x: (
|
||||||
lambda k, v=None: (
|
lambda k, v=None: (
|
||||||
k.strip(),
|
k.strip(),
|
||||||
RExpr(v) if v is not None else None)
|
CsvExpr(v) if v is not None else None)
|
||||||
)(*x.split('=', 1)),
|
)(*x.split('=', 1)),
|
||||||
const=(None, None),
|
const=(None, None),
|
||||||
help="Sort by this field. Can include an expression of the form "
|
help="Sort by this field. Can include an expression of the form "
|
||||||
@@ -2539,7 +2540,7 @@ if __name__ == "__main__":
|
|||||||
type=lambda x: (
|
type=lambda x: (
|
||||||
lambda k, v=None: (
|
lambda k, v=None: (
|
||||||
k.strip(),
|
k.strip(),
|
||||||
RExpr(v) if v is not None else None)
|
CsvExpr(v) if v is not None else None)
|
||||||
)(*x.split('=', 1)),
|
)(*x.split('=', 1)),
|
||||||
const=(None, None),
|
const=(None, None),
|
||||||
help="Sort by this field, but backwards. Can include an expression "
|
help="Sort by this field, but backwards. Can include an expression "
|
||||||
@@ -2570,7 +2571,7 @@ if __name__ == "__main__":
|
|||||||
type=lambda x: (
|
type=lambda x: (
|
||||||
lambda k, v=None: (
|
lambda k, v=None: (
|
||||||
k.strip(),
|
k.strip(),
|
||||||
RExpr(v) if v is not None else None)
|
CsvExpr(v) if v is not None else None)
|
||||||
)(*x.split('=', 1)),
|
)(*x.split('=', 1)),
|
||||||
const=(None, None),
|
const=(None, None),
|
||||||
help="Show only the hot path for each function call. Can "
|
help="Show only the hot path for each function call. Can "
|
||||||
@@ -2583,7 +2584,7 @@ if __name__ == "__main__":
|
|||||||
type=lambda x: (
|
type=lambda x: (
|
||||||
lambda k, v=None: (
|
lambda k, v=None: (
|
||||||
k.strip(),
|
k.strip(),
|
||||||
RExpr(v) if v is not None else None)
|
CsvExpr(v) if v is not None else None)
|
||||||
)(*x.split('=', 1)),
|
)(*x.split('=', 1)),
|
||||||
const=(None, None),
|
const=(None, None),
|
||||||
help="Like -r/--hot, but backwards.")
|
help="Like -r/--hot, but backwards.")
|
||||||
|
|||||||
+5
-5
@@ -30,10 +30,10 @@ OBJDUMP_PATH = ['objdump']
|
|||||||
|
|
||||||
|
|
||||||
# integer fields
|
# integer fields
|
||||||
class RInt(co.namedtuple('RInt', 'x')):
|
class CsvInt(co.namedtuple('CsvInt', 'x')):
|
||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
def __new__(cls, x=0):
|
def __new__(cls, x=0):
|
||||||
if isinstance(x, RInt):
|
if isinstance(x, CsvInt):
|
||||||
return x
|
return x
|
||||||
if isinstance(x, str):
|
if isinstance(x, str):
|
||||||
try:
|
try:
|
||||||
@@ -140,7 +140,7 @@ class CtxResult(co.namedtuple('CtxResult', [
|
|||||||
_by = ['z', 'i', 'file', 'function']
|
_by = ['z', 'i', 'file', 'function']
|
||||||
_fields = ['off', 'size']
|
_fields = ['off', 'size']
|
||||||
_sort = ['size']
|
_sort = ['size']
|
||||||
_types = {'off': RInt, 'size': RInt}
|
_types = {'off': CsvInt, 'size': CsvInt}
|
||||||
_children = 'children'
|
_children = 'children'
|
||||||
_notes = 'notes'
|
_notes = 'notes'
|
||||||
|
|
||||||
@@ -148,7 +148,7 @@ class CtxResult(co.namedtuple('CtxResult', [
|
|||||||
def __new__(cls, z=0, i=0, file='', function='', off=0, size=0,
|
def __new__(cls, z=0, i=0, file='', function='', off=0, size=0,
|
||||||
children=None, notes=None):
|
children=None, notes=None):
|
||||||
return super().__new__(cls, z, i, file, function,
|
return super().__new__(cls, z, i, file, function,
|
||||||
RInt(off), RInt(size),
|
CsvInt(off), CsvInt(size),
|
||||||
children if children is not None else [],
|
children if children is not None else [],
|
||||||
notes if notes is not None else set())
|
notes if notes is not None else set())
|
||||||
|
|
||||||
@@ -703,7 +703,7 @@ def collect_ctx(obj_paths, *,
|
|||||||
name = name.split('.', 1)[0]
|
name = name.split('.', 1)[0]
|
||||||
|
|
||||||
# context = sum of params
|
# context = sum of params
|
||||||
size = sum((param.size for param in params), start=RInt(0))
|
size = sum((param.size for param in params), start=CsvInt(0))
|
||||||
|
|
||||||
results.append(CtxResult(
|
results.append(CtxResult(
|
||||||
0, 0, file, name, 0, size,
|
0, 0, file, name, 0, size,
|
||||||
|
|||||||
+4
-4
@@ -34,10 +34,10 @@ SECTIONS = ['.data', '.bss']
|
|||||||
|
|
||||||
|
|
||||||
# integer fields
|
# integer fields
|
||||||
class RInt(co.namedtuple('RInt', 'x')):
|
class CsvInt(co.namedtuple('CsvInt', 'x')):
|
||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
def __new__(cls, x=0):
|
def __new__(cls, x=0):
|
||||||
if isinstance(x, RInt):
|
if isinstance(x, CsvInt):
|
||||||
return x
|
return x
|
||||||
if isinstance(x, str):
|
if isinstance(x, str):
|
||||||
try:
|
try:
|
||||||
@@ -143,12 +143,12 @@ class DataResult(co.namedtuple('DataResult', [
|
|||||||
_by = ['file', 'function']
|
_by = ['file', 'function']
|
||||||
_fields = ['size']
|
_fields = ['size']
|
||||||
_sort = ['size']
|
_sort = ['size']
|
||||||
_types = {'size': RInt}
|
_types = {'size': CsvInt}
|
||||||
|
|
||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
def __new__(cls, file='', function='', size=0):
|
def __new__(cls, file='', function='', size=0):
|
||||||
return super().__new__(cls, file, function,
|
return super().__new__(cls, file, function,
|
||||||
RInt(size))
|
CsvInt(size))
|
||||||
|
|
||||||
def __add__(self, other):
|
def __add__(self, other):
|
||||||
return DataResult(self.file, self.function,
|
return DataResult(self.file, self.function,
|
||||||
|
|||||||
+9
-9
@@ -44,10 +44,10 @@ THRESHOLD = (0.5, 0.85)
|
|||||||
|
|
||||||
|
|
||||||
# integer fields
|
# integer fields
|
||||||
class RInt(co.namedtuple('RInt', 'x')):
|
class CsvInt(co.namedtuple('CsvInt', 'x')):
|
||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
def __new__(cls, x=0):
|
def __new__(cls, x=0):
|
||||||
if isinstance(x, RInt):
|
if isinstance(x, CsvInt):
|
||||||
return x
|
return x
|
||||||
if isinstance(x, str):
|
if isinstance(x, str):
|
||||||
try:
|
try:
|
||||||
@@ -155,19 +155,19 @@ class PerfResult(co.namedtuple('PerfResult', [
|
|||||||
_fields = ['cycles', 'bmisses', 'branches', 'cmisses', 'caches']
|
_fields = ['cycles', 'bmisses', 'branches', 'cmisses', 'caches']
|
||||||
_sort = ['cycles', 'bmisses', 'cmisses', 'branches', 'caches']
|
_sort = ['cycles', 'bmisses', 'cmisses', 'branches', 'caches']
|
||||||
_types = {
|
_types = {
|
||||||
'cycles': RInt,
|
'cycles': CsvInt,
|
||||||
'bmisses': RInt, 'branches': RInt,
|
'bmisses': CsvInt, 'branches': CsvInt,
|
||||||
'cmisses': RInt, 'caches': RInt}
|
'cmisses': CsvInt, 'caches': CsvInt}
|
||||||
_children = 'children'
|
_children = 'children'
|
||||||
|
|
||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
def __new__(cls, z=0, file='', function='', line=0,
|
def __new__(cls, z=0, file='', function='', line=0,
|
||||||
cycles=0, bmisses=0, branches=0, cmisses=0, caches=0,
|
cycles=0, bmisses=0, branches=0, cmisses=0, caches=0,
|
||||||
children=None):
|
children=None):
|
||||||
return super().__new__(cls, z, file, function, int(RInt(line)),
|
return super().__new__(cls, z, file, function, int(CsvInt(line)),
|
||||||
RInt(cycles),
|
CsvInt(cycles),
|
||||||
RInt(bmisses), RInt(branches),
|
CsvInt(bmisses), CsvInt(branches),
|
||||||
RInt(cmisses), RInt(caches),
|
CsvInt(cmisses), CsvInt(caches),
|
||||||
children if children is not None else [])
|
children if children is not None else [])
|
||||||
|
|
||||||
def __add__(self, other):
|
def __add__(self, other):
|
||||||
|
|||||||
+5
-5
@@ -35,10 +35,10 @@ THRESHOLD = (0.5, 0.85)
|
|||||||
|
|
||||||
|
|
||||||
# integer fields
|
# integer fields
|
||||||
class RInt(co.namedtuple('RInt', 'x')):
|
class CsvInt(co.namedtuple('CsvInt', 'x')):
|
||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
def __new__(cls, x=0):
|
def __new__(cls, x=0):
|
||||||
if isinstance(x, RInt):
|
if isinstance(x, CsvInt):
|
||||||
return x
|
return x
|
||||||
if isinstance(x, str):
|
if isinstance(x, str):
|
||||||
try:
|
try:
|
||||||
@@ -145,15 +145,15 @@ class PerfBdResult(co.namedtuple('PerfBdResult', [
|
|||||||
_by = ['z', 'file', 'function', 'line']
|
_by = ['z', 'file', 'function', 'line']
|
||||||
_fields = ['readed', 'proged', 'erased']
|
_fields = ['readed', 'proged', 'erased']
|
||||||
_sort = ['erased', 'proged', 'readed']
|
_sort = ['erased', 'proged', 'readed']
|
||||||
_types = {'readed': RInt, 'proged': RInt, 'erased': RInt}
|
_types = {'readed': CsvInt, 'proged': CsvInt, 'erased': CsvInt}
|
||||||
_children = 'children'
|
_children = 'children'
|
||||||
|
|
||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
def __new__(cls, z=0, file='', function='', line=0,
|
def __new__(cls, z=0, file='', function='', line=0,
|
||||||
readed=0, proged=0, erased=0,
|
readed=0, proged=0, erased=0,
|
||||||
children=None):
|
children=None):
|
||||||
return super().__new__(cls, z, file, function, int(RInt(line)),
|
return super().__new__(cls, z, file, function, int(CsvInt(line)),
|
||||||
RInt(readed), RInt(proged), RInt(erased),
|
CsvInt(readed), CsvInt(proged), CsvInt(erased),
|
||||||
children if children is not None else [])
|
children if children is not None else [])
|
||||||
|
|
||||||
def __add__(self, other):
|
def __add__(self, other):
|
||||||
|
|||||||
+4
-4
@@ -30,10 +30,10 @@ OBJDUMP_PATH = ['objdump']
|
|||||||
|
|
||||||
|
|
||||||
# integer fields
|
# integer fields
|
||||||
class RInt(co.namedtuple('RInt', 'x')):
|
class CsvInt(co.namedtuple('CsvInt', 'x')):
|
||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
def __new__(cls, x=0):
|
def __new__(cls, x=0):
|
||||||
if isinstance(x, RInt):
|
if isinstance(x, CsvInt):
|
||||||
return x
|
return x
|
||||||
if isinstance(x, str):
|
if isinstance(x, str):
|
||||||
try:
|
try:
|
||||||
@@ -140,7 +140,7 @@ class StackResult(co.namedtuple('StackResult', [
|
|||||||
_by = ['z', 'file', 'function']
|
_by = ['z', 'file', 'function']
|
||||||
_fields = ['frame', 'limit']
|
_fields = ['frame', 'limit']
|
||||||
_sort = ['limit', 'frame']
|
_sort = ['limit', 'frame']
|
||||||
_types = {'frame': RInt, 'limit': RInt}
|
_types = {'frame': CsvInt, 'limit': CsvInt}
|
||||||
_children = 'children'
|
_children = 'children'
|
||||||
_notes = 'notes'
|
_notes = 'notes'
|
||||||
|
|
||||||
@@ -148,7 +148,7 @@ class StackResult(co.namedtuple('StackResult', [
|
|||||||
def __new__(cls, z=0, file='', function='', frame=0, limit=0,
|
def __new__(cls, z=0, file='', function='', frame=0, limit=0,
|
||||||
children=None, notes=None):
|
children=None, notes=None):
|
||||||
return super().__new__(cls, z, file, function,
|
return super().__new__(cls, z, file, function,
|
||||||
RInt(frame), RInt(limit),
|
CsvInt(frame), CsvInt(limit),
|
||||||
children if children is not None else [],
|
children if children is not None else [],
|
||||||
notes if notes is not None else set())
|
notes if notes is not None else set())
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -30,10 +30,10 @@ OBJDUMP_PATH = ['objdump']
|
|||||||
|
|
||||||
|
|
||||||
# integer fields
|
# integer fields
|
||||||
class RInt(co.namedtuple('RInt', 'x')):
|
class CsvInt(co.namedtuple('CsvInt', 'x')):
|
||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
def __new__(cls, x=0):
|
def __new__(cls, x=0):
|
||||||
if isinstance(x, RInt):
|
if isinstance(x, CsvInt):
|
||||||
return x
|
return x
|
||||||
if isinstance(x, str):
|
if isinstance(x, str):
|
||||||
try:
|
try:
|
||||||
@@ -140,14 +140,14 @@ class StructResult(co.namedtuple('StructResult', [
|
|||||||
_by = ['z', 'i', 'file', 'struct']
|
_by = ['z', 'i', 'file', 'struct']
|
||||||
_fields = ['off', 'size', 'align']
|
_fields = ['off', 'size', 'align']
|
||||||
_sort = ['size', 'align']
|
_sort = ['size', 'align']
|
||||||
_types = {'off': RInt, 'size': RInt, 'align': RInt}
|
_types = {'off': CsvInt, 'size': CsvInt, 'align': CsvInt}
|
||||||
_children = 'children'
|
_children = 'children'
|
||||||
|
|
||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
def __new__(cls, z=0, i=0, file='', struct='', off=0, size=0, align=0,
|
def __new__(cls, z=0, i=0, file='', struct='', off=0, size=0, align=0,
|
||||||
children=None):
|
children=None):
|
||||||
return super().__new__(cls, z, i, file, struct,
|
return super().__new__(cls, z, i, file, struct,
|
||||||
RInt(off), RInt(size), RInt(align),
|
CsvInt(off), CsvInt(size), CsvInt(align),
|
||||||
children if children is not None else [])
|
children if children is not None else [])
|
||||||
|
|
||||||
def __add__(self, other):
|
def __add__(self, other):
|
||||||
|
|||||||
Reference in New Issue
Block a user