Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature request] Allow multiple instructions on one line with separators #805

Closed
Rangi42 opened this issue Mar 26, 2021 · 10 comments · Fixed by #1210
Closed

[Feature request] Allow multiple instructions on one line with separators #805

Rangi42 opened this issue Mar 26, 2021 · 10 comments · Fixed by #1210
Labels
enhancement Typically new features; lesser priority than bugs rgbasm This affects RGBASM
Milestone

Comments

@Rangi42
Copy link
Contributor

Rangi42 commented Mar 26, 2021

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.)

@Rangi42 Rangi42 added enhancement Typically new features; lesser priority than bugs rgbasm This affects RGBASM labels Mar 26, 2021
Rangi42 added a commit to Rangi42/rgbds that referenced this issue Jul 1, 2021
Rangi42 added a commit to Rangi42/rgbds that referenced this issue Jul 2, 2021
Rangi42 added a commit to Rangi42/rgbds that referenced this issue Jul 4, 2021
Rangi42 added a commit to Rangi42/rgbds that referenced this issue Jul 4, 2021
@Rangi42
Copy link
Contributor Author

Rangi42 commented Jul 4, 2021

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 \.

@Rangi42 Rangi42 added this to the v1.0.0 milestone Jul 4, 2021
@Rangi42 Rangi42 changed the title [Feature request] Allow multiple instructions on one line with backslashes [Feature request] Allow multiple instructions on one line with separators Nov 2, 2023
@Rangi42
Copy link
Contributor Author

Rangi42 commented Nov 2, 2023

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
+;

@ISSOtm
Copy link
Member

ISSOtm commented Nov 2, 2023

: was also suggested as a separator, which wouldn't be ambiguous with an anon label decl. :: and .. are also possibilities.

@Rangi42
Copy link
Contributor Author

Rangi42 commented Nov 2, 2023

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?

@ISSOtm
Copy link
Member

ISSOtm commented Nov 2, 2023

Hmm, periods should probably be avoided, as there was a suggested "current label scope" syntax using multiple periods.

@Rangi42
Copy link
Contributor Author

Rangi42 commented Nov 2, 2023

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

@Rangi42
Copy link
Contributor Author

Rangi42 commented Nov 2, 2023

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

@Rangi42
Copy link
Contributor Author

Rangi42 commented Nov 2, 2023

So, : might conflict with a ternary operator. Although note the discussion in #621 about what syntax to use for that anyway.

@untoxa

This comment was marked as off-topic.

@Rangi42
Copy link
Contributor Author

Rangi42 commented Nov 3, 2023

@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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Typically new features; lesser priority than bugs rgbasm This affects RGBASM
Projects
None yet
3 participants