From f29f8f1fe10bd9af2b267780d53b5ac0d104e087 Mon Sep 17 00:00:00 2001 From: Jan Decaluwe Date: Mon, 16 Jul 2012 13:40:08 +0200 Subject: [PATCH] Support for top-level bound methods, starting from existing code for the top-level visitor in _analyze.py --HG-- branch : 0.8-dev --- myhdl/conversion/_analyze.py | 14 ++++++++++---- .../conversion/general/test_toplevel_method.py | 9 ++++++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/myhdl/conversion/_analyze.py b/myhdl/conversion/_analyze.py index 507a482f..3c6de6d3 100644 --- a/myhdl/conversion/_analyze.py +++ b/myhdl/conversion/_analyze.py @@ -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] diff --git a/myhdl/test/conversion/general/test_toplevel_method.py b/myhdl/test/conversion/general/test_toplevel_method.py index cd43c618..3fcc6dbd 100644 --- a/myhdl/test/conversion/general/test_toplevel_method.py +++ b/myhdl/test/conversion/general/test_toplevel_method.py @@ -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