customasm icon indicating copy to clipboard operation
customasm copied to clipboard

Traditional macro assembler functions

Open moonheart08 opened this issue 5 years ago • 3 comments

At the end of the day, there's no escape from them. It'd be nice if #define, #ifdef, #undef, and #ifundef were implemented, at least. Fullblown macros would be ideal, never-the-less. They'd be highly useful in larger projects.

moonheart08 avatar Feb 21 '20 02:02 moonheart08

I'm trying to decide whether to make the conditional directives be evaluated in a preprocessor step (like in C) or during the normal assembly pass.

As preprocessor directives, they would be more flexible, by allowing you to manipulate syntax constructs directly. But I'm not exactly sure about the use-cases for this.

As regular in-line assembly directives, they would be able to access standard labels and addresses and whatnot, which I believe is a nice advantage. You wouldn't need #define, you could just use regular = assignments. But for this alternative to be possible, the conditional directives could only be accepted in well-formed syntax contexts, preventing you from crossing the boundaries of syntax constructs. This alternative is probably a little more difficult to implement, since I'd have to sprinkle new code in several places, but I don't think it would be too limiting for the user.

Now, about macros, they should ideally just copy-paste their aguments into their bodies, right? No evaluation? I was also thinking of other types of constructs that would indeed evaluate their arguments. Perhaps regular function definitions? And perhaps some kind of free-standing instruction definition that would also emit bytes to the output?

hlorenzi avatar Mar 04 '20 16:03 hlorenzi

Yep. Macros are almost always a preprocessor step, so just do that here, too.

moonheart08 avatar Mar 04 '20 17:03 moonheart08

Could possibly add a anti-pattern warning that is printed when someone does something like #define foo 0x1214 and advise using foo = 0x1214

But if that's done, i'd recommend first making foo = x work in #cpudef blocks.

moonheart08 avatar Mar 04 '20 17:03 moonheart08

I've got something like this working on v0.13.1! I've written about it on the wiki.

hlorenzi avatar Jun 19 '23 01:06 hlorenzi