vscode-amiga-assembly icon indicating copy to clipboard operation
vscode-amiga-assembly copied to clipboard

Label folding including local labels

Open Bippym opened this issue 4 years ago • 7 comments

When folding routines it would be useful if the local routines are folded too. If I have the following

SetPalette:

                lea        myimage,a1                                         ; Image into a1 again to search for the palette	
.loop           cmp.l      #"CMAP",(a1)                                       ; Looking for the colormap
                beq        .found                                             ; Have we found the colormap
                addq       #2,a1                                              ; Not found, move on :)
                bra.s      .loop
	
.found          addq       #8,a1                                              ; Jump over the header

                move.l     #SCREEN_DEPTH<<2-1,d7                              ; Number of colours in the image
	
                clr.l      d4
                clr.l      d3
                clr.l      d2
                clr.l      d1

When folding "SetPalette:" I want it to also fold ".loop" and ".found" and they wont be visible. Otherwise I endup with this

^SetPalette ^.loop ^found

Bippym avatar Mar 15 '21 20:03 Bippym

Looks like a good way to do it, but I'm not sure that it is a common way to organize/use labels. It may be more suitable to detect the subroutines to fold it.

prb28 avatar Mar 15 '21 21:03 prb28

This is how the QT framework seems to fold subroutines. It makes sense (to me at least) to hide the local/sub-routines when folding the parent.

Bippym avatar Apr 14 '21 15:04 Bippym

I agree to fold subroutines inside the main label is interesting. The question is : is it a common way to name a subroutine stating with a ".", and the main without ? I've seen code written in a different way. So how to know if it is a sub or a main label ?

prb28 avatar Apr 15 '21 20:04 prb28

If the label starts with a ".", in most assemblers that is treated as a local variable (you can have several "." labels named the same as long as they have a non "." label between them). But lots of code exists that don't use it.

So I would say that "." labels is a good starting point.

I would also like a "special" comment syntax for folding, or both ;)

;region Optional text that shows at the folded place
Subroutine
        move.l #"DUMM",(a0)+
        move.l #"MY C",(a0)+
        move.l #"ODE"<<8,(a0)+
;region Nested region
waitformouse
        btst.b #6,$bfe001
        bne.b
;endregion
        rts
;endregion

geijer avatar Apr 16 '21 15:04 geijer

Maybe something configurable with regexp, like:

  • main section start regexp: "^[A-Za-z:-_]+$"
  • sub section start regexp: "^.[A-Za-z:-_]+.*$"
  • sub section end regexp or new sub section found: "^\srts\s$"
  • main section end regexp or new main section found: "" It would work with the comments too.

prb28 avatar Apr 17 '21 12:04 prb28

Hmm, several of my sections ends with a jump to another subroutine like:

    jsr (_LVOEnable,a6)
    rts

I usally optimize that to:

    jmp (_LVOEnable,a6)

You should at least add rte.

I think I would prefere a separate keyword for folding but it is worth a test :)

geijer avatar Apr 19 '21 05:04 geijer

In you case that would be:

  • main section start regexp: "^;region .*$"
  • main section end regexp or new main section found: "^;endregion .*$"

With a test to deal with the nested regions.

prb28 avatar Apr 19 '21 19:04 prb28