https://github.com/G33kDude/MCL.ahk
No, the acronym doesn't stand for anything. I think it used to be "machine code library", but we decided to leave it ambiguous.
See the README for how to use it, and example projects. The Examples/ folder also has some simpler single file examples.
Supports both 32 and 64 bit AHK, although 32 bit support is a little tentative.
Requires a gcc based cross-compiler installed under PATH (named as gcc.exe/g++.exe or x86_64-w64-mingw32-gcc.exe/x86_64-w64-mingw32-g++.exe) to run the tests or compile any code.
I've had luck with mingw-w64 installed via Cygwin, and mingw-w64 installed via MYSYS2. I believe Geek has used TDM-GCC without anything breaking.
No dependencies required to run pre-compiled code (see Geek's cJson library for an example of running pre-compiled code).
Note: I'm not very good at checking the forums (or replying in a timely fashion), so feel free to join https://geekdude.io/discord and ping me in #mcl-mcode-lib if you'd like.
MCL has a few extra features compared to other machine code tools, the big ones being:
- Global variables
- "Exporting" functions/variables back to AHK
- Constant function pointers (ex: void(*)() pMyFn = MyFn; in global scope)
- Very large constants (ex: ... doubles, which gcc tends to promote to being a global constant, breaking code under other tools)
The primary goal of MCL is to enable much more complex machine code functions/libraries without resorting to a dll. For example, Geek's cJson library, which is compiled under MCL, and makes use of global variables, "exporting" multiple functions, and floating point numbers.
MCL also supports a tiny subset of C++ (no STL, exceptions, or RTTI). For example, see the SpookyHash test, which uses a C++ implementation of the SpookyHash hashing algorithm.
MCL also adds the ability for code to "import" functions from dlls in the same way you can with DllCall. This feature doesn't replace dll files, and isn't the primary goal of the project. Just think of it as a cherry on top.
And a (low level) warning for this feature: There is a bug with mingw-w64 compilers which results in the stack being misaligned, which will cause a crash the next time a Windows API (or standard library) function is called from your C/C++. This bug can be tracked here.
For an example of "importing" functions, see my PDFGen example library, which uses a regular C library with a few headers changed around along with an incredible number of imported standard library functions.
How it works:
I'm still working on figuring out how to explain it. I'll reply to this post with a nice explanation eventually. If you have any specific questions, chances are I'll have an easier time answering them than explaining the whole thing, so please ask.