Open orlof opened 1 year ago
This would be quite useful even with normal addresses, so that one would be able to reuse memory among different subs and functions while keeping the speed of STATIC procedures
Even fancier way would be to allow renaming e.g.
DIM zp AS BYTE FAST
SUB SomeTimeCriticalRoutine(Value AS BYTE @zp) STATIC
'Some fine code
END SUB
...but that might be too far from Basic's traditions?
I fear that, most of all, it would allow for too messy code. Since parameter (argument) memory locations are bound to be rewritten with each sub/function call, I guess it would be fine to re-use memory, but I wouldn't mess up global (if not shared!) variables.
I think there are multiple possible improvements here:
SUB example (param AS BYTE FAST) STATIC
- note this won't reuse an existing address but assign a new oneSUB example (param AS BYTE) STATIC FAST
SUB example (param AS BYTE @$FF) STATIC
- note that the address can be a 16-bit value as wellNote that all the above could work together with STATIC only as dynamic SUBS/FUNCTIONS always pass parameters and the return value using the Stack.
Even fancier way would be to allow renaming e.g.
Or you can simply use global variables to share values:
DIM zp AS BYTE FAST
SUB SomeTimeCriticalRoutine() STATIC
'You can use zp here as it is global
END SUB
zp = 1 ' Assign value instead of passing parameter value
CALL SomeTimeCriticalRoutine ()
Basically, argument/parameter variables would be at the same level of variables declared with DIM
, which you can declare as FAST
OR at a specific address. That I would like :)
Yes, the compiler could give a warning and ignore the FAST or specific-address directives, or stop with an error if the sub/function is not declared STATIC
.
Example:
This would allow reuse of ZP addresses in multiple time critical subroutines.