Talk:Threaded code
From Wikipedia, the free encyclopedia
[edit] subroutine call techniques: All code is threaded code?
The article currently claims
- Threaded code is used in the Forth and early versions of the B programming languages, as well as many implementations of FORTRAN, BASIC, COBOL and other languages for small minicomputers.
then later
- Early compilers for ALGOL, Fortran, Cobol and some Forth systems often produced subroutine-threaded code.
It sounds like someone was confused by the people who call native machine language, "subroutine threaded code", which most people would say is the .opposite of threaded code. If "subroutine threaded code" is a kind of threaded code, then practically all code is threaded code of one kind or another. (The only exception is code that doesn't have *any* subroutines, right?).
I think Chuck Moore developed the term "threaded code" to describe Forth, meaning indirect threaded code or direct threaded code.
Did any of these other compiler/interpreters really generate indirect threaded code or direct threaded code ? I know some BASIC and PASCAL compilers generate "p-code" ...
--DavidCary 12:37, 13 July 2005 (UTC)
I am very interested in the variety of subroutine call techniques (what some people call the kinds of "threading model").
There's a nice discussion developing here, but it's starting to drown out what most people think of as "threaded code" (indirect-threaded code and direct-threaded code).
Is there a better article somewhere else (or a good name for an article, if one doesn't exist yet) to talk about subroutine call techniques in general, leaving this article to focus on ITC and DTC ?
--DavidCary 12:37, 13 July 2005 (UTC)
- Subroutine threaded code is different from native code in that everything is a call; including to constructs like IF. Take this code in Forth;
: X IF ." True" THEN ... etc
- An STC potentially generates (numbers are there to discuss in text)
(1) CALL <routine to put "label" on return stack> (2) CALL IF (3) CALL <routine to put address of string "True" on the stack> (4) CALL ." (5) <label>: (6) CALL THEN ... etc
- (1) "tucks" the address of the label <label> on the return stack by popping the caller's return address, pushing address of <label> and returning. (2) IF pops and checks the top of the data stack; if it's zero, then jump to label, else return. And so on. (6) is in fact a no-op, but it's sometimes generated so that the code can be decompiled easily by printing off the labels in the symbol table (called a dictionary in Forth) associated with the CALLed address.
- There are very few Forths that use STC in this extreme form, and a blend between STC and NCC (native code compilation) is normally used. An ITC is the same code, but with addresses only and no CALL opcode; a small VM interpreter does the call/return management. Alex 12:00, 27 March 2006 (UTC)
-
- ITC above should refer to DTC; sorry Alex 20:23, 27 March 2006 (UTC)
[edit] types of subroutine-call instructions supported by hardware
I removed In some computers there are different types of subroutine-call instructions using different lengths of addresses. In these, the programmers could often arrange to use a shorter form by using threaded code. because I don't see how it is relevant -- a threaded call is always shorter than even the shortest subroutine-call instruction.
I removed Threading is ... processed by ... the CPU (B), because the CPUs I am familiar with cannot directly process threaded code (except for so-called "subroutine threaded code"). But it is theoretically possible that some CPU has special hardware to directly process threaded code -- does such a CPU really exist ? --DavidCary 12:37, 13 July 2005 (UTC)
- Yes; see [Stack machine] and hardware specifically designed to run threaded code. Alex 12:03, 27 March 2006 (UTC)
- Sorry, stack machine Alex 14:29, 27 March 2006 (UTC)
[edit] Brad Rodriquez's articles
Could someone add a link to Brad Rodriquez's "Moving Forth" articles? http://www.zetetics.com/bj/papers/
Also, I think 'w' is 'working register' not 'word pointer'.
—The preceding unsigned comment was added by 68.60.59.250 (talk • contribs) 13:17, 20 April 2006 (UTC2)