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
View all comments
Show parent comment
1
u/morglod Sep 20 '26
Yeah there was a lot of stuff. Most part solved for me custom JIT, because after having it, I can do this interp->native->interp jumps easier.