Threaded code: Difference between revisions

Content deleted Content added
Threading models: Indirect-threaded Forth is not that common nowadays.
Line 24:
==Threading models==
Common models of threaded code are:
* Indirect threading: The list of addresses in code point to an address at the start of a data area. The address at the start of the data area points at machine code to use the data. This "extra" pointer in indirect threading serves as an "executable data type" to define custom interpreters for data. The address at the start of each data area points to the code shared by all data areas of that type. Though somewhat slower than other models, the sharing of data-management code can save a lot of space, and no type interpretation is usually needed. MostAncient [[Forth programming language|Forth]] systems produceproduced indirect-threaded code.
* Direct threading: The addresses in the code are actually the address of machine language. This is a compromise between speed and space. The indirect data pointer is lost, at some loss in the language's flexibility, and this may need to be corrected by a type tag in the data areas, with an auxiliary table. Some [[Forth programming language|Forth]] systems have produced direct-threaded code. On many machines direct-threading is faster than subroutine threading (see reference below).
* Subroutine threaded code, in which the code is actually a list of subroutine calls. This is an obvious implementation method. Early compilers for [[ALGOL]], [[Fortran]], [[Cobol]] and some [[Forth programming language|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 implementation trades space for speed, since subroutine instructions are available in most computer designs. However, in many computer systems, indexed fetches are faster than subroutine calls, and in these computers, direct threading can be faster than subroutine threading.