Difference between revisions of "Virtual machine"

From IFWiki
Jump to: navigation, search
m (added to Category:Development)
(Substantial rewrite)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
The equivalent of a computer created in software rather than in hardware. Java programs, for example, run in a Java virtual machine. Virtual machines such as the [[Z-machine]], [[Glulx]], and the [[T3 VM]] make writing interactive fiction easier. Rather than compiling games for each of the new operating systems, authors compile the game only once for the virtual machine. The game can then be run under any operating system for which a version of the virtual machine exists.
+
A '''Virtual Machine''' or '''VM''' is a computer program which acts as a model of a computer itself. A major advantage of using VMs is that programs targeting the VM can be compiled once and run on any computer with an implementation of that VM, rather than having to be compiled for each different computer architecture and operating system. Other advantages include making it possible to use different programing styles due to the VM's abstraction of the physical system, and providing domain-specific interfaces which are not present in physical systems.
 +
 
 +
Interactive fiction has had a long association with virtual machines, as [[Infocom]] invented one of the earliest VMs, the [[Z-machine]]. They wrote implementations of the Z-machine for several computer systems of their day, and many others have written new implementations since then. Because of their use of the Z-machine it is still possible to run their decades-old games on modern computers without them needing to be recompiled.
 +
 
 +
==Interactive fiction virtual machines==
 +
Several virtual machines have been invented specially for interactive fiction. These include the [[Z-machine]], [[Glulx]] and the [[TADS]] VMs.
 +
<!-- Include brief descriptions of the VMs here? It might be useful to show some of the differences in the one place, such as Z-Machine having specific opcodes for the object model, Glulx having accelerated functions and floating point arithmetic, and TADS 3 having inheritance at the VM level. -->
 +
 
 +
==Implementation strategies==
 +
Programs for VMs are usually compiled to [[bytecode]], the format of which is an important part of each VM's specification. The bytecode will contain information about the type of code and which version of the VM it has been compiled for, the initial memory state the VM must be initalised with, and the actual code to run.
 +
 
 +
Most IF VM implementations consist of a loop which runs through the byte code, executing each instruction in turn. Such implementations are fairly straight forward to make, but may suffer from poor performance, a problem sometimes occurring for works written in [[Inform 7]].
 +
 
 +
A rarer strategy for implementations is to use a [[JIT]], a "just-in-time" compiler. No IF VMs currently use a JIT to compile directly to the hardware architecture, but several implementations written in dynamic languages do compile the bytecode to the same language or system which the interpreter itself is written in. However as these languages are frequently implemented in VMs which use JIT technology themselves, such implementations have the potential to run at near-native speeds. JIT compiling implementations include [[Gnusto]], [[Quixe]] and [[ZLR]].
  
 
==Links==
 
==Links==
* [[wikipedia:Virtual machine]]
 
 
* [[Past_raif_topics: Development: part 2#Virtual machines|Discussions about virtual machines]] on the rec.arts.int-fiction newsgroup
 
* [[Past_raif_topics: Development: part 2#Virtual machines|Discussions about virtual machines]] on the rec.arts.int-fiction newsgroup
 
[[Category:Glossary]] [[Category:Development]]
 
[[Category:Glossary]] [[Category:Development]]
 +
* [http://en.wikipedia.org/wiki/Virtual_machine Wikipedia article "Virtual machine"]
 +
* [http://en.wikipedia.org/wiki/Just-in-time_compilation Wikipedia article "Just-in-time compilation"]

Latest revision as of 03:53, 22 March 2011

A Virtual Machine or VM is a computer program which acts as a model of a computer itself. A major advantage of using VMs is that programs targeting the VM can be compiled once and run on any computer with an implementation of that VM, rather than having to be compiled for each different computer architecture and operating system. Other advantages include making it possible to use different programing styles due to the VM's abstraction of the physical system, and providing domain-specific interfaces which are not present in physical systems.

Interactive fiction has had a long association with virtual machines, as Infocom invented one of the earliest VMs, the Z-machine. They wrote implementations of the Z-machine for several computer systems of their day, and many others have written new implementations since then. Because of their use of the Z-machine it is still possible to run their decades-old games on modern computers without them needing to be recompiled.

Interactive fiction virtual machines

Several virtual machines have been invented specially for interactive fiction. These include the Z-machine, Glulx and the TADS VMs.

Implementation strategies

Programs for VMs are usually compiled to bytecode, the format of which is an important part of each VM's specification. The bytecode will contain information about the type of code and which version of the VM it has been compiled for, the initial memory state the VM must be initalised with, and the actual code to run.

Most IF VM implementations consist of a loop which runs through the byte code, executing each instruction in turn. Such implementations are fairly straight forward to make, but may suffer from poor performance, a problem sometimes occurring for works written in Inform 7.

A rarer strategy for implementations is to use a JIT, a "just-in-time" compiler. No IF VMs currently use a JIT to compile directly to the hardware architecture, but several implementations written in dynamic languages do compile the bytecode to the same language or system which the interpreter itself is written in. However as these languages are frequently implemented in VMs which use JIT technology themselves, such implementations have the potential to run at near-native speeds. JIT compiling implementations include Gnusto, Quixe and ZLR.

Links