Andreas wrote
Hi,
In the book we write the VM translator in any high level language of our choice. However, this assumes that the high level language of our choice compiles on the Hack computer.
The VM Translator runs on
your computer and translates .vm files to .asm files. I wrote my VM Translator in Python. Writing a native VM is a much harder task and requires a much more sophisticated computer than Hack to run on.
In the real world, how would you write a VM? Surely it would have to be written in assembly code, which therefore suggests that it would have to be tailored to run on each architecture. However, this then takes us back to a problem which we were resolving by implementing the VM -- we don't need to have a custom compiler for each architecture (and thus it becomes very portable). However, we have a high level language compiling into an intermediate language, which is then converted (using the machine's language) into the machine language.
The Java VM is written in C/C++. The platform specific compilers allow it to run on the various different target hardware. Libraries have been written, also in C/C++, that interface with the target operating systems. When you download Java for a 32-bit Windows system you get a binary that is targeted to 32-bit Intel processors linked with the appropriate Windows support library. In the real world we write as little assembly code as possible.
For the embedded systems programming I do, the tools (compilers, etc.) run on Windows and only the binaries get loaded onto the actual hardware. All the code is written in C with a few small assembly language routines. 512K ROM and 64K RAM is a big configuration.
Also, with the Hack machine it shouldn't be possible to have the VM written in Jack, because in order to compile the Jack code to form the VM program you would need to translate it using the VM, so you would end up in an infinite loop.
Modern C/C++ compilers are written using earlier versions of themselves. The first C compiler was probably written in B, a precursor to the C language.
In college, we had to write an assembler in assembly language. It was written using the system supplied assembler, but the final for the course was to run our assembler through itself and show that it generated the correct output!
--Mark