r/Compilers • u/morglod • Sep 17 '26
Compile time code execution in mox
Hello! I am working on mox programming language and compiler which could run any code at compile time.
While I was telling about this language to my friend, I found a lot of interesting solutions to usual problems that could be solved just by using compile time code execution. So I want to research/discuss what problems do you have as a developer that you struggle with and want to solve at build time (using some macros or external tools).
Here are some of problems that I got in other languages and which i struggle with. Usually to solve it you need some ugly build systems with tons of esoterical configs, external tools for code generation etc.
PS #run in mox evaluates any expression/statement at compile time, including externally linked symbols. os_* and fs_* calls below are just wrappers around C functions, not some special magical things from compiler. Results of #run'ned expressions are baked to runtime as constants.
Baking git hash as a constant to binary
Build params from environment (or defining build constats)
const NO_ASSERTS := #run os_get_env == "true";
Reading configuration file and baking constants
: Config
CONFIG := #run read_config;
Self configuring build tools
#run
Go like dependency management
: __ast_ptr
PSS https://github.com/morglod/mox
2
u/Top-Employ5163 Sep 17 '26
Okay, the language has potential and looks similar to Jai. I'll star it on GitHub.
2
u/nirlahori Sep 17 '26
That's a really powerful feature. Awesome work.
2
u/whizzter Sep 17 '26
Very powerful but also a risk in these days of supply chain risks.
Got me thinking, I’ve been pondering on allowing but limiting operator overloading (math/vector types can get ”blessing” to use it but disallow it by default to discourage people from reinventing C++ iostreams).
Maybe the like deno one could design something similar to transitively bless modules/imports to do similar stuff.
2
u/AustinVelonaut Sep 17 '26
Is the mox compiler itself not open-sourced? I see
.moxlibrary modules in the repo, but no compiler sources.2
u/Milkmilkmilk___ Sep 20 '26
how are you running external functions at compile time?
2
u/[deleted] Sep 17 '26
[removed] — view removed comment