iPython noteb中myHDL手册中基本示例的AST编译错误

2024-04-19 00:01:49 发布

您现在位置:Python中文网/ 问答频道 /正文

编辑:只有当我从iPython notebook内部运行代码时才会发生这种情况。从一个普通的.py文件可以正常工作

我刚开始学习myHDL,但使用@instance或@always\u comb生成器会出现编译错误,如下所示:

TypeError: compile() expected string without null bytes

例如: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)

提供堆栈跟踪:

^{pr2}$

有没有我做错什么的线索?在


Tags: instance编辑signaldefipythonalwaysperiodnext
1条回答
网友
1楼 · 发布于 2024-04-19 00:01:49

这看起来是myhdl中unicode支持的问题。\u util.\u dedent()

下面是一个说明问题的片段:

enter image description here

为了快速修复,我添加了以下代码:

def _dedent(s):
    """Dedent python code string."""
    # RL convert to ascii
    s = s.encode('ascii','ignore')
    result = [t[:2] for t in generate_tokens(StringIO(s).readline)]
    # set initial indent to 0 if any
    if result[0][0] == INDENT:
        result[0] = (INDENT, '')
    return untokenize(result)

相关问题 更多 >