umouse

umouse.git
git clone git://git.lenczewski.org/umouse.git
Log | Files | Refs | Submodules | README

A0007.HTM (16914B)


      1 <title>ANS Forth RFI 0007: distinction between "immediacy" and
      2 "special compilation semantics"</title>
      3 
      4 This document is produced by TC X3J14 as its clarification of questions
      5 raised about ANSI X3.215-1994, American National Standard for Information
      6 Systems - Programming Languages - Forth.
      7 
      8 <p>
      9 The questions covered herein were raised by query
     10 
     11 <p>
     12 Q0007, regarding the distinction between "immediacy" and "special
     13         compilation semantics".
     14 
     15 <p>There are four parts in this document:
     16 
     17 <ol>
     18 <li><a href="#query">The original question as received.</a>
     19 <li><a href="#reply">The TC's reply.</a>
     20 <li><a href="#ballot">The Letter Ballot issued by TC Chair.</a>
     21 <li><a href="#results">TC Chair's statement of ballot results.</a>
     22 </ol>
     23 
     24 <h2><a name="query">Q0007 as received</a></h2>
     25 
     26 <pre>
     27 Subject: Q0007 Request Recognized & Draft 0
     28 To: X3J14@minerva.com
     29 Cc: wykoh@pado.krict.re.kr
     30 Date: Sat, 23 Dec 95 02:11:38 PST  
     31 </pre>
     32 
     33 The following query has been assigned number Q0007.
     34    - Greg Bailey, by direction  951223 0700Z
     35 <hr>
     36 Wonyong Koh wrote on Fri, 22 Dec 95 16:27:03 PST  <a href=dpans6.htm#6.1.0450>:</a>
     37 
     38 <i><blockquote>
     39 Dear Mr. Bailey,
     40 
     41 <p>
     42    I would like you to ask to interpret the ANS Forth Stanard.
     43 You might already know about it. In recent discussion in comp.
     44 lang.forth I and Mr. Jonah Thamas have different opinion on
     45 <a href=dpans6.htm#6.1.0950>CONSTANT</a>. I interpret that making <a href=dpans6.htm#6.1.0950>CONSTANT</a> create <a href=dpans6.htm#6.1.1710>IMMEDIATE</a>
     46 words does not violate ANS Standard while Mr. Thomas thinks
     47 it does. 
     48 
     49 <p>
     50    I think that it is a obvious choice to make <a href=dpans6.htm#6.1.0950>CONSTANT</a> words
     51 STATE-smart in subroutine-threaded Forth (i.e. native Forth
     52 compiler). <a href=dpans6.htm#6.1.1710>IMMEDIATE</a> <a href=dpans6.htm#6.1.0950>CONSTANT</a> words pushes a number on top of
     53 the stack in interpretation state while compiles in-line
     54 machine code in compilation state. I beleive that it is not
     55 TC's intention to leave significant number of native-code
     56 Forth compilers out of ANS Standard System. Please clarify this.
     57 
     58 <pre>
     59 Wonyong Koh
     60 wykoh@pado.krict.re.kr
     61 </pre>
     62 </blockquote></i>
     63 
     64 <h2><a name="reply">TC Reply to Q0007</a></h2>
     65 
     66 <pre>
     67 From: Elizabeth Rather
     68 Subject: Q0007R, "immediacy" and "special compilation semantics", Official Response
     69 To: X3J14 Technical Committee
     70 Cc: lbarra@itic.nw.dc.us
     71 Date: Mon, 19 Feb 96 14:10
     72 
     73 
     74 Doc#:  X3J14/Q0007R
     75 Reference Doc#:  X3.215.1994 ANS Forth
     76 Date:  February 19, 1996
     77 Title: Response to Request for Interpretation Q0007, Clarifying the
     78 distinction between "immediacy" and "special compilation semantics"
     79 </pre>
     80 
     81 <h3>Q0007:  Clarifying the distinction between "immediacy" and
     82         "special compilation semantics".</h3>
     83 
     84 Wonyong Koh wrote on Fri, 22 Dec 95 16:27:03 PST:
     85 
     86 <i><blockquote>
     87 Dear Mr. Bailey,
     88 
     89 <p>
     90    I would like you to ask to interpret the ANS Forth Stanard.
     91 You might already know about it. In recent discussion in comp.
     92 lang.forth I and Mr. Jonah Thamas have different opinion on
     93 <a href=dpans6.htm#6.1.0950>CONSTANT</a>. I interpret that making <a href=dpans6.htm#6.1.0950>CONSTANT</a> create <a href=dpans6.htm#6.1.1710>IMMEDIATE</a>
     94 words does not violate ANS Standard while Mr. Thomas thinks
     95 it does.
     96 
     97 <p>
     98    I think that it is a obvious choice to make <a href=dpans6.htm#6.1.0950>CONSTANT</a> words
     99 STATE-smart in subroutine-threaded Forth (i.e. native Forth
    100 compiler). <a href=dpans6.htm#6.1.1710>IMMEDIATE</a> <a href=dpans6.htm#6.1.0950>CONSTANT</a> words pushes a number on top of
    101 the stack in interpretation state while compiles in-line
    102 machine code in compilation state. I beleive that it is not
    103 TC's intention to leave significant number of native-code
    104 Forth compilers out of ANS Standard System. Please clarify this.
    105 
    106 <pre>
    107 Wonyong Koh
    108 wykoh@pado.krict.re.kr
    109 </pre>
    110 </blockquote></i>
    111 
    112 Wonyong Koh is literally correct, in the sense that optimizing
    113 compilers which add special compilation semantics to classes of
    114 definitions such as  CONSTANTs  are specifically supported by
    115 ANS Forth.  Applying the concept, in these terms, to ANS Forth
    116 has very clear meaning and leads to no inconsistencies.
    117 
    118 <p> However, using the term "immediate" to speak of such compilation
    119 semantics is not recommended since this term carries with it all of
    120 the implications of the implementation model prescribed by earlier
    121 standards such as FORTH-83.  Attempting to discuss the advanced
    122 capabilities available to ANS Forth compilers in terms of "immediacy"
    123 ineviteably leads to confusion, misunderstanding, and the eventual
    124 "discovery" of apparent inconsistencies that do not, in fact, exist in
    125 the Standard (although they may indeed exist in a particular
    126 implementation.)  This in turn can lead to arguments over moot points.
    127 
    128 <p>
    129 In particular, a  <a href=dpans6.htm#6.1.0950>CONSTANT</a>  with special compilation semantics
    130 is *not* the same thing as is a  <a href=dpans6.htm#6.1.0950>CONSTANT</a>  declared as follows:
    131 
    132 <pre>
    133      123 <a href=dpans6.htm#6.1.0950>CONSTANT</a> JOE  <a href=dpans6.htm#6.1.1710>IMMEDIATE</a>
    134 </pre>
    135 
    136 ... but in ANS Forth terms, this usage is the *only* sense in
    137 which the word "immediate" or the concept of "immediacy" is
    138 defined or meaningful.  Always discuss ANS Forth compilation
    139 semantics as such, not as "immediacy", for clarity and to avoid
    140 pitfalls, even when discussing an implementation that uses
    141 classical immediacy as its way for expressing compilation
    142 semantics.
    143 
    144 <h3>Analysis of Specific Case</h3>
    145 
    146 However, upon review of the usenet discussion you reference, it would
    147 appear that you may have added special compilation semantics to
    148 CONSTANTs without adding all of the communication with the compiler
    149 that is necessary to deliver the proper semantics in all cases when
    150 such CONSTANTs are used.  The test case that failed seems likely to
    151 have encountered one of these probable inconsistencies, as opposed to
    152 "caring" whether the <a href=dpans6.htm#6.1.0950>CONSTANT</a> definition in question was "immediate"
    153 in your implementation as such.
    154 
    155 <p>
    156 At the same time, the ability to declare an <a href=dpans6.htm#6.1.1710>IMMEDIATE</a> constant,
    157 as in   123 <a href=dpans6.htm#6.1.0950>CONSTANT</a> JOE  <a href=dpans6.htm#6.1.1710>IMMEDIATE</a>   had been precluded.
    158 
    159 <p>
    160 Careful review of the semantic requirements for definitions
    161 when used in compilation, interpretation, and execution, as
    162 well as the results of obtaining execution tokens and using
    163 them with  <a href=dpans6.htm#6.1.1370>EXECUTE</a>  or  <a href=dpans6.htm#6.2.0945>COMPILE,</a> , and when referenced
    164 following  <a href=dpans6.htm#6.2.2530>[COMPILE]</a>  (if  <a href=dpans6.htm#6.2.0945>COMPILE,</a>  or  <a href=dpans6.htm#6.2.2530>[COMPILE]</a> are to
    165 be supported) should make it clear that significant flow of
    166 information is required between the compiler and the definition
    167 when extending normally "default" compilation and/or
    168 interpretation semantics of compliant definitions.
    169 
    170 <p>
    171 *The standard does not define the way in which this information
    172 flow takes place.*  While a standard program may extend "macros"
    173 such as control flow words as illustrated in the examples,
    174 it is not possible to define words of the sort that normally
    175 have "default" compilation and interpretation semantics such
    176 that they have special compilation or interpretation semantics
    177 without depending on implementation specific knowledge.  If
    178 this is done without knowing how to communicate with the
    179 compiler, the resulting definitions may deliver the correct
    180 semantics in *some*, but cannot in *all*, cases.
    181 
    182 <p>
    183 For example, consider a Standard Program that adds special
    184 compilation semantics to  <a href=dpans6.htm#6.1.1290>DUP</a>  as in the following example:
    185 
    186 <pre>
    187     <a href=dpans6.htm#6.1.2410>VARIABLE</a> #DUPS
    188     <a href=dpans6.htm#6.1.0450>:</a> <a href=dpans6.htm#6.1.1290>DUP</a>   1 #DUPS <a href=dpans6.htm#6.1.0130>+!</a>  <a href=dpans6.htm#6.1.2033>POSTPONE</a> <a href=dpans6.htm#6.1.1290>DUP</a> <a href=dpans6.htm#6.1.0460>;</a>  <a href=dpans6.htm#6.1.1710>IMMEDIATE</a>
    189 </pre>
    190 
    191 If all this did was to count compilations of <a href=dpans6.htm#6.1.1290>DUP</a>, it would
    192 be compliant since the additional work done affects nothing
    193 else and is therefore OK (See section 3.)
    194 
    195 <p>
    196 However, this definition does not comply because it does not
    197 yield the correct semantics in all cases.
    198 
    199 <ul>
    200  <li> It compiles correctly
    201  <li> It interprets incorrectly
    202  <li> (what it compiles) executes correctly
    203  <li> Its tick, when EXECUTEd or COMPILE,'d executes incorrectly
    204  <li> <a href=dpans6.htm#6.2.2530>[COMPILE]</a> does not work correctly with it.
    205 </ul>
    206 
    207 
    208 And, coincidentally, execution of its tick is abysmally slow
    209 (which would take more information flow to resolve, but which
    210 is not required since it only affects performance as opposed
    211 to correct execution.)
    212 
    213 <p> If the word was made state smart to distinguish between interpret
    214 and compile states, so that it counted #DUPS and did the <a href=dpans6.htm#6.1.2033>POSTPONE</a> when
    215 in compilation state and simply executed <a href=dpans6.htm#6.1.1290>DUP</a> when interpreting, then
    216 the situation changes but is still not correct:
    217 
    218 <ul>
    219  <li> It compiles correctly
    220  <li> It interprets correctly
    221  <li> (what it compiles) executes correctly
    222  <li> Its tick, when EXECUTEd is correct if in interpret state
    223      at the time <a href=dpans6.htm#6.1.1370>EXECUTE</a> is invoked, but is incorrect if in compile
    224      state at the time
    225  <li> A definition into which its tick is  COMPILE,'d  runs
    226      correctly if the definition runs in interpret state but fails
    227      if it is run in compile state
    228  <li> <a href=dpans6.htm#6.2.2530>[COMPILE]</a> does not work correctly with it.
    229 </ul>
    230 
    231 And execution of the tick, even when correct, is still slow.
    232 
    233 <p>
    234 There is, at minimum, a bidirectional flow of information between
    235 the compiler / interpreter and the definition of  <a href=dpans6.htm#6.1.1290>DUP</a>  that must
    236 occur around ticking and <a href=dpans6.htm#6.2.2530>[COMPILE]</a> ; in its absence, the compiler
    237 does not have any way of asking the definition for an *execution*
    238 token, and the definition does not have any way to provide one;
    239 and, in the case of <a href=dpans6.htm#6.2.2530>[COMPILE]</a>, the compiler has no way of knowing
    240 that this definition is supposed to be treated as though it had
    241 default compilation semantics.
    242 
    243 <p>
    244 The TC did not attempt specifying this compiler interface because
    245 it affects only new capabilities which were almost universally
    246 impossible in earlier standards, and active experimentation is
    247 still underway with these new capabilities, including as it
    248 appears your own.  At some time in the future after more has
    249 been learned it may be appropriate to standardize such a message
    250 passing mechanism, however at present any *application* which
    251 adds compilation semantics like this will need to incorporate
    252 implementation dependent code... or it will yield noncompliant
    253 definitions, as illustrated above.
    254 
    255 <p> In the problem you have been discussing, you are the implementor
    256 so you certainly have the power to create and then employ the
    257 necessary interface.  However, it appears that you have overlooked
    258 this necessity, and that is probably why you have been having
    259 difficulty.
    260 
    261 <h3>Discussion of Immediacy, Transparency, and Compliance</h3>
    262 
    263 In FORTH-83 it was necessary to document the "I" (Immediate) attribute
    264 of every standard word (and for that matter every word in each
    265 application) because the application needed to be aware of this
    266 attribute in order to make correct selections between use of COMPILE
    267 and <a href=dpans6.htm#6.2.2530>[COMPILE]</a> , and in order to predict the consequences of using what
    268 are now called "execution tokens".  Since knowledge of immediate
    269 versus nonimmediate attribute for each existing word appeared in
    270 application programs in both explicit and implicit ways, it was not
    271 practical to change the "immediacy" of any word in the system, nor
    272 indeed in most applications.  The attribute of immediacy was the only
    273 tool for making or discussing the distinc- tion between compilation
    274 and execution behavior, and the need for program awareness of this
    275 attribute as well as its inelastic nature led to a number of well
    276 known inconsistencies.  In addition, it made compliance with FORTH-83
    277 impractically cumbersome for many advanced compilers, including the
    278 incremental optimizing sort.
    279 
    280 <p>
    281 ANS Forth addresses these problems by defining all words in terms
    282 of explicit compilation, interpretation, and execution semantics;
    283 by defining such words as  <a href=dpans6.htm#6.1.1710>IMMEDIATE</a>  and  <a href=dpans6.htm#6.2.2530>[COMPILE]</a> and the effects
    284 of <a href=dpans6.htm#6.1.1370>EXECUTE</a> with execution tokens as specific transformations and
    285 selections on these semantics; by introducing  <a href=dpans6.htm#6.1.2033>POSTPONE</a>  to solve
    286 a well known dilemma in selection of the appropriate semantics;
    287 and finally by deleting the "I" designations since it is no longer
    288 necessary for the application programmer to be aware of them as
    289 such.  Finally, having done these things, it is possible for a
    290 compiler to add any desired compilation semantics, including those
    291 useful for optimization purposes, to definitions without affecting
    292 the use of those definitions by applications.  <a href=dpans6.htm#6.1.1710>IMMEDIATE</a> remains
    293 available for application use, but its effects are specified in
    294 semantic terms that can coexist with arbitrary default compilation
    295 semantics.
    296 
    297 <p>
    298 In ANS Forth, the existence and nature of compilation semantics
    299 that are in effect messages to the compiler is concealed well
    300 from the programmer, and the application code is the same whether
    301 or not, for example,  <a href=dpans6.htm#6.1.1290>DUP</a>  is "immediate" (in the old terms) or
    302 "has special compilation semantics" (in ANS Forth terms).  The
    303 only significant caveat is that when a system supports  <a href=dpans6.htm#6.2.2530>[COMPILE]</a>
    304 it must be very careful to treat all definitions that the
    305 Standard says have "default" compilation semantics, but to
    306 which the system has given "special" compilation semantics
    307 for its own purposes, as though they had "default" compilation
    308 semantics when referenced by  <a href=dpans6.htm#6.2.2530>[COMPILE]</a>.
    309 
    310 <p>
    311 An implementation complies with the standard if all Forth words
    312 and classes of words defined by the Standard behave, in all cases,
    313 consistently with the semantics prescribed in the Standard.  The
    314 test for correctness is specifically limited to semantics, as
    315 opposed to nonsemantic considerations such as, for example,
    316 the size, speed, or binary representation of compiled programs.
    317 
    318 <p>
    319 Please refer to <a href=dpansd.htm#D.4>D.4</a>, <a href=dpansd.htm#D.5>D.5</a>, <a href=dpansd.htm#D.6.7>D.6.7</a>, and <a href=dpanse.htm#E.4.1>E.4.1</a> for further discussion
    320 of optimizing compilers and ANS Forth handling of "immediacy".
    321 
    322 <h2><a name="ballot">Letter Ballot</a></h2>
    323 
    324 <pre>
    325 X3 Subgroup Letter Ballot
    326 Authorized by X3 Procedures - Distributed by X3 Subgroup X3J14
    327 Project: X3J14, ANS Forth
    328 Doc#:  X3J14/LB018
    329 Reference Doc#s:  X3J14/Q0007R, X3.215.1994 ANS Forth
    330 Date:  February 19, 1996
    331 Title:  Response to Request for Interpretation Q0007, Clarifying the
    332 distinction between "immediacy" and "special compilation semantics"
    333 Ballot Period:  30 Days
    334 Ballot Closes NOON DATE:  March 21, 1996
    335 Respond to:  greg@minerva.com
    336         or:  Elizabeth D. Rather, Chair
    337              FORTH, Inc.
    338              111 N. Sepulveda Blvd.  Suite 300
    339              Manhattan Beach, CA  90266
    340              (310) 372-8493    FAX (310) 318-7130
    341              erather@forth.com
    342 
    343 Statement:
    344     Document X3J14/Q0007R contains a proposed Response to Request for
    345     Interpretation Q0007.
    346 
    347 Question:
    348     Do you agree that this response represents the intended interpretation of
    349     X3.215.1994 ANS Forth?
    350 
    351 
    352 /------------------------  begin response area----------------------\
    353 |
    354 |  YES____ NO____ ABSTAIN____
    355 |
    356 |  Signature:  [not required for email ballots]
    357 |  Name:
    358 |  Organization:
    359 |
    360 |  Explanation (REQUIRED for NO or ABSTAIN votes):
    361 |    <none>
    362 \------------------------  end response area  ----------------------/
    363 
    364 INSTRUCTIONS:
    365 Please return the entire letter ballot with your response _either_ by email
    366 to greg@minerva.com _or_ by regular mail or fax or email to me at the above
    367 address, before the closing date & time.
    368 
    369    If replying electronically PLEASE edit only within the response area
    370    indicated above, inserting any explanatory text in place of <none>.
    371    Any changes made outside that area will likely be overlooked.
    372 
    373 All TC members must vote.  Failure to vote in two consecutive ballots may
    374 cause you to lose your voting rights in X3J14.
    375 
    376 Thank you for your participation.
    377 
    378 Elizabeth D. Rather, Chair, X3J14
    379 </pre>
    380 
    381 <h2><a name="results">Results of Letter Ballot</a></h2>
    382 
    383 <pre>
    384 Letter ballot 18 closed at noon March 21 with the following results:
    385 
    386         Y  N  A NV
    387 LB18:  12, 0, 1, 1
    388 
    389 Abstention from John Hayes.
    390 </pre>