Threaded code: Difference between revisions

Content deleted Content added
BurntSky (talk | contribs)
m fixed ambiguous link
Line 42:
*So-called "subroutine threaded code", a series of native machine language "call" instructions. This is not threaded code in the original sense, since the instructions are directly executed, without any interpretation. Early compilers for [[ALGOL]], [[Fortran]], [[Cobol]] and some Forth systems often produced subroutine-threaded code. The code in many of these systems operated on a first-in-first-out stack of operands, which had well-developed compiler theory. Many people believe that this is the fastest threading model, since all modern processors have special hardware support for such subroutine "call" instructions. But according to measurements by Anton Ertl, "in contrast to popular myths, subroutine threading is usually slower than direct threading."
 
*Token Threaded Code uses lists of 8 or 12-bit indexes to a table of pointers. Token threaded code is notably compact, without much special effort by a programmer. It is usually half to three-fourths the size of other threaded-codes, which are themselves a quarter to an eighth the size of compiled code. The table's pointers can either be indirect or direct. Some Forth compilers produce token threaded code. Some programmers consider the "[[p-code]]" generated by some Pascal compilers to be token threaded code. Some programmers consider the [[byte code]]s used by [[Microsoft .NET Framework|.NET]], [[Java programming language|Java]], [[Basic programming language|Basic]] and some [[C programming language|C]] compilers to be token-threading.
*Huffman Threaded Code consists of lists of [[Huffman code]]s. A Huffman code is a variable length bit string used to identify a unique item. A Huffman-threaded interpreter locates subroutines using an index table or tree of pointers that can be navigated by the Huffman code. Huffman threaded code is one of the most compact representations known for a computer program. Basically the index and codes are organized by measuring the frequency that each subroutine occurs in the code. Frequent calls are given the shortest codes. Operations with approximately equal frequencies are given codes with nearly equal bit-lengths. Most Huffman-threaded systems have been implemented as direct-threaded Forth systems, and used to pack large amounts of slow-running code into small, cheap [[microcontroller]]s. Most published uses have been in toys, calculators or watches.