r/ProgrammingLanguages • u/RedCrafter_LP • May 14 '26
Help Compile time evaluation
I want to include compile time evaluation in my language.
For context I have most of the language design and compiler planned out and am currently implementing it. Currently writing the parser that turns a stream of tokens into the ast. The plan is to target llvm ir for the moment.
While I have enough to do before I have to address it I want to get some information about executing code at compile time. I am explicitly not talking about macros for them I already have an idea. My questions are:
- How to decide rather to execute a function or keep the call in code
- Security concern about access to the system on compile time evaluation
- How to execute it without writing a separate interpreter
- Does llvm provide any supporting features for this
Thanks
19
Upvotes
View all comments
Show parent comment
3
u/AttentionCapital1597 May 15 '26
You can totally avoid UB, unless you indeed expose capabilities of the hardware that are impossible to define ahead of time (like accessing uninitialized/unowned memory). If you want a general purpose language i recommend you keep those things out. Plenty of GP languages get away with that and in turn get to be 100% defined (Java or Python e.g.).
Re inverting const/pure modifiers: that checks out and will do the trick IMO Though be aware that constness is a kind of function coloring. If you must have it, i recommend making the more powerful variant the default (in this case impure). That would be like making every function
asyncby default (i think Go does that) orthrowsby default (e.g. C++, Python, JS, and most JVM Ghosts do that).