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
2
u/MindlesslyBrowsing May 14 '26
Well then if this optimization is so non-aggressive I'd say you can evaluate everything that just relies on const values. You can have it as like a compilation step.
The thing that might make it not worth is it taking more memory? For example if your const is two const strings combined and you evaluate it you're now storing double the amount it would just take to store the original two... Could be a matter of defining a ratio and tweaking to your liking.