Re: [phix] what is a hybrid interpreter compiler?
- Posted by petelomax Jan 30, 2021
- 1114 views
Is this a valid understanding?
Almost. Forget about "IL" - almost every compiler has some form of it, and certainly any that produce efficient machine code.
But it sends the wrong message: some (slow) interpreters run IL on a VM, whereas Phix is more like C & libc (only asm-based).
As an ''interpreter''
- Phix reads, parses, makes executable code, then executes it (directly from memory)
As a ''compiler''
- as above but saves the executable code to a file, which it then executes[*]
- you can run the program at any time (and ship it, no need for Phix anymore)
[*] unless -norun is specified on the command line
Note: interpretation is often noticably faster than compilation because writing an executable file usually wakes up an anti-virus program which then stalls proceeedings (for ~1s).
However, the last stage of compilation also performs some additional optimisation steps, so sometimes but not always that ends up faster.
errors are detected and reported in a programmer friendly way
That is not a separate step, errors can occur at any stage, for instance illegal characters in the read stage, and
non_existent_routine() is in fact only reported after the machine code has been generated, when it finds it still
present on some "todo" list. Mention it before or after, sure, but not as part of the interpreter/compiler distinction.