Message board for the users of flat assembler.
> Compiler Internals > fasm preprocessor: string slice operator (experimental)
I wanted fasm to be able to manipulate string arguments to preprocessor
instructions, such as "format", so I dug into the source code and made this.
Specifically, I wanted this to be possible:
This patch adds string slice operator, inspired by Python,
allowing the preprocessor to manipulate strings like so:
"abc" converts to "c"
"slice and dice"[6:9] converts to "and"
"slice and dice"[:9] converts to "slice and"
"slice and dice"[6:] converts to "and dice"
"slice and dice" converts to string length, 14
Like the "#" operator, it only works inside macros.
The addition to preprocessor, gpe_slice.inc:
I don't have a good knowledge of fasm internals as the only partial
documentation is old and there are few comments in the code.
(In particular, I spent a lot of time before finding that call to precalculate_value trashes [error_line] and later it results in access violation.)
So the addition is in "kinda works" quality. Use at your own risk!
Perhaps Tomasz can direct me further on that.
Regardless, hopefully this serves as an example and helps someone in digging in fasm source code.
Updated guide to fasm internals/porting
String directives for manipulating text
REQUEST: iterate over characters of symbol/literate.
Attached the patch file and examples.
|24 Oct 2016, 16:16||
Found the conflict with macros inside a macro like:
and fixed the patch. Updated the post and the attachment.
|29 Oct 2016, 07:45||
< Last Thread | Next Thread >
Copyright © 2004-2018, Tomasz Grysztar.
Powered by rwasa.