gbdev / gbdev/rgbds

Define symbols using arithmetic on imported symbols

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

Description

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](https://github.com/gbdev/rgbds/files/11837538/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](https://youtu.be/4r7wHMg5Yjg?t=28) 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](https://github.com/gbdev/rgbds/files/11837545/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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.