Skip to content

Change object file format to not reuse "patch" mechanism for assertions #2019

Description

@Rangi42

In both RGBASM and RGBLINK, the struct Section stores a collection of struct Patches, which represent bytes that get patched over with values computed at link time from RPN expressions.

When #488 implemented assertions, it reused code from the patch mechanism to store RPN expressions which were being asserted to be true (nonzero). This had two consequences I'd like to fix.

One is that the Offset field of a patch is unused by the assertion (documented in rgbds(5) as an "unused leftover from the patch structure"), so it just bloats the object files a little bit.

The other is that the Type field of a patch ends up having two different meanings. For section patches it can be 0, 1, 2, or 3, indicating the type of patch (byte, word, long, or jr). For assertion patches it can be 0, 1, or 2, indicating the type of assertion (warning, error, or fatal). This results in some suspicious-looking code casting to/from contradictory enum values.

I'd rather just have separate code to write→read sections and assertions, without trying to reuse writePatch and readPatch functions for both. If we want to avoid duplicate code, there can be smaller reused units like "write/read RPNSize followed by RPNExpr". This would be a breaking change if we remove the unused Offset field from assertions in the object file.

Metadata

Metadata

Assignees

No one assigned

    Labels

    breakingThis is a breaking change that requires a major version updateoptimizationThis increases performance or decreases sizerefactoringThis PR is intended to clean up code more than change functionalityrgbasmThis affects RGBASMrgblinkThis affects RGBLINK

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions