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/morglod Sep 17 '26
Hm, probably good solution for this is to have registry of hand picked and moderated "packages" (mostly because of vibecoding).
Dont have answer for now.
Compiler's comptime could work in interpreter mode fully, so I could catch external calls. May be when it became a problem, it could be solved by having whitelist of things that could be called externally at comptime