Skip to content

Block macros #2034

Description

@ISSOtm

Here's a relatively common macro pattern:

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:

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:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementTypically new features; lesser priority than bugsrgbasmThis affects RGBASM

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions