That's just alerted me to a flaw in my system, then. Because functions aren't built using string replacement, something like:
Code: Select all
.function load(reg, val)
ld reg,val
.endfunction
...will not work as reg is a string value.
The current way functions are handled is that when the function is called, Brass goes through the list of arguments, evaluates them, and sets labels to those values. So, in the above case:
Code: Select all
.function load(reg, val)
ld reg,val
.endfunction
load(hl, 10)
...is evaluated as:
Code: Select all
.module _func_0_ ; Restrict labels to local scope
; Set up arguments
reg = hl
val = 10
; Evaluate function
ld reg,val
.endmodule
This clearly won't work. Now, a workaround might be this sort of thing:
Code: Select all
.function load(token reg, value val)
ld reg,val
.endfunction
...in which Brass associates a particular type with each argument. For "value" types (which would be the default) new labels are created as above. For "token" types, the token passed in to the function would be replaced, much like TASM does by string replacement. If this doesn't make sense, I'll try and explain it better.
You could make it more explicit (there are a number of different token types - eg string tokens or operator tokens).
Yes, thinking about it, that's more the way to go (types on the arguments).
Bear in mind that none of this functionality is handled by Brass itself, and is actually handled by an external plugin, so you can write your own run-time function declaration system if you so wish. In fact, for the API, or any API-like project, you could be better off writing dedicated function plugins that do advanced optimisations (you could write this in C#, VB, PHP - any .NET language - freeing you from the constraints of the assembler's scripting) and still provide the TASM macros as an option for those using TASM. Or, indeed, just have a plugin that adds a #define/#defcont system (via a preprocessor and/or directive plugin) that simulates TASM's behaviour.