1
0
mirror of https://github.com/myhdl/myhdl.git synced 2024-12-14 07:44:38 +08:00

Support for top-level bound methods, starting from existing

code for the top-level visitor in _analyze.py

--HG--
branch : 0.8-dev
This commit is contained in:
Jan Decaluwe 2012-07-16 13:40:08 +02:00
parent 59744e5901
commit f29f8f1fe1
2 changed files with 18 additions and 5 deletions

View File

@ -1269,16 +1269,15 @@ def isboundmethod(m):
return ismethod(m) and m.__self__ is not None
def _analyzeTopFunc(func, *args, **kwargs):
if isboundmethod(func):
raise AssertionError("Bound methods not supported")
tree = _makeAST(func)
v = _AnalyzeTopFuncVisitor(tree, *args, **kwargs)
v = _AnalyzeTopFuncVisitor(func, tree, *args, **kwargs)
v.visit(tree)
return v
class _AnalyzeTopFuncVisitor(_AnalyzeVisitor):
def __init__(self, tree, *args, **kwargs):
def __init__(self, func, tree, *args, **kwargs):
self.func = func
self.tree = tree
self.args = args
self.kwargs = kwargs
@ -1286,8 +1285,15 @@ class _AnalyzeTopFuncVisitor(_AnalyzeVisitor):
self.argdict = {}
def visit_FunctionDef(self, node):
self.name = node.name
argnames = [arg.id for arg in node.args.args]
if isboundmethod(self.func):
if not argnames[0] == 'self':
self.raiseError(node, _error.NotSupported,
"first method argument name other than 'self'")
# skip self
argnames = argnames[1:]
i=-1
for i, arg in enumerate(self.args):
n = argnames[i]

View File

@ -1,5 +1,7 @@
import sys
from myhdl import *
from myhdl import ConversionError
from myhdl.conversion._misc import _error
from myhdl.conversion import analyze
class HdlObj(object):
@ -116,7 +118,12 @@ def test_hdlobjnotself():
x = Signal(intbv(0, min=0, max=16))
y = Signal(intbv(0, min=0, max=16))
hdlobj_inst = HdlObjNotSelf()
analyze(hdlobj_inst.method_func, clk, x, srst, y)
try:
analyze(hdlobj_inst.method_func, clk, x, srst, y)
except ConversionError, e:
assert e.kind == _error.NotSupported
else:
assert False