Inline?

BlitzMax Forums/BlitzMax Programming/Inline?

zoqfotpik(Posted 2014) [#1]
Is there currently a way to inline either macros or asm?

Two separate questions, orthogonally related, one post.


GW(Posted 2014) [#2]
No, bmk would need to be tweaked to add some kind of real preprocessor.
Blitzmax doesn't handle inline asm, you can 'import' an asm file however.


zoqfotpik(Posted 2014) [#3]
Is there documentation on importing .asm files?

Now, a compiler designer I'm not, but would it really be that difficult to implement a basic macro expander? It seems like something that could be done with a unix pipe pretty easily as long as you didn't try to do anything cute with it.


Brucey(Posted 2014) [#4]
Is there documentation on importing .asm files?

Import "asm_source.s"

Source should be "fasm" compatible.


Yasha(Posted 2014) [#5]
For assembly you could also consider using a JIT of some kind (store the assembly in the program as text, assemble it at runtime... I believe there's a GNU lightning mod floating around somewhere that you could use for this, or maybe TCC).

The main nuisance for macros is that since Max uses both the # and ' characters for forms that are incompatible with C syntax, you can't run it through the C preprocessor (unless your program has no comments!). Technically I guess you could just comment your Max with //, but that would confuse existing IDEs and make your code mostly unreadable to other Maxers. There are other cross-pl macro languages, but they're all pretty obscure by comparison.

I guess sed awk could help...

awk -F'"' -v OFS='"' '{ for (i=1; i<=NF; i+=2) gsub("'"'"'", "//", $i) } 1' myfile.bmx > myfile.tmp.c
gcc -E -P myfile.tmp.c > myfile.tmp.bmx
bmk makeapp -a -r -o myapp_release myfile.tmp.bmx



Who was John Galt?(Posted 2014) [#6]
Really? I've only ever used Import with GNU-style assembly.
That's interesting, and also news to me. I assume you need mingw installed?


zoqfotpik(Posted 2014) [#7]
How do you provide access points for functions in the asm file and tell your blitzmax program where they are?


Yasha(Posted 2014) [#8]
That's interesting, and also news to me. I assume you need mingw installed?


Actually looking back over my own work, I've just realised I never imported the assembly as .s, but precompiled it and imported it as .o - obviously if you're going to do that you can write in whatever syntax (or language!) you want, as Max doesn't handle compilation. Sorry, that was a dumb comment on my part.