Re: [phix] what is a hybrid interpreter compiler?

new topic     » goto parent     » topic index » view thread      » older message » newer message

First and foremost Phix is (internally) a compiled language:

source -> tokens -> il -> hardware-specific [x86/64] machine code -> executable file -> run (from disk). 

However, by default (no -c flag on the command line) it behaves as an interpreter:

source -> tokens -> il -> hardware-specific [x86/64] machine code -> run (in memory). 

Four points regarding interpretation:
1: It executes just(/almost) as fast as compiled
2: Obviously omitting the disk write step means it is actually faster
3: Writing an exe usually triggers an anti-virus scan/stall before it can be run.
4: In practice interpretation omits some optimisation steps performed when compiling.

The "il" (intermediate language/representation) used internally by Phix is like an AST (abstract syntax tree) but is actually a flat linear list (with self-contained links) for improved performance reasons.

The main optimisation omitted during interpretation is "constant/type propagation", for instance in

function lower(object s) 
    if atom(s) then --- (a single character) 
        ... 
    elsif string(s) then 
        ... -- [2] 
    else            -- (a nested sequence) 
        ... 
    end if 
end function 

the compiler analyses the il and might find that in all calls to lower, s is a string. It can then only emit the middle [2] block and does not even have to emit the string test. Obviously you end up with a smaller and faster executable, but on average the cost of that analysis is more than what you save at runtime, acceptable and still a good move for compilation [any loss dwarfed by disk io & av checks anyway], however (usually) simply not worthwhile for interpretation.

The message we want to deliver is 1: no waiting for the compiler (eg Go is often touted as a fast compiler, but I almost always end up drumming my fingers waiting for it to start), and 2: interpretation does not mean slow.

In "hybrid interpreter/compiler" I suppose hybrid really just means "both". There does seem to be a common association of "hybrid" with "jit", which Phix is not.

Erm, yeah, I guess this probably deserves a paragraph/section all of it's own.

PS No argument that Go has a blindingly fast runtime, way better than Phix, it's the compile-time I find tardy.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu