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

Provide a predefined string for the most recent global label #1156

Closed
pinobatch opened this issue Aug 17, 2023 · 3 comments
Closed

Provide a predefined string for the most recent global label #1156

pinobatch opened this issue Aug 17, 2023 · 3 comments
Labels
enhancement Typically new features; lesser priority than bugs rgbasm This affects RGBASM

Comments

@pinobatch
Copy link
Member

pinobatch commented Aug 17, 2023

I'd like to be able to use the most recently defined global label in a string expression, such as in an EQUS statement.

I'm writing a local variable allocation tool. Pending a fix for #1146, it reads all source code files in a directory, looks for global labels (which "Labels" in the manual defines as those not containing a .), infers a call graph of subroutines, reads declarations of local variables associated with each global label, and comes up with an allocation such that each subroutine's variables start after those of its callees. This way, different subroutines' variables can overlap in memory so long as a subroutine's variables doesn't overlap those of its callees. (Recursion is assumed not to happen, as it is uncommon in 8-bit programs.)

I expect the output of this call graph analyzer to look like this:

section "hSAVE_locals",HRAM
  union
  ; func1 has no callees
func1_hXPos:: ds 1
func1_hYPos:: ds 1
func1_hWidth:: ds 1
func1_hHeight:: ds 1
func1_hTileID:: ds 1
func1_hAttr:: ds 1
  nextu
  ds 6  ; func2's largest callee is func1
func2_hFoo:: ds 1
func2_hBar:: ds 1
func2_hBaz:: ds 1
  nextu
  ds 6  ; func3's largest callee is func1
func3_hSpam:: ds 1
func3_hEggs:: ds 1
func3_hBacon:: ds 1
  endu

Notice that func2 and func3 variables overlap, whereas neither overlaps func1 because the subroutines func2 and func3 call func1.

Within a routine, I'd like to define short names for a variable. I had planned to do this with macros that expand to something like this:

section "demo",ROM0
func3:
redef LAST_GLOBAL_LABEL equs "func3"
redef hSpam equs "{LAST_GLOBAL_LABEL}_hSpam"
redef hEggs equs "{LAST_GLOBAL_LABEL}_hEggs"
redef hBacon equs "{LAST_GLOBAL_LABEL}_hBacon"
println "Variables are {hSpam}, {hEggs}, and {hBacon}"
ldh a, [hSpam]

The program prints the following as expected:

Variables are func3_hSpam, func3_hEggs, and func3_hBacon

This issue requests a way to automatically set LAST_GLOBAL_LABEL (or whatever name would be more fitting) so that hSpam can expand to func3_hSpam inside func3, without having to repeat the subroutine's name at the start of every subroutine in something like redef LAST_GLOBAL_LABEL equs "func3". Neither section "String expressions" nor "Predeclared symbols" lists a way to determine the most recent global label.

I can think of an alternative way to accomplish this by slightly loosening a restriction on local labels, which I'll describe in another issue.

@Rangi42
Copy link
Contributor

Rangi42 commented Aug 17, 2023

This was previously proposed as __SCOPE__ in issue #775.

@pinobatch
Copy link
Member Author

RESOLVED DUPLICATE of #775

@pinobatch pinobatch closed this as not planned Won't fix, can't repro, duplicate, stale Aug 17, 2023
@Rangi42
Copy link
Contributor

Rangi42 commented Aug 17, 2023

To be clear, if you want to reopen #775, I'd support that.

@Rangi42 Rangi42 added enhancement Typically new features; lesser priority than bugs rgbasm This affects RGBASM labels Aug 17, 2023
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
Projects
None yet
Development

No branches or pull requests

2 participants