Skip to content

Commit

Permalink
Merge pull request #164 from hgomersall/improved_block_decorator
Browse files Browse the repository at this point in the history
[WIP] Improved block decorator
  • Loading branch information
jandecaluwe committed Apr 20, 2016
2 parents b951c34 + 80448fd commit 72b5dd6
Showing 1 changed file with 50 additions and 10 deletions.
60 changes: 50 additions & 10 deletions myhdl/_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@

import inspect

from functools import wraps
#from functools import wraps
import functools

import myhdl
from myhdl import BlockError, BlockInstanceError, Cosimulation
Expand Down Expand Up @@ -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):

def __init__(self, bound_func, srcfile, srcline):

@wraps(func)
def deco(*args, **kwargs):
deco.calls += 1
return _Block(func, deco, srcfile, srcline, *args, **kwargs)
deco.calls = 0
return deco
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):
Expand Down

0 comments on commit 72b5dd6

Please sign in to comment.