mirror of
https://github.com/myhdl/myhdl.git
synced 2025-01-24 21:52:56 +08:00
Replaced the block decorator with one that properly supports instance methods for conversion.
This commit is contained in:
parent
c66482e966
commit
80448fd467
@ -22,7 +22,8 @@ from __future__ import absolute_import
|
|||||||
|
|
||||||
import inspect
|
import inspect
|
||||||
|
|
||||||
from functools import wraps
|
#from functools import wraps
|
||||||
|
import functools
|
||||||
|
|
||||||
import myhdl
|
import myhdl
|
||||||
from myhdl import BlockError, BlockInstanceError, Cosimulation
|
from myhdl import BlockError, BlockInstanceError, Cosimulation
|
||||||
@ -80,16 +81,55 @@ def _getCallInfo():
|
|||||||
return _CallInfo(name, modctxt, symdict)
|
return _CallInfo(name, modctxt, symdict)
|
||||||
|
|
||||||
|
|
||||||
def block(func):
|
class _bound_function_wrapper(object):
|
||||||
srcfile = inspect.getsourcefile(func)
|
|
||||||
srcline = inspect.getsourcelines(func)[0]
|
def __init__(self, bound_func, srcfile, srcline):
|
||||||
|
|
||||||
@wraps(func)
|
self.srcfile = srcfile
|
||||||
def deco(*args, **kwargs):
|
self.srcline = srcline
|
||||||
deco.calls += 1
|
|
||||||
return _Block(func, deco, srcfile, srcline, *args, **kwargs)
|
self.bound_func = bound_func
|
||||||
deco.calls = 0
|
functools.update_wrapper(self, bound_func)
|
||||||
return deco
|
|
||||||
|
self.calls = 0
|
||||||
|
|
||||||
|
def __call__(self, *args, **kwargs):
|
||||||
|
self.calls += 1
|
||||||
|
return _Block(self.bound_func, self, self.srcfile,
|
||||||
|
self.srcline, *args, **kwargs)
|
||||||
|
|
||||||
|
class block(object):
|
||||||
|
def __init__(self, func):
|
||||||
|
self.srcfile = inspect.getsourcefile(func)
|
||||||
|
self.srcline = inspect.getsourcelines(func)[0]
|
||||||
|
|
||||||
|
self.func = func
|
||||||
|
functools.update_wrapper(self, func)
|
||||||
|
|
||||||
|
self.calls = 0
|
||||||
|
|
||||||
|
def __get__(self, instance, owner):
|
||||||
|
|
||||||
|
bound_func = self.func.__get__(instance, owner)
|
||||||
|
return _bound_function_wrapper(bound_func, self.srcfile, self.srcline)
|
||||||
|
|
||||||
|
def __call__(self, *args, **kwargs):
|
||||||
|
|
||||||
|
self.calls += 1
|
||||||
|
return _Block(self.func, self, self.srcfile,
|
||||||
|
self.srcline, *args, **kwargs)
|
||||||
|
|
||||||
|
#def block(func):
|
||||||
|
# srcfile = inspect.getsourcefile(func)
|
||||||
|
# srcline = inspect.getsourcelines(func)[0]
|
||||||
|
#
|
||||||
|
# print(func, type(func))
|
||||||
|
# @wraps(func)
|
||||||
|
# def deco(*args, **kwargs):
|
||||||
|
# deco.calls += 1
|
||||||
|
# return _Block(func, deco, srcfile, srcline, *args, **kwargs)
|
||||||
|
# deco.calls = 0
|
||||||
|
# return deco
|
||||||
|
|
||||||
|
|
||||||
class _Block(object):
|
class _Block(object):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user