On Tue, Dec 15, 2009 at 10:29 AM, Jan Decaluwe <ja...@ja...> wrote:
> Christopher L. Felton wrote:
> > The following will cause an error.
> >
> > >>> from myhdl import *
> > >>> from copy import copy
> > >>> x = Signal(False)
> > >>> y = copy(x)
> > Exception RuntimeError: 'maximum recursion depth exceeded while calling
> > a Python object' in <type 'exceptions.AttributeError'> ignored
> >
> >
> > Not sure why??
>
> Me neither :-)
>
> The Signal object is becoming a rather complex thing with
> (mutually) recursive dependencies on other objects, so I'm
> not really surprized however.
>
Yes, agree it is a complicated object. So far been working pretty good,
only issues I have hit is this one and the issue that there is no Signal
type now (isinstance(x, Signal)).
> I hope you have other means to accomplish what you want?
>
I can probably think of some work around for now. But a couple
observations.
1. Tried adding a test hasattr(self._val, attr) before descending down to
the object the Signal holds. I think this makes sense to check before
calling the _val object. But this had the mechanical error self._val was
checked before it existed. I guess in the constructor when new "attributes"
are created the __getattr__ is called by default and getattr must have some
error handling or something? But I only just learned about getattr and
setattr, I might not be understanding what I am observing.
2. I like the idea of getattr because it allows the Signal to be somewhat
transparent. Can still interact with the object that it holds. Why no
setattr?
3. Adding a simply print to __getattr__ it appears this function is
called frequently. Don't know if this desired?
Some Background on what I have been working on.
MyHDL Fixed Point Object
Ran across this error for the fixed point object. When I had a signal of
the fixed point (fxint) object couple issues occurred. When an operation
executed on the signals (a+b) called the fxint __add__ and this is where the
copy was. I should be able to remove the copy here (the work around). The
getattr and setattr are very useful in this scenario. Because in the
elaboration phase the fixed point sizing/alignment can be handled.
z.Q = a + b
# where z, a and b are type Signal(fxint(0)) and fxint has intbv as a base
class
DSP System Simulation / HDL Simulation
The other non-common use. What I put together a DSP system simulation that
utilized the Signal object. The dspsys allows me to define a DSP system
(testbench and analysis) kinda like simulink but it can also interface with
the HDL simulator. In this case I needed the the Signal object to carry a
numpy array (sometimes large). Had to override some of the functions, cause
I didn't want to copy the arrays on each "next" but simply to swap current
val and next.
Sorry for the previous duplicate posts, my spam filter decided to
get aggressive and I wasn't receiving the posts.
.chris
|