Threaded Code - Common Amenities

Common Amenities

Separating the data and return stacks in a machine eliminates a great deal of stack management code, substantially reducing the size of the threaded code. The dual-stack principle was originated three times independently: for Burroughs large systems, Forth and PostScript, and is used in some Java virtual machines.

Three registers are often present in a threaded virtual machine. Another one exists for passing data between subroutines ('words'). These are:

  • ip or i (instruction pointer) of the virtual machine (not to be confused with the program counter of the underlying hardware implementing the VM)
  • w (work pointer)
  • rp or r (return stack pointer)
  • sp or s (parameter stack pointer for passing parameters between words)

Often, threaded virtual machines such as implementations of Forth have a simple virtual machine at heart, consisting of three primitives. Those are:

  • nest, also called docol
  • unnest, or semi_s (;s)
  • next

In an indirect-threaded virtual machine, the one given here, the operations are:

next: (ip)+ -> w ; jmp (w)+ nest: ip -> -(rp) ; w -> ip ; next unnest: (rp)+ -> ip ; next

This is perhaps the simplest and fastest interpreter or virtual machine.

Read more about this topic:  Threaded Code

Famous quotes containing the word common:

    The wildest dreams of wild men, even, are not the less true, though they may not recommend themselves to the sense which is most common among Englishmen and Americans to-day. It is not every truth that recommends itself to the common sense. Nature has a place for the wild clematis as well as for the cabbage. Some expressions of truth are reminiscent,—others merely sensible, as the phrase is,—others prophetic.
    Henry David Thoreau (1817–1862)