On Thu, 22 Aug 2019 11:46:58 -0000 (UTC)
Krishna Myneni <
krishna...@ccreweb.org> wrote:
Both Anton and Andrew (aph) know that VARIABLE and CONSTANT was
historically implemented with CREATE like so:
https://groups.google.com/d/msg/comp.lang.forth/FLod-QnyTUI/wpmE4aeYIMoJ
With Google Books, you can find those /EXACT/ definitions in books
on Forth from 1981 to 2018, or with slight variations, e.g.,
: VARIABLE CREATE 2 ALLOT ;
So, since apparently every book on Forth ever written does it that way,
I'm really not sure what Anton and Andrew mean when they say **many**
Forths don't do it that way ...
Of course, I believe that historical behavior should be preserved, as
much as possible. So, let's look at fig-FORTH did for a moment.
fig-FORTH's BASE and STATE are created with USER. fig-FORTH's code
defines VARIABLE and USER in terms of CONSTANT. fig-FORTH's standard
states that CREATE is to be used to implement defining words, i.e.,
CONSTANT CODE USER VARIABLE VOCABULARY , specifically mentioning CODE
and CONSTANT .
So, we have: BASE & STATE -> USER -> CONSTANT -> CREATE
In fig-FORTH and Forth-79, ' (tick) returns the PFA. In Forth-83,
' (tick) returns the CFA. In Forth-94, ' (tick) returns an XT .
So, >BODY was introduced with Forth-83 to get from the CFA to PFA.
However, if fig-FORTH was modified to return the CFA or XT for ' (tick),
then >BODY would always work as every constant or variable in fig-FORTH
eventually calls CREATE . As you can see from excerpts from Forth-83,
there was no mention of an ambiguous condition for >BODY if the word
wasn't defined by CREATE, implying that CREATE was always used by
constants and variables for Forth-83. This disclaimer was added in
Forth-94 for >BODY with the introduction of XTs .
I've brought up this issue in the past, as have others over the years.
So, I'm not real sure why they're so strongly opposed to this i.e.,
having all variables and constants work with >BODY . That was clearly
historical behavior that should be preserved. It would also certainly
help with compatibility, consistency, and portability. Maybe, it has
something to do with compiled Forths? ...
In addition to the fig-FORTH code, I've posted excerpts from fig-FORTH,
Forth-79, Forth-83 for the definitions of CREATE CONSTANT VARIABLE for
your reference below, but nothing from Forth-94, Forth-2012 etc.
Rod Pemberton
fig-Forth:
CREATE
A defining word used in the form:
CREATE cccc
by such words as CODE and CONSTANT to create a
dictionary header for a Forth definition. The code field
contains the address of the word's parameter field. The
new word is created in the CURRENT vocabulary.
CONSTANT n --- L0
A defining word used in the form:
n CONSTANT cccc
to create word cccc, with its parameter field containing
n. When cccc is later executed, it will push the value
of n to the stack.
VARIABLE E,L0
A defining word used in the form:
n VARIABLE cccc
When VARIABLE is executed, it creates the definition
cccc with its parameter field initialised to n. When
cccc is later executed, the address of its parameter
field (containing n) is left on the stack, so that a
fetch or store may access this location.
2 : CREATE ( A SMUDGED CODE HEADER TO PARAM FIELD *)
3 ( WARNING IF DUPLICATING A CURRENT NAME *)
4 TIB HERE 0A0 + < 2 ?ERROR ( 6502 only )
5 -FIND ( CHECK IF UNIQUE IN CURRENT AND CONTEXT )
6 IF ( WARN USER ) DROP NFA ID.
7 4 MESSAGE SPACE ENDIF
8 HERE DUP C@ WIDTH @ MIN 1+ ALLOT
9 DP C@ 0FD = ALLOT ( 6502 only )
10 DUP A0 TOGGLE HERE 1 - 80 TOGGLE ( DELIMIT BITS )
11 LATEST , CURRENT @ !
12 HERE 2+ , ;
1 : CONSTANT ( WORD WHICH LATER CREATES CONSTANTS *)
2 CREATE SMUDGE , ;CODE
3 2 # LDY, W )Y LDA, PHA, INY, W )Y LDA, PUSH JMP,
4
5 : VARIABLE ( WORD WHICH LATER CREATES VARIABLES *)
6 CONSTANT ;CODE
7 CLC, W LDA, 2 # ADC, PHA, TYA, W 1+ ADC, PUSH JMP,
10 : USER ( CREATE USER VARIABLE *)
11 CONSTANT ;CODE
12 2 # LDY, CLC, W )Y LDA, UP ADC, PHA,
13 0 # LDA, UP 1+ ADC, PUSH JMP,
Forth-79:
CREATE 239
A defining word used in the form:
CREATE <name>
to create a dictionary entry for <name>, without allocating
any parameter field memory. When <name> is subsequently
executed, the address of the first byte of <name>'s parameter
field is left on the stack.
CONSTANT n -- 185
A defining word used in the form:
n CONSTANT <name>
to create a dictionary entry for <name>, leaving n in its
parameter field. When <name> is later executed, n will be
left on the stack.
VARIABLE 227
A defining word executed in the form:
VARIABLE <name>
to create a dictionary entry for <name> and allot two bytes
for storage in the parameter field. The application must
initialize the stored value. When <name> is later executed,
it will place the storage address on the stack.
Forth-83:
CREATE --
M,79 A defining word executed in the form:
CREATE <name>
Creates a dictionary entry for <name>. After <name> is
created, the next available dictionary location is the
first byte of <name>'s parameter field. When <name> is
subsequently executed, the address of the first byte of
<name>'s parameter field is left on the stack. CREATE
does not allocate space in <name>'s parameter field.
CONSTANT 16b --
M,83 A defining word executed in the form:
16b CONSTANT <name>
Creates a dictionary entry for <name> so that when
<name> is later executed, 16b will be left on the stack.
VARIABLE --
M,79 A defining word executed in the form:
VARIABLE <name>
____
A dictionary entry for <name> is created and two bytes
are ALLOTted in its parameter field. This parameter field is
to be used for contents of the variable. The application is
responsible for initializing the contents of the variable
which it creates. When <name> is later executed, the
address of its parameter field is placed on the stack.
>BODY addr1 -- addr2 83
"to-body" addr2 is the parameter field address corresponding
to the compilation address addr1. See: "9.2 Addressable
Memory"
' -- addr M,83
"tick" Used in the form:
' <name>
addr is the compilation address of <name>. An error
condition exists if <name> is not found in the currently
active search order.
--
Facebook privacy is like a leaky bucket of water.