1

編集:これは、 iPython notebook内からコードを実行した場合にのみ発生します。通常の .py ファイルから正常に動作します

myHDL の学習を始めたばかりで、@instance または @always_comb ジェネレーターを次のように使用するとコンパイル エラーが発生します。

TypeError: compile() には null バイトのない文字列が必要です

例: 3.2 シグナル、ポート、および並行性:

from myhdl import Signal, delay, always, instance, now, Simulation

def ClkDriver(clk, period=20):
    lowTime = int(period/2)
    highTime = period - lowTime

    @instance
    def driveClk():
        while True:
            yield delay(lowTime)
            clk.next = 1
            yield delay(highTime)
            clk.next = 0

    return driveClk

clk = Signal(0)
clkdriver_inst = ClkDriver(clk)

スタック トレースを表示します。

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-47-4252bd2f72e0> in <module>()
     16 
     17 clk = Signal(0)
---> 18 clkdriver_inst = ClkDriver(clk)

<ipython-input-47-4252bd2f72e0> in ClkDriver(clk, period)
      5     highTime = period - lowTime
      6 
----> 7     @instance
      8     def driveClk():
      9         while True:

C:\Python27\lib\site-packages\myhdl\_instance.pyc in instance(genFunc)
     40     if genFunc.func_code.co_argcount > 0:
     41         raise InstanceError(_error.NrOfArgs)
---> 42     return _Instantiator(genFunc)
     43 
     44 class _Instantiator(object):

C:\Python27\lib\site-packages\myhdl\_instance.pyc in __init__(self, genFunc)
     47         self.genfunc = genFunc
     48         self.gen = genFunc()
---> 49         self.waiter = _inferWaiter(self.gen)
     50 

C:\Python27\lib\site-packages\myhdl\_Waiter.pyc in _inferWaiter(gen)
    209     s = inspect.getsource(f)
    210     s = _dedent(s)
--> 211     root = ast.parse(s)
    212     root.symdict = f.f_globals.copy()
    213     root.symdict.update(f.f_locals)

C:\Python27\lib\ast.pyc in parse(source, filename, mode)
     35     Equivalent to compile(source, filename, mode, PyCF_ONLY_AST).
     36     """
---> 37     return compile(source, filename, mode, PyCF_ONLY_AST)
     38 
     39 

TypeError: compile() expected string without null bytes

私が間違っていることについての手がかりはありますか?

4

1 に答える 1