gbdev / gbdev/rgbds

Block macros

Open
#2,034 4 comments 0 reactions 0 assignees View on GitHub
enhancement rgbasm
Dominant language
C++
Stars
1.6k
Forks
193
Avg merge
1d 33m
Merged PRs (30d)
23

Description

Here's a relatively common macro pattern:

```asm
struct Thing
bytes 1, Type
end_struct
```

(See also pret's table macros, for example.)

Problem: you can forget to close them, and they rely on some global state which makes the macro's implementation icky.

I think I'd like a way to do something like this:

```asm
struct Thing {
bytes 1, Type
}
```

(Braces are the standard for blocks in current systems languages, and while in principle they conflict with interpolation syntax, a brace at EOL would always be a syntax error so we can try giving it semantics, though maybe only in raw lines.)

Tentative syntax:

```asm
MACRO struct [body] ; The macro expects a braced body, referred to within as `body`.
; ...setup...
body ; Used like a macro.
; ...teardown...
ENDM
```

(This means that a macro's body has to be valid code that does not get specially processed. I think that's better for external tooling e.g. syntax highlighters, and any fancier processing could use a `"""multi-line string"""` instead.)

Contributor guide

Open the contributing guide

Research direction

Compare the current end_struct macro pattern with pret's table macros, then examine how the proposed braced body and MACRO [body] syntax should behave. The issue names no files or tests, so first locate the macro parser and existing macro tests. Done means braced macro bodies parse reliably, expand in the intended place, and preserve the proposed setup and teardown behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.