-
Notifications
You must be signed in to change notification settings - Fork 10
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
Add support for writing basic macros #16
Comments
I've thought a macro system for quite awhile. It'd definitely be a nice feature to have! The main limitation are semantics and implementation: how exactly does it work and how do I accomplish it given the existing architecture? The primitive expression evaluation in the assembler defers to python's builtin eval function. Maybe python could be further utilized for macros somehow? A macro could be written as a simply python function that takes a few args and generates assembler Items? But I'd like macros to resemble regular assembler syntax, not python. Part of me has always been curious about writing an S-expression based assembler... |
I do want to implement some sort of simple macro system. Do you have any thoughts / ideas on what the syntax could look like for defining and using macros? |
My experience with Assembly macros is limited, but I think a basic syntax similar to this would be a good start:
In I guess what you need is a way to detect a start/end keyword for the macro, and a way to identify variables within the macro itself. Once that code is pre-processed into actual Assembly, then you can just append it where the macro is used:
would end up appending:
... something like that 🤣 |
Would it be possible to use separate, stand-alone, preprocessor as a make step before assembly? There are plenty available although I haven't checked which ones preserve lines and indentation properly. |
That's possible! Do you know of any high-quality, python-based preprocessors? Pulling something in off the shelf could be a nice path to success. I could write something simple myself but I'd like to avoid reinventing the wheel if possible. Using a non-python, standalone preprocessor sounds less ideal since it'd require an implicit dependency on external programs: something that bronzebeard tries to avoid. |
Says the person who wrote their own assembler and forth interpreter 🙄 but I get the point. |
Hah, yeah good point. I suppose it's more about being picky about wheels? Either way, if there is solid option that exists, I'd consider integration. |
Hi @theandrew168 ,
Would it be possible to add support for writing basic macros in the assembly programs? I wanted to see how
derzforth
would change in size if I inlined all thej next
instructions.For the moment my hack in
derzforth.asm
is to replace<4 spaces>j next
withinclude next.asm
, which contains:The binary size increased by exactly 200 bytes, which I think is worth it for the performance gain.
Either way, I think it would be interesting to have a real macro syntax or something similar to what
GAS
andNASM
provide... doesn't have to be as complex/powerful though. What do you think?The text was updated successfully, but these errors were encountered: