4 ms·
An interpreted language has a runtime that is essentially a function “i(script: string)” that immediately follows the instructions encoded in the string. A com
by jiggawatts 1y ago
An interpreted language has a runtime that is essentially a function “i(script: string)” that immediately follows the instructions encoded in the string.
A compiler is a function “c(script: string) -> byte[]” that instead of running the script, outputs a binary that does the same thing as the interpreter, but more efficiently.
Commonly this means converting the human-readable script syntax to binary machine code that a CPU can run directly, but platforms like Java and .NET actually do this through multiple steps with an intermediate “byte code” that CPUs can’t execute without a lightweight runtime.
The benefit of the JIT is that it makes the compiler code portable to other CPU architectures without having to ship the source code. It is simple enough that interpreting it is just a “while” loop that bumps a pointer, reads the next instruction bytes, and uses a giant switch table to decide what to do.
If you squint at it, machine code is the same, except that the “loop and switch statement” is hard wired into the silicon.