Re: CREATE
- From: Coos Haak <chforth@xxxxxxxxx>
- Date: Wed, 22 Jul 2009 02:45:32 +0200
Op Tue, 21 Jul 2009 16:28:14 -0700 (PDT) schreef Harold:
On Jul 21, 1:26 pm, Elizabeth D Rather <erat...@xxxxxxxxx> wrote:
MarkWills wrote:
Elizabeth said:
Another point that you seem to be missing is that DOCOL isn't the only
possible code field address. You've now added DOVAR to your repertoire,
but the important thing is that every defining word may have a unique
code field address (I say "may" because they don't *have* to be unique;
CREATE, VARIABLE, and BUFFER: may share the same, for example).
DOES> works by patching the default code field address left by CREATE in
an instance definition to point to the code following DOES> in the
defining word's definition.
Cheers,
Elizabeth
With regards to CREATE, I think that the decision to merge <BUILDS
into CREATE unnecessarily restricts certain implementation techniques.
Consider an architecture that has a limited number of one-byte fast
subroutine call instructions, e.g. the Intel 8080 RST, or the RCA 1802
SEP instructions. In a direct-threaded implementation, these one-byte
calls can be dedicated to the run-time semantics of the most common
defining words like CONSTANT, VARIABLE, USER, and docolon. But you
can't compile a one-byte call for a CREATE'd object, because you don't
know whether or not its runtime semantics are going to be overridden
by a later occurring DOES>. So a CREATE'd object has to be compiled as
a more general (i.e. larger and slower) subroutine call instruction
with a modifiable destination address, typically 3 or more bytes long.
If the default runtime semantics of a CREATE'd object are never
overridden with a later DOES>, this wastes space and time.
In the old Fig-Forth days, the word <BUILDS was a signal to the
compiler that there would be a following DOES>, so it needed to be
compiled with the more general subroutine call instruction that could
be overridden. On the other hand, the Fig-Forth CREATE couldn't be
followed by DOES>, so the compiler could use a (faster) one-byte
subroutine call instruction, actually the same runtime semantics as
VARIABLE. The only difference being that, at compile time, VARIABLE
also does a CELL ALLOT.
The decision to merge <BUILDS into CREATE prevents this sort of
optimization. ANSI Forth is usually pretty good at precluding
different implementation techniques, so I wonder whether the
standardization committee considered this issue when the decision was
made to eliminate <BUILDS.
Have good look at the CamelForth implementation for the 1802.
Indeed, it uses various SEP instructions for colon definitions,
CONSTANT and VARIABLE. But you can not tick them and use >BODY to
get to their contents. That's not even allowed in the Standard.
But words built with CREATE are tickable and subsequently >BODY will
return the correct data address. All according to the current
Standard.
--
Coos
CHForth, 16 bit DOS applications
http://home.hccnet.nl/j.j.haak/forth.html
.
- References:
- CREATE
- From: MarkWills
- Re: CREATE
- From: Andrew Haley
- Re: CREATE
- From: MarkWills
- Re: CREATE
- From: Coos Haak
- Re: CREATE
- From: Elizabeth D Rather
- Re: CREATE
- From: MarkWills
- Re: CREATE
- From: Elizabeth D Rather
- Re: CREATE
- From: MarkWills
- Re: CREATE
- From: Elizabeth D Rather
- Re: CREATE
- From: Harold
- CREATE
- Prev by Date: Re: CREATE
- Next by Date: Re: Ficl Forth working on the Nintendo DS
- Previous by thread: Re: CREATE
- Next by thread: Re: CREATE
- Index(es):
Relevant Pages
|
Loading