Re: [myhdl-list] Block return values (myhdl.BlockError)
Brought to you by:
jandecaluwe
From: Henry G. <he...@ma...> - 2016-05-10 10:02:36
|
On 10/05/16 10:45, Henry Gomersall wrote: > On 10/05/16 10:32, Jan Decaluwe wrote: >> > I have considered this issue for some time now >> > and I have basically decided to leave the constraints >> > as they are, that is, blocks should only return >> > block and instantiator objects. > I think your reasoning is sound. > > Do you object to alternative strategies for constructing Block > operators? This could leave @block as the default usual case, with more > esoteric cases handled by direct access to the construction of the Block > object. This could allow the best of both worlds - simple default and > arbitrary control if desired. Actually, a neat solution could be to allow optional decorator arguments taking the class constructor and allow subclassing of _Block. e.g. class MyBlock(_Block): @property def some_exposed_property(self): return 20 @block(block_class=MyBlock) def foo(): ... In the case of handling alternative default args, it's simply a case then of an alternative Block. Something like (untested so may be wrong)... (it actually doesn't matter whether it is right or easy, it provides an opportunity to add later). class ExtractExtraArgsBlock(_Block): @property def extra_args(self): return extra_args def __init__(self, func, deco, srcfile, srcline, *args, **kwargs): self.extra_args = [] def wrapper_func(*args, **kwargs): inst, output_stuff = func(*args, **kwargs) self.extra_args.append(output_stuff) return inst wrapper_srcfile = inspect.getsourcefile(wrapper_func) wrapper_srcline = inspect.getsourcelines(wrapper_func)[0] super(self, _Block).__init__( wrapper_func, deco, wrapper_srcfile, wrapper_srcline, *args, **kwargs) |