mirror of
https://github.com/myhdl/myhdl.git
synced 2025-01-24 21:52:56 +08:00
restored 1.8
This commit is contained in:
parent
de2ab41f7d
commit
f1c371576f
188
myhdl/_Signal.py
188
myhdl/_Signal.py
@ -35,7 +35,7 @@ from copy import deepcopy as copy
|
|||||||
|
|
||||||
from myhdl import _simulator as sim
|
from myhdl import _simulator as sim
|
||||||
from myhdl._simulator import _siglist, _futureEvents, now
|
from myhdl._simulator import _siglist, _futureEvents, now
|
||||||
from myhdl._Waiter import _WaiterList, _Waiter
|
from myhdl._Waiter import _WaiterList
|
||||||
from myhdl._intbv import intbv
|
from myhdl._intbv import intbv
|
||||||
from myhdl._bin import bin
|
from myhdl._bin import bin
|
||||||
|
|
||||||
@ -202,73 +202,23 @@ class Signal(object):
|
|||||||
def _printVcdVec(self):
|
def _printVcdVec(self):
|
||||||
print >> sim._tf, "b%s %s" % (bin(self._val, self._nrbits), self._code)
|
print >> sim._tf, "b%s %s" % (bin(self._val, self._nrbits), self._code)
|
||||||
|
|
||||||
|
|
||||||
# experimental item and slice proxy signals through call interface
|
|
||||||
def _listener(self, sig, *args):
|
|
||||||
if len(args) == 1:
|
|
||||||
index = args[0]
|
|
||||||
while 1:
|
|
||||||
self.next[index] = sig.val
|
|
||||||
yield sig
|
|
||||||
elif len(args) == 2:
|
|
||||||
high, low = args
|
|
||||||
if low is None:
|
|
||||||
low = 0
|
|
||||||
if high is None:
|
|
||||||
while 1:
|
|
||||||
self.next[:low] = sig.val
|
|
||||||
yield sig
|
|
||||||
else:
|
|
||||||
while 1:
|
|
||||||
self.next[high:low] = sig.val
|
|
||||||
yield sig
|
|
||||||
else:
|
|
||||||
raise TypeError
|
|
||||||
|
|
||||||
def _driver(self, sig, *args):
|
|
||||||
if len(args) == 1:
|
|
||||||
index = args[0]
|
|
||||||
while 1:
|
|
||||||
sig.next = self.val[index]
|
|
||||||
yield self
|
|
||||||
elif len(args) == 2:
|
|
||||||
high, low = args
|
|
||||||
if low is None:
|
|
||||||
low = 0
|
|
||||||
if high is None:
|
|
||||||
while 1:
|
|
||||||
sig.next = self.val[:low]
|
|
||||||
yield self
|
|
||||||
else:
|
|
||||||
while 1:
|
|
||||||
sig.next = self.val[high:low]
|
|
||||||
yield self
|
|
||||||
else:
|
|
||||||
raise TypeError
|
|
||||||
|
|
||||||
def __call__(self, *args):
|
|
||||||
if len(args) == 1:
|
|
||||||
index = args[0]
|
|
||||||
sig = Signal(self[index])
|
|
||||||
elif len(args) == 2:
|
|
||||||
high, low = args
|
|
||||||
if low is None:
|
|
||||||
low = 0
|
|
||||||
if high is None:
|
|
||||||
sig = Signal(self[:low])
|
|
||||||
else:
|
|
||||||
sig = Signal(self[high:low])
|
|
||||||
else:
|
|
||||||
raise TypeError
|
|
||||||
listener = self._listener(sig, *args)
|
|
||||||
sig._eventWaiters.append(_Waiter(listener))
|
|
||||||
driver = self._driver(sig, *args)
|
|
||||||
self._eventWaiters.append(_Waiter(driver))
|
|
||||||
return sig
|
|
||||||
|
|
||||||
|
|
||||||
### operators for which delegation to current value is appropriate ###
|
### operators for which delegation to current value is appropriate ###
|
||||||
|
|
||||||
|
# hashing (?)
|
||||||
|
def __hash__(self):
|
||||||
|
return hash(self._val)
|
||||||
|
|
||||||
|
|
||||||
|
def __nonzero__(self):
|
||||||
|
if self._val:
|
||||||
|
return 1
|
||||||
|
else:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
# length
|
||||||
|
def __len__(self):
|
||||||
|
return len(self._val)
|
||||||
|
|
||||||
# indexing and slicing methods
|
# indexing and slicing methods
|
||||||
|
|
||||||
def __getitem__(self, i):
|
def __getitem__(self, i):
|
||||||
@ -277,153 +227,139 @@ class Signal(object):
|
|||||||
def __getslice__(self, i, j):
|
def __getslice__(self, i, j):
|
||||||
return self._val[i:j]
|
return self._val[i:j]
|
||||||
|
|
||||||
# hashing (?)
|
|
||||||
def __hash__(self):
|
|
||||||
return hash(self.val)
|
|
||||||
|
|
||||||
# truth testing
|
|
||||||
def __nonzero__(self):
|
|
||||||
if self.val:
|
|
||||||
return 1
|
|
||||||
else:
|
|
||||||
return 0
|
|
||||||
|
|
||||||
# length
|
|
||||||
def __len__(self):
|
|
||||||
return len(self.val)
|
|
||||||
|
|
||||||
# integer-like methods
|
# integer-like methods
|
||||||
|
|
||||||
def __add__(self, other):
|
def __add__(self, other):
|
||||||
if isinstance(other, Signal):
|
if isinstance(other, Signal):
|
||||||
return self.val + other._val
|
return self._val + other._val
|
||||||
else:
|
else:
|
||||||
return self.val + other
|
return self._val + other
|
||||||
def __radd__(self, other):
|
def __radd__(self, other):
|
||||||
return other + self.val
|
return other + self._val
|
||||||
|
|
||||||
def __sub__(self, other):
|
def __sub__(self, other):
|
||||||
if isinstance(other, Signal):
|
if isinstance(other, Signal):
|
||||||
return self.val - other._val
|
return self._val - other._val
|
||||||
else:
|
else:
|
||||||
return self.val - other
|
return self._val - other
|
||||||
def __rsub__(self, other):
|
def __rsub__(self, other):
|
||||||
return other - self.val
|
return other - self._val
|
||||||
|
|
||||||
def __mul__(self, other):
|
def __mul__(self, other):
|
||||||
if isinstance(other, Signal):
|
if isinstance(other, Signal):
|
||||||
return self.val * other._val
|
return self._val * other._val
|
||||||
else:
|
else:
|
||||||
return self.val * other
|
return self._val * other
|
||||||
def __rmul__(self, other):
|
def __rmul__(self, other):
|
||||||
return other * self.val
|
return other * self._val
|
||||||
|
|
||||||
def __div__(self, other):
|
def __div__(self, other):
|
||||||
if isinstance(other, Signal):
|
if isinstance(other, Signal):
|
||||||
return self.val / other._val
|
return self._val / other._val
|
||||||
else:
|
else:
|
||||||
return self.val / other
|
return self._val / other
|
||||||
def __rdiv__(self, other):
|
def __rdiv__(self, other):
|
||||||
return other / self.val
|
return other / self._val
|
||||||
|
|
||||||
def __mod__(self, other):
|
def __mod__(self, other):
|
||||||
if isinstance(other, Signal):
|
if isinstance(other, Signal):
|
||||||
return self.val % other._val
|
return self._val % other._val
|
||||||
else:
|
else:
|
||||||
return self.val % other
|
return self._val % other
|
||||||
def __rmod__(self, other):
|
def __rmod__(self, other):
|
||||||
return other % self.val
|
return other % self._val
|
||||||
|
|
||||||
# XXX divmod
|
# XXX divmod
|
||||||
|
|
||||||
def __pow__(self, other):
|
def __pow__(self, other):
|
||||||
if isinstance(other, Signal):
|
if isinstance(other, Signal):
|
||||||
return self.val ** other._val
|
return self._val ** other._val
|
||||||
else:
|
else:
|
||||||
return self.val ** other
|
return self._val ** other
|
||||||
def __rpow__(self, other):
|
def __rpow__(self, other):
|
||||||
return other ** self.val
|
return other ** self._val
|
||||||
|
|
||||||
def __lshift__(self, other):
|
def __lshift__(self, other):
|
||||||
if isinstance(other, Signal):
|
if isinstance(other, Signal):
|
||||||
return self.val << other._val
|
return self._val << other._val
|
||||||
else:
|
else:
|
||||||
return self.val << other
|
return self._val << other
|
||||||
def __rlshift__(self, other):
|
def __rlshift__(self, other):
|
||||||
return other << self.val
|
return other << self._val
|
||||||
|
|
||||||
def __rshift__(self, other):
|
def __rshift__(self, other):
|
||||||
if isinstance(other, Signal):
|
if isinstance(other, Signal):
|
||||||
return self.val >> other._val
|
return self._val >> other._val
|
||||||
else:
|
else:
|
||||||
return self.val >> other
|
return self._val >> other
|
||||||
def __rrshift__(self, other):
|
def __rrshift__(self, other):
|
||||||
return other >> self.val
|
return other >> self._val
|
||||||
|
|
||||||
def __and__(self, other):
|
def __and__(self, other):
|
||||||
if isinstance(other, Signal):
|
if isinstance(other, Signal):
|
||||||
return self.val & other._val
|
return self._val & other._val
|
||||||
else:
|
else:
|
||||||
return self.val & other
|
return self._val & other
|
||||||
def __rand__(self, other):
|
def __rand__(self, other):
|
||||||
return other & self.val
|
return other & self._val
|
||||||
|
|
||||||
def __or__(self, other):
|
def __or__(self, other):
|
||||||
if isinstance(other, Signal):
|
if isinstance(other, Signal):
|
||||||
return self.val | other._val
|
return self._val | other._val
|
||||||
else:
|
else:
|
||||||
return self.val | other
|
return self._val | other
|
||||||
def __ror__(self, other):
|
def __ror__(self, other):
|
||||||
return other | self.val
|
return other | self._val
|
||||||
|
|
||||||
def __xor__(self, other):
|
def __xor__(self, other):
|
||||||
if isinstance(other, Signal):
|
if isinstance(other, Signal):
|
||||||
return self.val ^ other._val
|
return self._val ^ other._val
|
||||||
else:
|
else:
|
||||||
return self.val ^ other
|
return self._val ^ other
|
||||||
def __rxor__(self, other):
|
def __rxor__(self, other):
|
||||||
return other ^ self.val
|
return other ^ self._val
|
||||||
|
|
||||||
def __neg__(self):
|
def __neg__(self):
|
||||||
return -self.val
|
return -self._val
|
||||||
|
|
||||||
def __pos__(self):
|
def __pos__(self):
|
||||||
return +self.val
|
return +self._val
|
||||||
|
|
||||||
def __abs__(self):
|
def __abs__(self):
|
||||||
return abs(self.val)
|
return abs(self._val)
|
||||||
|
|
||||||
def __invert__(self):
|
def __invert__(self):
|
||||||
return ~self.val
|
return ~self._val
|
||||||
|
|
||||||
# conversions
|
# conversions
|
||||||
|
|
||||||
def __int__(self):
|
def __int__(self):
|
||||||
return int(self.val)
|
return int(self._val)
|
||||||
|
|
||||||
def __long__(self):
|
def __long__(self):
|
||||||
return long(self.val)
|
return long(self._val)
|
||||||
|
|
||||||
def __float__(self):
|
def __float__(self):
|
||||||
return float(self.val)
|
return float(self._val)
|
||||||
|
|
||||||
def __oct__(self):
|
def __oct__(self):
|
||||||
return oct(self.val)
|
return oct(self._val)
|
||||||
|
|
||||||
def __hex__(self):
|
def __hex__(self):
|
||||||
return hex(self.val)
|
return hex(self._val)
|
||||||
|
|
||||||
|
|
||||||
# comparison
|
# comparison
|
||||||
def __cmp__(self, other):
|
def __cmp__(self, other):
|
||||||
return cmp(self.val, other)
|
return cmp(self._val, other)
|
||||||
|
|
||||||
# representation
|
# representation
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.val)
|
return str(self._val)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "Signal(" + repr(self.val) + ")"
|
return "Signal(" + repr(self._val) + ")"
|
||||||
|
|
||||||
# augmented assignment not supported
|
# augmented assignment not supported
|
||||||
def _augm(self):
|
def _augm(self):
|
||||||
@ -501,5 +437,3 @@ class _SignalWrap(object):
|
|||||||
return self.sig._apply(self.next, self.timeStamp)
|
return self.sig._apply(self.next, self.timeStamp)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user