Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define symbols using arithmetic on imported symbols #1146

Open
pinobatch opened this issue Jun 22, 2023 · 7 comments
Open

Define symbols using arithmetic on imported symbols #1146

pinobatch opened this issue Jun 22, 2023 · 7 comments
Labels
enhancement Typically new features; lesser priority than bugs rgbasm This affects RGBASM rgblink This affects RGBLINK
Milestone

Comments

@pinobatch
Copy link
Member

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

@Rangi42 Rangi42 added enhancement Typically new features; lesser priority than bugs rgbasm This affects RGBASM rgblink This affects RGBLINK labels Jun 22, 2023
@aaaaaa123456789
Copy link
Member

Can you please post the files as gists or anywhere else where they'd render on a browser? Right now, your links force a download. Thanks!

@ISSOtm
Copy link
Member

ISSOtm commented Jun 22, 2023

This seems close to #201; I'm thinking of either allowing to define "soft labels" (symbols that are defined using EQU syntax but aren't constant), or we'd have to create a separate numeric symbol type that stores any RPN expression (which would be much more heavy to implement).

I asked Pino to make an issue for this so the use case is recorded (it seems it can be shimmed with EQUS in the meantime), but I don't plan to touch this until after #201 is implemented, and decide from there.

@pinobatch
Copy link
Member Author

Gists:

I had posted the files as a download for two reasons.

  1. I expected maintainers to download the files, visually compare them on a desktop or laptop computer to gain confidence that their lines correspond, and use the RGBASM one as a test case for changes related to the issue. I wanted to avoid mistakes while copying and pasting the gist into a text editor that may have hindered comparing them and testing with them.
  2. When I post a gist, I want to include context for future readers who discover it. When posting a new issue, I don't have an issue URL.

Going forward, are gists better than downloads in general for examples of input to RGBASM?

@Rangi42
Copy link
Contributor

Rangi42 commented Jun 22, 2023

I've sometimes wanted to define "soft labels" in RAM code. Currently we sometimes write this pattern:

LOAD "RAM Code", WRAM0
wFunction:
	...
	db $cd ; call
.callee:
	ds 2
	...
ENDL

Since neither of these are possible:

	 db LOW(OPCODE(call 0))
.callee: ds 2
	call .callee: 0

With soft labels, we could do something like this:

	DEF .callee EQUL @ + 1
	call 0

@aaaaaa123456789
Copy link
Member

Isn't that what you'd use EQUS for?

@pinobatch
Copy link
Member Author

EQUS cannot be EXPORTed.

@Rangi42
Copy link
Contributor

Rangi42 commented Jun 22, 2023

EQUS also doesn't appear in .sym files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Typically new features; lesser priority than bugs rgbasm This affects RGBASM rgblink This affects RGBLINK
Projects
None yet
Development

No branches or pull requests

4 participants