[Tutor] Virtual Machine Terminology
Alan Gauld
alan.gauld at blueyonder.co.uk
Thu Apr 22 03:21:09 EDT 2004
> Is Python itself a virtual machine?
No. But the current implementations of Pyhon employ a
virtual machine architecture.
> A virtual machine is a machine written in software, which
> provides an abstract layer to applications. In a layered
> application the virtual machine acts as the lowest layer,
> providing abstraction over the native environment.
A virtual machine is a set of primitive operations soimilar
to those provided by assembler. These operations come with
an interpreter than translates them into native machine
code for the native platform (Unix, Windows, VMS etc)
Python for example compiles code into .pyc files. These
are the virtual machine executables but they are not
executable on the native machine (you need Python installed
to use them). You can see a representation of the pyc files
by using the Python disassembler module. You will see
Python assembler whilch looks a lot like a high level
native assembler language.
The Python interpreter then translates these assembler
codes into native machine code. This is much easier to
port than a full Python translator would be and is one
reason why Python is so portable. The virtual machine
(the pyc files) are the same its only the underlying
translation that differs.
Jython works slightly differently. It compiles python
source into Java Virtual assembler. Then you use the
standard Java translator to convert from JVM code to
native code. So the same Python source can run on the
Python virtual machine or a Java virtuial machine
depending on the compiler you choose. This shows that
it is not Python itself that is the virtual machine
but rather the implementation.
> This definition seems to fit almost any programming or
> scripting language. Is a BASH script which handles printing
> also then a virtual machine?
No. Many programming languages translate the source directly
into native machine code. Bash interprets commands directly
into executable code. Compiled C is simply native machine code.
VB, Perl, Python, Smalltalk, UCSD Pascal and others all use
a virtual machine approach.
Microsoft .NET platform is another example of a virtual machine.
Here it doesn't matter which language you use(VB.NET,
C#, Managed C++, Python.NET) it all gets translated
into the common runtime language. The .NET platform then
runs the program by translating the CLR code into Win32 code.
(There is at least 1 project working on translating NET
virtual machine to Linux...)
HTH,
Alan G.
More information about the Tutor
mailing list