1
0
mirror of https://github.com/myhdl/myhdl.git synced 2024-12-14 07:44:38 +08:00

Made Signal and intbv hashable on the undelying value

This commit is contained in:
jand 2003-03-05 17:40:14 +00:00
parent 952989137e
commit f7720916b5
8 changed files with 7 additions and 17 deletions

View File

@ -44,6 +44,7 @@ def mux(z, a, b, sel):
z.next = a z.next = a
else: else:
z.next = b z.next = b
\end{verbatim} \end{verbatim}
To verify, let's simulate this logic with some random patterns. The To verify, let's simulate this logic with some random patterns. The
@ -191,10 +192,8 @@ enable count
0 1 0 1
1 2 1 2
StopSimulation StopSimulation
\end{verbatim} \end{verbatim}
\section{High level modeling} \section{High level modeling}
\emph{Empty} \emph{Empty}

View File

@ -136,7 +136,7 @@ class Signal(object):
# hashing not supported # hashing not supported
def __hash__(self): def __hash__(self):
assert TypeError, "Signal objects are unhashable" return hash(self._val)
### operators for which delegation to current value is appropriate ### ### operators for which delegation to current value is appropriate ###

View File

@ -102,8 +102,6 @@ In the following, a "sig" denotes an instance of the Signal class.
* A sig should have no other public attributes than those described * A sig should have no other public attributes than those described
above. above.
* Signal objects are unhashable.
* In practice, Signals will often have numbers as their underlying * In practice, Signals will often have numbers as their underlying
values. As a matter of convenience, the special Python object values. As a matter of convenience, the special Python object
methods for numeric and bitwise operators are supported on Signal methods for numeric and bitwise operators are supported on Signal

View File

@ -24,6 +24,7 @@ __version__ = "$Revision$"
__date__ = "$Date$" __date__ = "$Date$"
from __future__ import generators from __future__ import generators
import sys
import exceptions import exceptions
import _simulator as sim import _simulator as sim
@ -127,7 +128,9 @@ class Simulation:
except StopSimulation, e: except StopSimulation, e:
if not quiet: if not quiet:
msg = "StopSimulation" kind, value, traceback = sys.exc_info()
msg = str(kind)
msg = msg[msg.rindex('.')+1:]
if str(e): if str(e):
msg += ": %s" % e msg += ": %s" % e
print msg print msg

View File

@ -71,7 +71,7 @@ class intbv(object):
# hash # hash
def __hash__(self): def __hash__(self):
raise TypeError, "intbv objects are unhashable" return hash(self._val)
# copy methods # copy methods
def __copy__(self): def __copy__(self):

View File

@ -80,4 +80,3 @@ separate type.
* intbv supports the iterator protocol to iterate on its bits; again, * intbv supports the iterator protocol to iterate on its bits; again,
this requires a known length. this requires a known length.
* intbv objects are unhashable

View File

@ -37,10 +37,6 @@ from Signal import Signal
from _simulator import _siglist from _simulator import _siglist
from intbv import intbv from intbv import intbv
class TestSignalUnhashable(TestCase):
def testSignalUnhashable(self):
self.assertRaises(TypeError, hash, Signal(3))
class SigTest(TestCase): class SigTest(TestCase):

View File

@ -35,11 +35,6 @@ import operator
from intbv import intbv from intbv import intbv
concat = intbv.concat concat = intbv.concat
class TestIntbvUnhashable(TestCase):
def testIntbvUnhashable(self):
self.assertRaises(TypeError, hash, intbv(3))
class TestIntbvConcat(TestCase): class TestIntbvConcat(TestCase):