3 ms·
It says V8 compiles JavaScript to Machine Code, but is that really correct given that the machine code is an intermediate product, and the result of applying a
by amelius 8y ago
It says V8 compiles JavaScript to Machine Code, but is that really correct given that the machine code is an intermediate product, and the result of applying a JIT to a specialized piece of code (where part of the variables are already known to the compiler)?
- chrisseaton 8y ago> given that the machine code is an intermediate product The machine code isn't the intermediate product - it's the final product. Some internal IR is the intermediate product. But yes it's normal convention in the industry to talk about JIT compilation to machine code as 'compiling to machine code'.
- amelius 8y agoBut let's say, they added "decompilers" to the graph, and there is (say) a decompiler from machine code to C. Then I'd assume, because there is a path in the graph from JavaScript to C (going through machine code), that I can translate from JavaScript to C. Except this isn't true because V8 is a JIT, and doesn't output its internal representation.
- chrisseaton 8y agoIt's not a graph of compilers to a file on disk. It's a graph of compilers. Just because it exists only in memory doesn't mean it doesn't exist. Has the JavaScript been compiled to machine code. Yes, it has. You mean that the JavaScript compilation is only valid for a given application at a given point in time? Yes that's true.
- amelius 8y agoWhat I meant is: the graph is more useful if you can apply the relations transitively (i.e. find one or more paths between any two languages, and use the compilers to walk along the path). The demo even suggests that by allowing you to find a path, and leave the "directly" box unchecked.
- pierrec 8y agoI guess what you're saying is that machine code is an "intermediate product" in the sense that the final product must include the compiler, and the machine code produced by a JIT compiler is useless by itself. And I agree with your overall point, JIT compilers and VMs shouldn't be in there. You might as well include all interpreters. If you look at a JIT compiler as a black box, it acts like an interpreter, and I'm pretty sure this is meant as a practical graph ("what can I do with this language") rather than one that describes the internals of compilers and interpreters.