I have read that the interpreter (VM) is a software that executes code. I have also read that the CPU executes the instructions. What is the difference between the two execution? The VM does not convert the byte code into machine code. What does it do exactly?
-
1Your CPU (if it's an x86) is not that different from a typical ad hoc VM interpreter. It translates the high level instructions into sequences of microcode instructions which are executed "directly". – SK-logic Nov 18 '15 at 15:03
1 Answers
The VM does not convert the byte code into machine code.
A virtual machine does convert the bytecode into machine code. That is precisely its main purpose, because it allows you to execute your program on every OS and architecture where the virtual machine is present, without the need to recompile it. Plus it can do other things, like security controls etc.
EDIT
I am more used to the Java world, where the virtual machine actually compiles the bytecode into CPU instructions, in order to speed up (a lot) things. It seems however that in Python the code to fulfill those instructions is instead part of the interpreter, which simply read your program and do internally what is needed for. I suggest you to read your link, which seems to be quite explaining. Plus, I have read somewhere that Python is introducing a JIT compiler too.

- 801
- 3
- 9
- 17
-
but the explanation here ( http://stackoverflow.com/a/3299724/1358676 ) differs... or am I missing something? – codingsplash Nov 17 '15 at 11:58
-
1@user567: maybe you missed that that linked answer is specific to a particular implementation/version of a Python interpreter. You didn’t put anything into your question indicating that it’s meant to be Python-specific. – Holger Nov 17 '15 at 12:20
-
1