You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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:
Notice that
func2
andfunc3
variables overlap, whereas neither overlapsfunc1
because the subroutinesfunc2
andfunc3
callfunc1
.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:
The program prints the following as expected:
This issue requests a way to automatically set
LAST_GLOBAL_LABEL
(or whatever name would be more fitting) so thathSpam
can expand tofunc3_hSpam
insidefunc3
, without having to repeat the subroutine's name at the start of every subroutine in something likeredef 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.
The text was updated successfully, but these errors were encountered: