From f7720916b55f05582db5eb7b02c68883971b3945 Mon Sep 17 00:00:00 2001 From: jand Date: Wed, 5 Mar 2003 17:40:14 +0000 Subject: [PATCH] Made Signal and intbv hashable on the undelying value --- doc/modeling.tex | 3 +-- myhdl/Signal.py | 2 +- myhdl/Signal_spec.txt | 2 -- myhdl/Simulation.py | 5 ++++- myhdl/intbv.py | 2 +- myhdl/intbv_spec.txt | 1 - myhdl/test_Signal.py | 4 ---- myhdl/test_intbv.py | 5 ----- 8 files changed, 7 insertions(+), 17 deletions(-) diff --git a/doc/modeling.tex b/doc/modeling.tex index 8c4cc6a7..941302c3 100644 --- a/doc/modeling.tex +++ b/doc/modeling.tex @@ -44,6 +44,7 @@ def mux(z, a, b, sel): z.next = a else: z.next = b + \end{verbatim} To verify, let's simulate this logic with some random patterns. The @@ -191,10 +192,8 @@ enable count 0 1 1 2 StopSimulation - \end{verbatim} - \section{High level modeling} \emph{Empty} diff --git a/myhdl/Signal.py b/myhdl/Signal.py index 87ca2e2e..a06df77e 100644 --- a/myhdl/Signal.py +++ b/myhdl/Signal.py @@ -136,7 +136,7 @@ class Signal(object): # hashing not supported def __hash__(self): - assert TypeError, "Signal objects are unhashable" + return hash(self._val) ### operators for which delegation to current value is appropriate ### diff --git a/myhdl/Signal_spec.txt b/myhdl/Signal_spec.txt index 46db32b6..94babe03 100644 --- a/myhdl/Signal_spec.txt +++ b/myhdl/Signal_spec.txt @@ -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 above. -* Signal objects are unhashable. - * In practice, Signals will often have numbers as their underlying values. As a matter of convenience, the special Python object methods for numeric and bitwise operators are supported on Signal diff --git a/myhdl/Simulation.py b/myhdl/Simulation.py index ddb01726..10eaa8ec 100644 --- a/myhdl/Simulation.py +++ b/myhdl/Simulation.py @@ -24,6 +24,7 @@ __version__ = "$Revision$" __date__ = "$Date$" from __future__ import generators +import sys import exceptions import _simulator as sim @@ -127,7 +128,9 @@ class Simulation: except StopSimulation, e: if not quiet: - msg = "StopSimulation" + kind, value, traceback = sys.exc_info() + msg = str(kind) + msg = msg[msg.rindex('.')+1:] if str(e): msg += ": %s" % e print msg diff --git a/myhdl/intbv.py b/myhdl/intbv.py index c75fc8c3..37a528ff 100644 --- a/myhdl/intbv.py +++ b/myhdl/intbv.py @@ -71,7 +71,7 @@ class intbv(object): # hash def __hash__(self): - raise TypeError, "intbv objects are unhashable" + return hash(self._val) # copy methods def __copy__(self): diff --git a/myhdl/intbv_spec.txt b/myhdl/intbv_spec.txt index 03038143..7b490e45 100644 --- a/myhdl/intbv_spec.txt +++ b/myhdl/intbv_spec.txt @@ -80,4 +80,3 @@ separate type. * intbv supports the iterator protocol to iterate on its bits; again, this requires a known length. -* intbv objects are unhashable diff --git a/myhdl/test_Signal.py b/myhdl/test_Signal.py index bf44ca52..76ba915c 100644 --- a/myhdl/test_Signal.py +++ b/myhdl/test_Signal.py @@ -37,10 +37,6 @@ from Signal import Signal from _simulator import _siglist from intbv import intbv -class TestSignalUnhashable(TestCase): - - def testSignalUnhashable(self): - self.assertRaises(TypeError, hash, Signal(3)) class SigTest(TestCase): diff --git a/myhdl/test_intbv.py b/myhdl/test_intbv.py index 33dc8142..f550364b 100644 --- a/myhdl/test_intbv.py +++ b/myhdl/test_intbv.py @@ -35,11 +35,6 @@ import operator from intbv import intbv concat = intbv.concat -class TestIntbvUnhashable(TestCase): - - def testIntbvUnhashable(self): - self.assertRaises(TypeError, hash, intbv(3)) - class TestIntbvConcat(TestCase):