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
|
||||
|
||||
from functools import wraps
|
||||
#from functools import wraps
|
||||
import functools
|
||||
|
||||
import myhdl
|
||||
from myhdl import BlockError, BlockInstanceError, Cosimulation
|
||||
@ -80,16 +81,55 @@ def _getCallInfo():
|
||||
return _CallInfo(name, modctxt, symdict)
|
||||
|
||||
|
||||
def block(func):
|
||||
srcfile = inspect.getsourcefile(func)
|
||||
srcline = inspect.getsourcelines(func)[0]
|
||||
class _bound_function_wrapper(object):
|
||||
|
||||
@wraps(func)
|
||||
def deco(*args, **kwargs):
|
||||
deco.calls += 1
|
||||
return _Block(func, deco, srcfile, srcline, *args, **kwargs)
|
||||
deco.calls = 0
|
||||
return deco
|
||||
def __init__(self, bound_func, srcfile, srcline):
|
||||
|
||||
self.srcfile = srcfile
|
||||
self.srcline = srcline
|
||||
|
||||
self.bound_func = bound_func
|
||||
functools.update_wrapper(self, bound_func)
|
||||
|
||||
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):
|
||||
|
Loading…
x
Reference in New Issue
Block a user