rgbds
rgbds copied to clipboard
[Feature request] Allow multiple instructions on one line with backslashes
In comments people often use "/
" or "\
" to separate multiple instructions, like "ld a, [hli] \ ld h, [hl] \ ld l, a
". It could be possible to do this in rgbasm
as well: outside of string literals, backslash is only used for macro arguments and line continuations, and line continuations must be followed only by whitespace or comments before the newline.
beginLineContinuation()
could change to return a T_NEWLINE
(or some T_FAKE_NEWLINE
if necessary) if it runs into a non-whitespace character, instead of printing an error. (Edit: the T_EOL
introduced by #716 might be appropriate here.)
In PR #901 @ISSOtm was "strongly against" \
as a statement separator because its meaning then changes between "line continuation" and "statement separator" depending on context. Another available possibility was .
, but that doesn't stand out as much as /
or \
.
If we just want to allow multiple instructions on one line, not labels, directives, etc, then it's a pretty simple change to the parser (using .
as the separator here):
plain_directive : label
- | label cpu_command
+ | label cpu_commands
[...]
+cpu_commands : cpu_command
+ | cpu_command T_PERIOD cpu_commands
+;
:
was also suggested as a separator, which wouldn't be ambiguous with an anon label decl. ::
and ..
are also possibilities.
I would avoid :
because putting anonymous labels or references to them on the same line would look odd:
: ldh a, [rSTAT] : and %11 : cp STATF_VBL : jr nz, :-
For comparison:
; two colons
: ldh a, [rSTAT] :: and %11 :: cp STATF_VBL :: jr nz, :-
; two periods
: ldh a, [rSTAT] .. and %11 .. cp STATF_VBL .. jr nz, :-
; one period
: ldh a, [rSTAT] . and %11 . cp STATF_VBL . jr nz, :-
On the other hand, periods might look weird with local labels:
; two periods
.wait_vbl: ldh a, [rSTAT] .. and %11 .. cp STATF_VBL .. jr nz, .wait_vbl
; one period
.wait_vbl: ldh a, [rSTAT] . and %11 . cp STATF_VBL . jr nz, .wait_vbl
What are others' preferences?
Hmm, periods should probably be avoided, as there was a suggested "current label scope" syntax using multiple periods.
Then it's between :
or ::
. Here's a real-world comparison:
; using single colon
RestoreAllPP:
ld a, MON_PP : call GetPartyParamLocation
push hl
ld a, MON_MOVES : call GetPartyParamLocation
pop de
xor a : ld [wMenuCursorY], a : ld [wMonType], a
ld c, NUM_MOVES
.loop
ld a, [hli]
and a : ret z
push hl
push de : push bc
call GetMaxPPOfMove
pop bc : pop de
ld a, [de] : and PP_UP_MASK : ld b, a
ld a, [wTempPP] : add b : ld [de], a
inc de
ld hl, wMenuCursorY : inc [hl]
pop hl
dec c : jr nz, .loop
ret
; using double colon
RestoreAllPP:
ld a, MON_PP :: call GetPartyParamLocation
push hl
ld a, MON_MOVES :: call GetPartyParamLocation
pop de
xor a :: ld [wMenuCursorY], a :: ld [wMonType], a
ld c, NUM_MOVES
.loop
ld a, [hli]
and a :: ret z
push hl
push de :: push bc
call GetMaxPPOfMove
pop bc :: pop de
ld a, [de] :: and PP_UP_MASK :: ld b, a
ld a, [wTempPP] :: add b :: ld [de], a
inc de
ld hl, wMenuCursorY :: inc [hl]
pop hl
dec c :: jr nz, .loop
ret
I just realized $
means end-of-line in regex; maybe that would justify it?
; using dollar sign
RestoreAllPP:
ld a, MON_PP $ call GetPartyParamLocation
push hl
ld a, MON_MOVES $ call GetPartyParamLocation
pop de
xor a $ ld [wMenuCursorY], a $ ld [wMonType], a
ld c, NUM_MOVES
.loop
ld a, [hli]
and a $ ret z
push hl
push de $ push bc
call GetMaxPPOfMove
pop bc $ pop de
ld a, [de] $ and PP_UP_MASK $ ld b, a
ld a, [wTempPP] $ add b $ ld [de], a
inc de
ld hl, wMenuCursorY $ inc [hl]
pop hl
dec c $ jr nz, .loop
ret
And for completeness, here's #
, the other unused punctuation:
; using pound sign
RestoreAllPP:
ld a, MON_PP # call GetPartyParamLocation
push hl
ld a, MON_MOVES # call GetPartyParamLocation
pop de
xor a # ld [wMenuCursorY], a # ld [wMonType], a
ld c, NUM_MOVES
.loop
ld a, [hli]
and a # ret z
push hl
push de # push bc
call GetMaxPPOfMove
pop bc # pop de
ld a, [de] # and PP_UP_MASK # ld b, a
ld a, [wTempPP] # add b # ld [de], a
inc de
ld hl, wMenuCursorY # inc [hl]
pop hl
dec c # jr nz, .loop
ret
So, :
might conflict with a ternary operator. Although note the discussion in #621 about what syntax to use for that anyway.
are you trying to make assembly code even less readable than it is?
@ISSOtm The examples posted by sylvie (zlago) were selling me on $
specifically. I quickly got used to how it looks. And it doesn't conflict with later feature plans (.
/..
for nested scopes, :
for ternary operator, #
for raw strings/tokens, '
for character literals).