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/RedCrafter_LP May 14 '26
Yes mutable state is a thing in my language. I'm thinking of just marking core side effect functions like write and read as non const. I don't want to do the hunt through the std library to mark every function possible const like they are currently doing in rust. My language does constness by default. There is a keyword to make a function non const instead. This is exactly why I'm unsure about scope. Folding every function call that only depends on function arguments or constants could take a long time unintentionally when someone is calling a large chain of self contained functions that have literal arguments at the very top.