Skip to content

Define symbols using arithmetic on imported symbols #1146

Open
@pinobatch

Description

@pinobatch

I'm working on a local variable allocator that counts how many HRAM variables a subroutine uses so that its callers know how many HRAM variables to skip when placing their own locals. I had planned to build it as a macro pack where macros would do this:

  1. Import the address of the end of local variables for each callee
  2. Calculate their maximum, giving the address of the start of local variables for the present subroutine
  3. Add the size of local variables for the present subroutine, giving the address of the end of local variables for the present subroutine
  4. Export this address for use by the present subroutine's callers

I wrote an example of steps 1, 3, and 4 in ca65 (locals-sample-ca65.s.txt), which assembled successfully. The right side of the symbol definition isn't constexpr, and honey badger don't give a bleep because honey badger can put it in a patch and make the linker fix it up.

However, a line-by-line translation of this code to RGBASM syntax (locals-sample-rgbasm.s.txt) produces an error at the DEF ... EQU.

error: locals-sample-rgbasm.s.txt(3):
    Expected constant expression: 'calleeFunc_hLocalsEnd' is not constant at assembly time
error: Assembly aborted (1 error)!

suggested labels: enhancement, ca65 parity

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementTypically new features; lesser priority than bugsrgbasmThis affects RGBASMrgblinkThis affects RGBLINK

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions