Skip to content

Commit

Permalink
Merge e9ca6da into d945781
Browse files Browse the repository at this point in the history
  • Loading branch information
cdonovick committed Jun 27, 2019
2 parents d945781 + e9ca6da commit 4b05771
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 31 deletions.
10 changes: 1 addition & 9 deletions hwtypes/bit_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,7 @@ def ite(self, t_branch, f_branch):
t_branch = fb_t(t_branch)
T = fb_t
else:
t_branch = BV_t(t_branch)
f_branch = BV_t(f_branch)
ext = t_branch.size - f_branch.size
if ext > 0:
f_branch = f_branch.zext(ext)
elif ext < 0:
t_branch = t_branch.zext(-ext)

T = type(t_branch)
raise TypeError(f'Atleast one branch must be a {self.get_family().BitVector}')


return t_branch if self else f_branch
Expand Down
13 changes: 4 additions & 9 deletions hwtypes/bit_vector_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,14 @@ class AbstractBitVectorMeta(ABCMeta):
# BitVectorType, size : BitVectorType[size]
_class_cache = weakref.WeakValueDictionary()

def __call__(cls, value=_MISSING, size=_MISSING, *args, **kwargs):
if cls.is_sized and size is not _MISSING:
raise TypeError('Cannot use old style construction on sized types')
elif cls.is_sized:
def __call__(cls, value=_MISSING, *args, **kwargs):
if cls.is_sized:
if value is _MISSING:
return super().__call__(*args, **kwargs)
else:
return super().__call__(value, *args, **kwargs)
elif size is _MISSING or size is None:
if size is None:
warnings.warn('DEPRECATION WARNING: Use of BitVectorT(value, size) is deprecated')
else:
warnings.warn('DEPRECATION WARNING: Use of implicitly sized BitVectors is deprecated')

if value is _MISSING:
raise TypeError('Cannot construct {} without a value'.format(cls, value))
Expand All @@ -41,8 +38,6 @@ def __call__(cls, value=_MISSING, size=_MISSING, *args, **kwargs):
size = max(int(value).bit_length(), 1)
else:
raise TypeError('Cannot construct {} from {}'.format(cls, value))
else:
warnings.warn('DEPRECATION WARNING: Use of BitVectorT(value, size) is deprecated')

return type(cls).__call__(cls[size], value)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_bv.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def test_eq():


def test_setitem():
bv = BitVector(5)
bv = BitVector[3](5)
assert bv.as_uint() ==5
bv[0] = 0
assert repr(bv) == 'BitVector[3](4)'
Expand Down
4 changes: 0 additions & 4 deletions tests/test_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ class C(A, B): pass
with pytest.raises(TypeError):
C[6]

x = BV(5)
assert x.size == 3
assert type(x).size == 3

def test_instance():
x = BV[8](0)
assert isinstance(x, ABV)
Expand Down
10 changes: 2 additions & 8 deletions tests/test_optypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,13 @@ def test_ite(t_constructor, t_size, f_constructor, f_size):
if t_constructor is f_constructor is _rand_bv and t_size == f_size:
res = pred.ite(t, f)
assert type(res) is type(t)
elif t_constructor is f_constructor is _rand_bv:
elif t_constructor is f_constructor:
# either both ints or BV with different size
with pytest.raises(TypeError):
res = pred.ite(t, f)
elif t_constructor is f_constructor: #rand int
res = pred.ite(t, f)
t_size = max(t.bit_length(), 1)
f_size = max(f.bit_length(), 1)
assert type(res) is BitVector[max(t_size, f_size)]
elif t_constructor is _rand_bv:
res = pred.ite(t, f)
assert type(res) is BitVector[t_size]
else: #t_constructor is _rand_int
print(type(t), t, t_constructor, t_size)
print(type(f), f, f_constructor, f_size)
res = pred.ite(t, f)
assert type(res) is BitVector[f_size]

0 comments on commit 4b05771

Please sign in to comment.