wallento / wavedrompy

WaveDrom compatible python command line
Other
93 stars 21 forks source link

“<” triggers IndexError: deque index out of range #28

Open meisterluk opened 3 years ago

meisterluk commented 3 years ago

Consider the following source code:

{"signal": [
    {"name": "clk_i",   "wave": "P.......", "phase": 1.0 },
    {"name": "reset_i", "wave": "1.0...1" },
    {"name": "in_i",    "wave": "=....==<", "phase": 0.5, "data": "0 1 0" },
    {"name": "state_p", "wave": "=.=====", "data": "00 01 10 11 10|00 00" },
    {"name": "state_n", "wave": "=.=====", "data": "01 10 11 00|10 00|01 01"},
    {"name": "out_o",   "wave": "=.=====", "data": "11 10 00 10 00|11 11"}
  ],
  "config": { "hscale": 1 },
  "head": { "tick": 0 }
}

This works just fine in the editor. Now, let us try the same source code in wavedrompy:

Traceback (most recent call last):
  File "/usr/local/bin/wavedrompy", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.8/dist-packages/wavedrom/__init__.py", line 63, in main
    render_write(args.input, args.svg, False)
  File "/usr/local/lib/python3.8/dist-packages/wavedrom/__init__.py", line 47, in render_write
    out = render(jinput, strict_js_features=strict_js_features)
  File "/usr/local/lib/python3.8/dist-packages/wavedrom/__init__.py", line 38, in render
    return WaveDrom().render_waveform(0, source, output, strict_js_features)
  File "/usr/local/lib/python3.8/dist-packages/wavedrom/waveform.py", line 793, in render_waveform
    content = self.parse_wave_lanes(ret.lanes)
  File "/usr/local/lib/python3.8/dist-packages/wavedrom/waveform.py", line 196, in parse_wave_lanes
    sub_content.append(self.parse_wave_lane(sigx["wave"], self.lane.period * self.lane.hscale - 1))
  File "/usr/local/lib/python3.8/dist-packages/wavedrom/waveform.py", line 160, in parse_wave_lane
    if Stack[0] in ['.', '|']:
IndexError: deque index out of range

As far as I can see, this is related to the “<” character.

wallento commented 2 years ago

Interesting, I will have a look at it, and sorry for the delay

wallento commented 2 years ago

I am not sure why the example is supposed to work. I think the following code does what you want to achieve:

{"signal": [
    {"name": "clk_i",   "wave": "P.......", "phase": 1.0 },
    {"name": "reset_i", "wave": "1.0...1" },
    {"name": "in_i",    "wave": "=....==<u>", "phase": 0.5, "data": "0 1 0" },
    {"name": "state_p", "wave": "=.=====", "data": "00 01 10 11 10|00 00" },
    {"name": "state_n", "wave": "=.=====", "data": "01 10 11 00|10 00|01 01"},
    {"name": "out_o",   "wave": "=.=====", "data": "11 10 00 10 00|11 11"}
  ],
  "config": { "hscale": 1 },
  "head": { "tick": 0 }
}

Here: issue_28

I believe that the original wavedrom code does not work properly here. < starts a subcycle, I would expect that the subcycle ends with >. So, in my understanding you want a half period of u.

Anyhow, with the original wavedrom it doesn't render as expected. Here is some code I put into the editor:

{"signal": [
    {"name": "clk_i",   "wave": "P.......", "phase": 1.0 },
    {"name": "reset_i", "wave": "1.0...1" },
    {"name": "in_i0",    "wave": "=....==<", "phase": 0.5, "data": "0 1 0" },
    {"name": "in_i1",    "wave": "=....==<u>", "phase": 0.5, "data": "0 1 0" },
    {"name": "in_i2",    "wave": "=.........=.=.u", "phase": 0.5, period: 0.5, "data": "0 1 0" },
    {"name": "state_p", "wave": "=.=====", "data": "00 01 10 11 10|00 00" },
    {"name": "state_n", "wave": "=.=====", "data": "01 10 11 00|10 00|01 01"},
    {"name": "out_o",   "wave": "=.=====", "data": "11 10 00 10 00|11 11"}
  ],
  "config": { "hscale": 1 },
  "head": { "tick": 0 }
}

I would expect that in_i0 is invalid, in_i1 is what would actually be the expected, in_i2 is the workaround actually working with half cycles working on both wavedrompy and wavedrom. @wavedrom what do you think. Is this a bug in in wavedrom or expected behavior?

meisterluk commented 2 years ago

I understand your point and I am not sure about the expected behaviour either. So I am also interested in @wavedrom's position.