Re: [myhdl-list] Global state and multiple instances
Brought to you by:
jandecaluwe
From: Juan P. C. <jp...@gm...> - 2015-05-06 17:30:57
|
now() was just an example of a globally defined function accessing global variables, and the example is an idea of how we could potentially move all globals inside Simulation. I'have not looked in too much depth on how the other globals are used. The case with now() was the one that seem most obvious and simple to me to illustrate the case. The problem with making now() a method of Simulation and have users use that directly is that they would have to have a reference to the Simulation instance. Something ugly like this: sim = Simulation() # Create the instance first def logicmodule(sim): @always(...) def logic(): print sim.now() sim.append(logicmodule(sim)) # Then pass the instance to the module. or ... class MySim(Simulation): def logicmodule(self): # Default method ran to obtain the logic modules @always(...) def logic(): self.now() ... return logic, ... s = MySim.run() While we could still let the user write: @always(...) def logic(): print now() s = Sim(logic) And let Sim take care of "patching" to have the call to now() point to it's own self.now(). Thanks, JP On Wed, May 6, 2015 at 1:13 PM, Henry Gomersall <he...@ca...> wrote: > On 06/05/15 18:06, Juan Pablo Caram wrote: > > Attempting to make the global calls in user code local to the > > Simulation instance. The example in StackOverflow shows how the calls > > to, say, a global now(), can be replaced by a local instance, > > self.now(). This avoids any complicated lookups that would degrade > > performance, and maintains the syntax used by the user. > > Is the only issue the now() call? > > I think it makes much more sense to make now() a method on the > simulation instance and changing the API. If there is no global notion > of now(), I don't see why it makes sense to even offer that as part of > the API... > > Cheers, > > Henry > > > ------------------------------------------------------------------------------ > One dashboard for servers and applications across Physical-Virtual-Cloud > Widest out-of-the-box monitoring support with 50+ applications > Performance metrics, stats and reports that give you Actionable Insights > Deep dive visibility with transaction tracing using APM Insight. > http://ad.doubleclick.net/ddm/clk/290420510;117567292;y > _______________________________________________ > myhdl-list mailing list > myh...@li... > https://lists.sourceforge.net/lists/listinfo/myhdl-list > |