This is how D's CTFE (Compile Time Function Execution) works. You can execute at compile time any function, and it will work as long as the source code is available to the compiler, and it doesn't access globals or do pointer monkey business.
You can indeed build a program that runs completely at compiler time. Here's a compile time ray tracer in D circa 2006: