views:

43

answers:

3

If I am correct in understanding what I've read a virtual machine is essentially a compiler for intermediate code. But it is never said that Delphi (as an example of unmanaged code) runs in its compiler. Would it be less confusing to just describe a virtual machine as a compiler?

+2  A: 

A traditional compiler does a one-time conversion from source code to object code. A virtual machine like the JVM uses a mixture of interpretation (of bytecode) and a just-in-time compiler that compiles segments of bytecode to native code. It's not accurate to describe a VM overall as a compiler.

Matthew Flaschen
A mixture of an interpreter and a compiler with the machine metaphor used solely to indicate that it's an ongoing process, perhaps?
culchie
+1  A: 

There's a compiler that translates source code to VM code (bytecode), and a JIT compiler for VM code -> machine code. The VM is the standard that the source code -> VM compiler targets, not necessarily the specific implementation. It could be implemented with a real machine, in which case it wouldn't need to do JIT compilation.

A VM is closer to an emulator (or if your JIT is really stupid, an interpreter :))

Merlyn Morgan-Graham
"The VM is the standard" I prefer that way of looking at it, ie as a language specification for an intermediate language.
culchie
But intermediate code being closer to machine code (than source code) runs on a less virtual machine than high level source code (that will only run in your head!)
culchie
Not necessarily. Interpreters run source code, too. They might have to chop it up a few times to digest it, but they still run the code directly, without an explicit compilation stage.
Merlyn Morgan-Graham
+1  A: 

I think what people are trying to capture with the terminology is that there's an extra layer of abstraction with virtual machines. So, same code, but the VM for each platform allows it to run on that specific platform.

Carlos
Again it's probably because I don't fully get it but something like part-assembled code and final-compiler-interpreter seems to work better for me
culchie