r/ProgrammingLanguages • • 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:

  1. How to decide rather to execute a function or keep the call in code
  2. Security concern about access to the system on compile time evaluation
  3. How to execute it without writing a separate interpreter
  4. Does llvm provide any supporting features for this

Thanks

19 Upvotes

17 comments sorted by

View all comments

Show parent comment

2

u/RedCrafter_LP May 14 '26

If the original 2 strings are never used elsewhere they never see the binary. Let's stick with your concatenation example with fictional std lib functions. const x = "Hello" + "World". Becomes string::add("Hello", "World") and since add is const "HelloWorld". End result const x = "HelloWorld".

The individual strings are never part of the program.