adafruit / Adafruit_CircuitPython_PIOASM

Simple assembler to convert pioasm to bytes
MIT License
27 stars 17 forks source link

Fix for "; comment only lines" #5

Closed dglaude closed 3 years ago

dglaude commented 3 years ago

This should fix #4 but there might be a better way.

tannewt commented 3 years ago

@dglaude Mind testing the version I've added to this PR?

dglaude commented 3 years ago

My initial version was failing to produce the expected output when comment when jump. It was also failing with a message about not supporting .wrap_target when the comment is on first line. Here is my testing code, I recorded the expected output, and then I started to drop comment up, down and center:

import adafruit_pioasm

program1 = """;NeoPixels are 800khz bit streams.
.program ws2812
.side_set 1
.wrap_target
bitloop:
  out x 1        side 0 [1]; Side-set still takes place when instruction stalls
  jmp !x do_zero side 1 [1]; Branch on the bit we shifted out. Positive pulse
            ; Here
do_one:
  jmp  bitloop   side 1 [1]; Continue driving high, for a long pulse
do_zero:     ; <= this is a label
  nop            side 0 [1]; Or drive low, for a short pulse
.wrap
; Zeroes are 1/3 duty cycle (~416ns) and ones are 2/3 duty cycle (~833ns).
"""

expected1 = [24865, 4387, 4352, 41282]
assembled1 = adafruit_pioasm.assemble(program1)

for i in assembled1:
    j = expected1.pop(0)
    print(i, j)
    if i != j:
        print("ERROR ^^^")
        break
dglaude commented 3 years ago

So your version works. (CI fail but that is something else I guess)