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
2
u/whizzter Sep 17 '26
Right, I got thinking in terms of script-less building, project/package source files/roots can specify required packages/commands and if needed also bless them if they have any right point in doing I/O (comp or runtime).
I mean, since you can exec from the source, is there any tasks that can’t be customized and all non-language build tools becomes superfluous? (And hence, once you control from sourcecode, external invocations can be traced by the build tools).
The C/C++ culture is special because package managers appeared afterwards, could a modern language (unless targeting the C/C++ demographic) succeed without easy access to packages? (Or extreme hype)