umouse

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

DPANSD.HTM (39253B)


      1 <HTML><HEAD>
      2 <TITLE>DPANS94</TITLE>
      3 <link disabled rel="stylesheet" href="mpexc6.css">
      4 <style>@import url(mpexc6.css);</style>
      5 </head>
      6 
      7 <BODY>
      8 <table width=100%>
      9 <tr>
     10 <td align=left>
     11 <a href=dpansc.htm><img src=left.gif
     12  width=26 height=26 align=ALIGN border=0></a>
     13 <a href=dpanse.htm><img src=right.gif
     14  width=26 height=26 align=ALIGN border=0></a>
     15 </td>
     16 <td align=right>
     17 <a href=dpans.htm#toc><img src=up.gif 
     18  width=26 height=26 align=ALIGN border=0></a>
     19 <a name=D.>Table of Contents</a>
     20 </td>
     21 </tr>
     22 </table>
     23 <p>
     24 <hr size=4>
     25 
     26 <H1>D. Compatibility analysis of ANS Forth (informative annex)</H1>
     27 
     28 Prior to ANS Forth, there were several industry standards for Forth.
     29 The most influential are listed here in chronological order, along with
     30 the major differences between ANS Forth and the most recent, Forth-83.
     31 
     32 <P>
     33 
     34 
     35 <hr>
     36 <A name=D.1>
     37 <H2>D.1 FIG Forth (circa 1978)</H2>
     38 </a>
     39 
     40 FIG Forth was a <B>model</B> implementation of the Forth language
     41 developed by the Forth Interest Group (FIG).  In FIG Forth, a relatively
     42 small number of words were implemented in processor-dependent machine
     43 language and the rest of the words were implemented in Forth.  The FIG
     44 model was placed in the public domain, and was ported to a wide variety
     45 of computer systems.  Because the bulk of the FIG Forth implementation
     46 was the same across all machines, programs written in FIG Forth enjoyed
     47 a substantial degree of portability, even for <B>system-level</B>
     48 programs that directly manipulate the internals of the Forth system
     49 implementation.
     50 
     51 <P>
     52 
     53 FIG Forth implementations were influential in increasing the number of
     54 people interested in using Forth.  Many people associate the
     55 implementation techniques embodied in the FIG Forth model with <B>the
     56 nature of Forth</B>.
     57 
     58 <P>
     59 
     60 However, FIG Forth was not necessarily representative of commercial
     61 Forth implementations of the same era.  Some of the most successful
     62 commercial Forth systems used implementation techniques different from
     63 the FIG Forth <B>model</B>.
     64 
     65 <P>
     66 
     67 
     68 <hr>
     69 <A name=D.2>
     70 <H2>D.2 Forth-79</H2>
     71 </a>
     72 
     73 The Forth-79 Standard resulted from a series of meetings from 1978 to
     74 1980, by the Forth Standards Team, an international group of Forth users
     75 and vendors (interim versions known as Forth 77 and Forth 78 were also
     76 released by the group).
     77 
     78 <P>
     79 
     80 Forth-79 described a set of words defined on a 16-bit, twos-complement,
     81 unaligned, linear byte-addressing virtual machine.  It prescribed an
     82 implementation technique known as <B>indirect threaded code</B>, and
     83 used the ASCII character set.
     84 
     85 <P>
     86 
     87 The Forth-79 Standard served as the basis for several public domain and
     88 commercial implementations, some of which are still available and
     89 supported today.
     90 
     91 <P>
     92 
     93 <hr>
     94 <A name=D.3>
     95 <H2>D.3 Forth-83</H2>
     96 </a>
     97 
     98 The Forth-83 Standard, also by the Forth Standards Team, was released in
     99 1983.  Forth-83 attempted to fix some of the deficiencies of Forth-79.
    100 
    101 <P>
    102 
    103 Forth-83 was similar to Forth-79 in most respects.  However, Forth-83
    104 changed the definition of several well-defined features of Forth-79.
    105 For example, the rounding behavior of integer division, the base value
    106 of the operands of 
    107 <a href=dpans6.htm#6.2.2030>PICK</a> 
    108 and 
    109 <a href=dpans6.htm#6.2.2150>ROLL</a>, 
    110 the meaning of the address returned by
    111 <a href=dpans6.htm#6.1.0070>'</a>, 
    112 the compilation behavior of ', the value of a <B>true</B> flag, the
    113 meaning of 
    114 NOT, 
    115 and the <B>chaining</B> behavior of words defined by
    116 VOCABULARY were all changed.  Forth-83 relaxed the implementation
    117 restrictions of Forth-79 to allow any kind of threaded code, but it did
    118 not fully allow compilation to native machine code (this was not
    119 specifically prohibited, but rather was an indirect consequence of
    120 another provision).
    121 
    122 <P>
    123 
    124 Many new Forth implementations were based on the Forth-83 Standard, but
    125 few <B>strictly compliant</B> Forth-83 implementations exist.
    126 
    127 <P>
    128 
    129 Although the incompatibilities resulting from the changes between
    130 Forth-79 and Forth-83 were usually relatively easy to fix, a number of
    131 successful Forth vendors did not convert their implementations to be
    132 Forth-83 compliant.  For example, the most successful commercial Forth
    133 for Apple Macintosh computers is based on Forth-79.
    134 
    135 <P>
    136 
    137 <hr>
    138 <A name=D.4>
    139 <H2>D.4 Recent developments</H2>
    140 </a>
    141 
    142 Since the Forth-83 Standard was published, the computer industry has
    143 undergone rapid and profound changes.  The speed, memory capacity, and
    144 disk capacity of affordable personal computers have increased by factors
    145 of more than 100.  8-bit processors have given way to 16-bit processors,
    146 and now 32-bit processors are commonplace.
    147 
    148 <P>
    149 
    150 The operating systems and programming-language environments of small
    151 systems are much more powerful than they were in the early 80's.
    152 
    153 <P>
    154 
    155 The personal-computer marketplace has changed from a predominantly
    156 <B>hobbyist</B> market to a mature business and commercial market.
    157 
    158 <P>
    159 
    160 Improved technology for designing custom microprocessors has resulted in
    161 the design of numerous <B>Forth chips</B>, computers optimized for the
    162 execution of the Forth language.
    163 
    164 <P>
    165 
    166 The market for ROM-based embedded control computers has grown
    167 substantially.
    168 
    169 <P>
    170 
    171 In order to take full advantage of this evolving technology, and to
    172 better compete with other programming languages, many recent Forth
    173 implementations have ignored some of the <B>rules</B> of previous Forth
    174 standards.  In particular:
    175 
    176 <UL>
    177 <LI>32-bit Forth implementations are now common.
    178 <LI>Some Forth systems adopt the address-alignment restrictions of the
    179 hardware on which they run.
    180 <LI>Some Forth systems use native-code generation, microcode
    181 generation, and optimization techniques, rather than the traditional
    182 <B>threaded code</B>.
    183 <LI>Some Forth systems exploit segmented addressing architectures,
    184 placing portions of the Forth <B>dictionary</B> in different segments.
    185 <LI>More and more Forth systems now run in the environment of
    186 another <B>standard</B> operating system, using OS text files for source
    187 code, rather than the traditional Forth <B>blocks</B>.
    188 <LI>Some Forth systems allow external operating system software,
    189 windowing software, terminal concentrators, or communications channels
    190 to handle or preprocess user input, resulting in deviations from the
    191 input editing, character set availability, and screen management
    192 behavior prescribed by Forth-83.
    193 </UL>
    194 <P>
    195 
    196 Competitive pressure from other programming languages (predominantly
    197 <B>C</B>) and from other Forth vendors have led Forth vendors to
    198 optimizations that do not fit in well with the <B>virtual machine
    199 model</B> implied by existing Forth standards.
    200 
    201 <P>
    202 
    203 
    204 <hr>
    205 <A name=D.5>
    206 <H2>D.5 ANS Forth approach</H2>
    207 </a>
    208 
    209 The ANS Forth committee addressed the serious fragmentation of the Forth
    210 community caused by the differences between Forth-79 and Forth-83, and
    211 the divergence from either of these two industry standards caused by
    212 marketplace pressures.
    213 
    214 <P>
    215 
    216 Consequently, the committee has chosen to base its compatibility
    217 decisions not upon a strict comparison with the Forth-83 Standard, but
    218 instead upon consideration of the variety of existing implementations,
    219 especially those with substantial user bases and/or considerable success
    220 in the marketplace.
    221 
    222 <P>
    223 
    224 The committee feels that, if ANS Forth prescribes stringent requirements
    225 upon the virtual machine model, as did the previous standards, then many
    226 implementors will chose not to comply with ANS Forth.  The committee
    227 hopes that ANS Forth will serve to unify rather than to further divide
    228 the Forth community, and thus has chosen to encompass rather than
    229 invalidate popular implementation techniques.
    230 
    231 <P>
    232 
    233 Many of the changes from Forth-83 are justified by this rationale.  Most
    234 fall into the category that <B>an ANS Forth Standard Program may not
    235 assume x</B>, where <B>x</B> is an entitlement resulting from the
    236 virtual machine model prescribed by the Forth-83 Standard.  The
    237 committee feels that these restrictions are reasonable, especially
    238 considering that a substantial number of existing Forth implementations
    239 do not correctly implement the Forth-83 virtual model, thus the Forth-83
    240 entitlements exist <B>in theory</B> but not <B>in practice</B>.
    241 
    242 <P>
    243 
    244 Another way of looking at this is that while ANS Forth acknowledges the
    245 diversity of current Forth practice, it attempts to document the
    246 similarity therein.  In some sense, ANS Forth is thus a <B>description
    247 of reality</B> rather than a <B>prescription for a particular virtual
    248 machine</B>.
    249 
    250 <P>
    251 
    252 Since there is no previous American National Standard for Forth, the
    253 action requirements prescribed by section 3.4 of X3/SD-9, <B>Policy and
    254 Guidelines</B>, regarding previous standards do not apply.
    255 
    256 <P>
    257 
    258 The following discussion describes differences between ANS Forth and
    259 Forth-83.  In most cases, Forth-83 is representative of Forth-79 and FIG
    260 Forth for the purposes of this discussion.  In many of these cases,
    261 however, ANS Forth is more representative of the existing state of the
    262 Forth industry than the previously-published standards.
    263 
    264 <P>
    265 
    266 <hr>
    267 <A name=D.6>
    268 <H2>D.6 Differences from Forth-83</H2>
    269 </a>
    270 
    271 
    272 
    273 <hr>
    274 <A name=D.6.1>
    275 <H3>D.6.1 Stack width</H3>
    276 </a>
    277 
    278 Forth-83 specifies that stack items occupy 16 bits.  This includes
    279 addresses, flags, and numbers.  ANS Forth specifies that stack items are
    280 at least 16 bits; the actual size must be documented by the
    281 implementation.
    282 
    283 <P>
    284 
    285 Words affected:                 all arithmetic, logical and addressing
    286 operators
    287 
    288 <P>
    289 
    290 Reason:                                 32-bit machines are becoming
    291 commonplace.  A 16-bit Forth system on a 32-bit machine is not competitive.
    292 
    293 <P>
    294 
    295 Impact:                                 Programs that assume 16-bit stack
    296 width will continue to run on 16-bit machines; ANS Forth does not require a
    297 different stack width, but simply allows it.  Many programs will be unaffected
    298 (but see <B>address unit</B>).
    299 
    300 <P>
    301 
    302 Transition/Conversion:  Programs which use bit masks with the high bits set
    303 may have to be changed, substituting either an implementation-defined bit-mask
    304 constant, or a procedure to calculate a bit mask in a stack-width-independent
    305 way.  Here are some procedures for constructing width-independent bit masks:
    306 
    307 <P>
    308 
    309 
    310 <PRE>
    311 1  CONSTANT LO-BIT
    312 TRUE 1 RSHIFT  INVERT  CONSTANT HI-BIT
    313 
    314 : LO-BITS  ( n -- mask )
    315     0 SWAP  0 ?DO  1 LSHIFT  LO-BIT OR  LOOP ;
    316 
    317 : HI-BITS  ( n -- mask )
    318     0 SWAP  0 ?DO  1 RSHIFT  HI-BIT OR  LOOP ;
    319 </PRE>
    320 
    321 <P>
    322 
    323 Programs that depend upon the <B>modulo 65536</B> behavior implicit in
    324 16-bit arithmetic operations will need to be rewritten to explicitly
    325 perform the modulus operation in the appropriate places.  The committee
    326 believes that such assumptions occur infrequently.  Examples: some
    327 checksum or CRC calculations, some random number generators and most
    328 fixed-point fractional math.
    329 
    330 <P>
    331 
    332 
    333 <hr>
    334 <A name=D.6.2>
    335 <H3>D.6.2 Number representation</H3>
    336 </a>
    337 
    338 Forth-83 specifies two's-complement number representation and
    339 arithmetic.  ANS Forth also allows one's-complement and
    340 signed-magnitude.
    341 
    342 <P>
    343 
    344 Words affected: all arithmetic and logical operators, 
    345 <a href=dpans6.htm#6.1.1800>LOOP</a>, 
    346 <a href=dpans6.htm#6.1.0140>+LOOP</a>
    347 <P>
    348 
    349 
    350 Reason: Some computers use one's-complement or signed-magnitude.  The
    351 committee did not wish to force Forth implementations for those machines
    352 to emulate two's-complement arithmetic, and thus incur severe
    353 performance penalties.  The experience of some committee members with
    354 such machines indicates that the usage restrictions necessary to support
    355 their number representations are not overly burdensome.
    356 
    357 <P>
    358 
    359 Impact: An ANS Forth Standard Program may declare an <B>environmental
    360 dependency on two's-complement arithmetic</B>.  This means that the
    361 otherwise-Standard Program is only guaranteed to work on
    362 two's-complement machines.  Effectively, this is not a severe
    363 restriction, because the overwhelming majority of current computers use
    364 two's-complement.  The committee knows of no Forth-83 compliant
    365 implementations for non-two's-complement machines at present, so
    366 existing Forth-83 programs will still work on the same class of machines
    367 on which they currently work.
    368 
    369 <P>
    370 
    371 Transition/Conversion: Existing programs wishing to take advantage of
    372 the possibility of ANS Forth Standard Systems on non-two's-complement
    373 machines may do so by eliminating the use of arithmetic operators to
    374 perform logical functions, by deriving bit-mask constants from bit
    375 operations as described in the section about stack width, by restricting
    376 the usage range of unsigned numbers to the range of positive numbers,
    377 and by using the provided operators for conversion from single numbers
    378 to double numbers.
    379 
    380 <P>
    381 
    382 
    383 <hr>
    384 <A name=D.6.3>
    385 <H3>D.6.3 Address units</H3>
    386 </a>
    387 
    388 Forth-83 specifies that each unique address refers to an 8-bit byte in
    389 memory.  ANS Forth specifies that the size of the item referred to by
    390 each unique address is implementation-defined, but, by default, is the
    391 size of one character.  Forth-83 describes many memory operations in
    392 terms of a number of bytes.  ANS Forth describes those operations in
    393 terms of a number of either characters or address units.
    394 
    395 <P>
    396 
    397 Words affected: those with <B>address unit</B> arguments
    398 <P>
    399 
    400 Reason: Some machines, including the most popular Forth chip, address
    401 16-bit memory locations instead of 8-bit bytes.
    402 
    403 <P>
    404 
    405 Impact: Programs may choose to declare an environmental dependency on
    406 byte addressing, and will continue to work on the class of machines for
    407 which they now work.  In order for a Forth implementation on a
    408 word-addressed machine to be Forth-83 compliant, it would have to
    409 simulate byte addressing at considerable cost in speed and memory
    410 efficiency.  The committee knows of no such Forth-83 implementations for
    411 such machines, thus an environmental dependency on byte addressing does
    412 not restrict a Standard Program beyond its current de facto
    413 restrictions.
    414 
    415 <P>
    416 
    417 Transition/Conversion: The new 
    418 <a href=dpans6.htm#6.1.0898>CHARS</a> 
    419 and 
    420 <a href=dpans6.htm#6.1.0897>CHAR+</a> 
    421 address arithmetic
    422 operators should be used for programs that require portability to
    423 non-byte-addressed machines.  The places where such conversion is
    424 necessary may be identified by searching for occurrences of words that
    425 accept a number of address units as an argument (e.g., 
    426 <a href=dpans6.htm#6.1.1900>MOVE</a>, 
    427 <a href=dpans6.htm#6.1.0710>ALLOT</a>).
    428 
    429 <P>
    430 
    431 
    432 <hr>
    433 <A name=D.6.4>
    434 <H3>D.6.4 Address increment for a cell is no longer two</H3>
    435 </a>
    436 
    437 As a consequence of Forth-83's simultaneous specification of 16-bit
    438 stack width and byte addressing, the number two could reliably be used
    439 in address calculations involving memory arrays containing items from
    440 the stack.  Since ANS Forth requires neither 16-bit stack width nor byte
    441 addressing, the number two is no longer necessarily appropriate for such
    442 calculations.
    443 
    444 <P>
    445 
    446 Words
    447 affected: 
    448 <a href=dpans6.htm#6.1.0650>@</a> 
    449 <a href=dpans6.htm#6.1.0010>!</a> 
    450 <a href=dpans6.htm#6.1.0130>+!</a> 
    451 2+ 
    452 <a href=dpans6.htm#6.1.0320>2*</a> 
    453 2- 
    454 <a href=dpans6.htm#6.1.0140>+LOOP</a>
    455 
    456 <P>
    457 
    458 Reason: See reasons for <B>Address Units</B> and <B>Stack Width</B>
    459 <P>
    460 
    461 Impact: In this respect, existing programs will continue to work on
    462 machines where a stack cell occupies two address units when stored in
    463 memory.  This includes most machines for which Forth-83 compliant
    464 implementations currently exist.  In principle, it would also include
    465 16-bit-word-addressed machines with 32-bit stack width, but the
    466 committee knows of no examples of such machines.
    467 
    468 <P>
    469 
    470 Transition/Conversion: The new 
    471 <a href=dpans6.htm#6.1.0890>CELLS</a> 
    472 and 
    473 <a href=dpans6.htm#6.1.0880>CELL+</a> 
    474 address arithmetic
    475 operators should be used for portable programs.  The places where such
    476 conversion is necessary may be identified by searching for the character
    477 <B>2</B> and determining whether or not it is used as part of an address
    478 calculation.  The following substitutions are appropriate within address
    479 calculations:
    480 
    481 <P>
    482 
    483 
    484 <PRE>
    485 Old                     New
    486 ---                     ---
    487 2+  or  2 +             CELL+
    488 2*  or  2 *             CELLS
    489 2-  or  2 -             1 CELLS -
    490 2/  or  2 /             1 CELLS /
    491 2                       1 CELLS
    492 </PRE>
    493 
    494 <P>
    495 
    496 The number <B>2</B> by itself is sometimes used for address calculations
    497 as an argument to 
    498 +LOOP, 
    499 when the loop index is an address.  When
    500 converting the word 
    501 <a href=dpans6.htm#6.1.0330>2/</a> 
    502 which operates on negative dividends, one should
    503 be cognizant of the rounding method used.
    504 
    505 <P>
    506 
    507 
    508 <hr>
    509 <A name=D.6.5>
    510 <H3>D.6.5 Address alignment</H3>
    511 </a>
    512 
    513 Forth-83 imposes no restriction upon the alignment of addresses to any
    514 boundary.  ANS Forth specifies that a Standard System may require
    515 alignment of addresses for use with various <B>@</B> and <B>!</B>
    516 operators.
    517 
    518 <P>
    519 
    520 Words Affected: 
    521 <a href=dpans6.htm#6.1.0010>!</a> 
    522 <a href=dpans6.htm#6.1.0130>+!</a> 
    523 <a href=dpans6.htm#6.1.0310>2!</a> 
    524 <a href=dpans6.htm#6.1.0350>2@</a> 
    525 <a href=dpans6.htm#6.1.0650>@</a> 
    526 <a href=dpans15.htm#15.6.1.0600>?</a> 
    527 <a href=dpans6.htm#6.1.0150>,</a>
    528 <P>
    529 
    530 Reason: Many computers have hardware restrictions that favor the use of
    531 aligned addresses.  On some machines, the native memory-access
    532 instructions will cause an exception trap if used with an unaligned
    533 address.  Even on machines where unaligned accesses do not cause
    534 exception traps, aligned accesses are usually faster.
    535 
    536 <P>
    537 
    538 Impact: All of the ANS Forth words that return addresses suitable for
    539 use with aligned <B>@</B> and <B>!</B> words must return aligned
    540 addresses.  In most cases, there will be no problem.  Problems can arise
    541 from the use of user-defined data structures containing a mixture of
    542 character data and cell-sized data.
    543 
    544 <P>
    545 
    546 Many existing Forth systems, especially those currently in use on
    547 computers with strong alignment requirements, already require alignment.
    548 Much existing Forth code that is currently in use on such machines has
    549 already been converted for use in an aligned environment.
    550 
    551 <P>
    552 
    553 Transition/Conversion: There are two possible approaches to conversion
    554 of programs for use on a system requiring address alignment.
    555 
    556 <P>
    557 
    558 The easiest approach is to redefine the system's aligned <B>@</B> and
    559 <B>!</B> operators so that they do not require alignment.  For example,
    560 on a 16-bit little-endian byte-addressed machine, unaligned <B>@</B> and
    561 <B>!</B> could be defined:
    562 
    563 
    564 <PRE>
    565 	: @  ( addr -- x )  DUP C@ SWAP CHAR+ C@ 8 LSHIFT OR  ;
    566 	: !  ( x addr -- )  OVER 8 RSHIFT OVER CHAR+ C! C!  ;
    567 </PRE>
    568 <P>
    569 
    570 These definitions, and similar ones for <B>+!</B>, <B>2@</B>, <B>2!</B>,
    571 <B>,</B>, and <B>?</B> as needed, can be compiled before an unaligned
    572 application, which will then work as expected.
    573 
    574 <P>
    575 
    576 This approach may conserve memory if the application uses substantial
    577 numbers of data structures containing unaligned fields.
    578 
    579 <P>
    580 
    581 Another approach is to modify the application's source code to eliminate
    582 unaligned data fields.  The ANS Forth words 
    583 <a href=dpans6.htm#6.1.0705>ALIGN</a> 
    584 and 
    585 <a href=dpans6.htm#6.1.0706>ALIGNED</a> 
    586 may be
    587 used to force alignment of data fields.  The places where such alignment
    588 is needed may be determined by inspecting the parts of the application
    589 where data structures (other than simple variables) are defined, or by
    590 <B>smart compiler</B> techniques (see the <B>Smart Compiler</B>
    591 discussion below).
    592 
    593 <P>
    594 
    595 This approach will probably result in faster application execution
    596 speed, at the possible expense of increased memory utilization for data
    597 structures.
    598 
    599 <P>
    600 
    601 Finally, it is possible to combine the preceding techniques by
    602 identifying exactly those data fields that are unaligned, and using
    603 <B>unaligned</B> versions of the memory access operators for only those
    604 fields.  This <B>hybrid</B> approach affects a compromise between
    605 execution speed and memory utilization.
    606 
    607 <P>
    608 
    609 
    610 <hr>
    611 <a name=D.6.6>
    612 <H3>D.6.6 Division/modulus rounding direction</H3>
    613 </a>
    614 
    615 Forth-79 specifies that division rounds toward 0 and the remainder
    616 carries the sign of the dividend.  Forth-83 specifies that division
    617 rounds toward negative infinity and the remainder carries the sign of
    618 the divisor.  ANS Forth allows either behavior for the division
    619 operators listed below, at the discretion of the implementor, and
    620 provides a pair of division primitives to allow the user to synthesize
    621 either explicit behavior.
    622 
    623 <P>
    624 
    625 Words Affected: 
    626 <a href=dpans6.htm#6.1.0230>/</a> 
    627 <a href=dpans6.htm#6.1.1890>MOD</a> 
    628 <a href=dpans6.htm#6.1.0240>/MOD</a> 
    629 <a href=dpans6.htm#6.1.0110>*/MOD</a> 
    630 <a href=dpans6.htm#6.1.0100>*/</a>
    631 <P>
    632 
    633 Reason: The difference between the division behaviors in Forth-79 and
    634 Forth-83 was a point of much contention, and many Forth implementations
    635 did not switch to the Forth-83 behavior.  Both variants have vocal
    636 proponents, citing both application requirements and execution
    637 efficiency arguments on both sides.  After extensive debate spanning
    638 many meetings, the committee was unable to reach a consensus for
    639 choosing one behavior over the other, and chose to allow either behavior
    640 as the default, while providing a means for the user to explicitly use
    641 both behaviors as needed.  Since implementors are allowed to choose
    642 either behavior, they are not required to change the behavior exhibited
    643 by their current systems, thus preserving correct functioning of
    644 existing programs that run on those systems and depend on a particular
    645 behavior.  New implementations could choose to supply the behavior that
    646 is supported by the native CPU instruction set, thus maximizing
    647 execution speed, or could choose the behavior that is most appropriate
    648 for the intended application domain of the system.
    649 
    650 <P>
    651 
    652 Impact: The issue only affects programs that use a negative dividend
    653 with a positive divisor, or a positive dividend with a negative divisor.
    654 The vast majority of uses of division occur with both a positive
    655 dividend and a positive divisor; in that case, the results are the same
    656 for both allowed division behaviors.
    657 
    658 <P>
    659 
    660 Transition/Conversion: For programs that require a specific rounding
    661 behavior with division operands of mixed sign, the division operators
    662 used by the program may be redefined in terms of one of the new ANS
    663 Forth division primitives 
    664 <a href=dpans6.htm#6.1.2214>SM/REM</a> 
    665 (symmetrical division, i.e., round
    666 toward zero) or 
    667 <a href=dpans6.htm#6.1.1561>FM/MOD</a> 
    668 (floored division, i.e., round toward negative
    669 infinity).  Then the program may be recompiled without change.  For
    670 example, the Forth-83 style division operators may be defined by:
    671 
    672 <P>
    673 
    674 
    675 <PRE>
    676 : /MOD  ( n1 n2 -- n3 n4 )     >R S>D R> FM/MOD  ;
    677 : MOD   ( n1 n2 -- n3 )        /MOD DROP  ;
    678 : /     ( n1 n2 -- n3 )        /MOD SWAP DROP   ;
    679 : */MOD ( n1 n2 n3 -- n4 n5 )  >R M* R> FM/MOD  ;
    680 : */    ( n1 n2 n3 -- n4 n5 )  */MOD SWAP DROP  ;
    681 </PRE>
    682 
    683 <P>
    684 
    685 <hr>
    686 <A name=D.6.7>
    687 <H3>D.6.7 Immediacy</H3>
    688 </a>
    689 
    690 Forth-83 specified that a number of <B>compiling words</B> are
    691 <B>immediate</B>, meaning that they are executed instead of compiled
    692 during compilation.  ANS Forth is less specific about most of these
    693 words, stating that their behavior is only defined during compilation,
    694 and specifying their results rather than their specific compile-time
    695 actions.
    696 
    697 <P>
    698 
    699 To force the compilation of a word that would normally be executed,
    700 Forth-83 provided the words COMPILE , used with non-immediate words, and
    701 <a href=dpans6.htm#6.2.2530>[COMPILE]</a> , 
    702 used with immediate words.  ANS Forth provides the single
    703 word 
    704 <a href=dpans6.htm#6.1.2033>POSTPONE</a> , 
    705 which is used with both immediate and non-immediate
    706 words, automatically selecting the appropriate behavior.
    707 
    708 <P>
    709 
    710 Words Affected: 
    711 <b><code>COMPILE [COMPILE] 
    712 <a href=dpans6.htm#6.1.2510>[']</a> 
    713 <a href=dpans6.htm#6.1.0070>'</a></code></b>
    714 <P>
    715 
    716 Reason: The designation of particular words as either immediate or not
    717 depends upon the implementation technique chosen for the Forth system.
    718 With traditional <B>threaded code</B> implementations, the choice was
    719 generally quite clear (with the single exception of the word 
    720 <a href=dpans6.htm#6.1.1760>LEAVE</a>), and
    721 the standard could specify which words should be immediate.  However,
    722 some of the currently popular implementation techniques, such as
    723 native-code generation with optimization, require the immediacy
    724 attribute on a different set of words than the set of immediate words of
    725 a threaded code implementation.  ANS Forth, acknowledging the validity
    726 of these other implementation techniques, specifies the immediacy
    727 attribute in as few cases as possible.
    728 
    729 <P>
    730 
    731 When the membership of the set of immediate words is unclear, the
    732 decision about whether to use COMPILE or [COMPILE] becomes unclear.
    733 Consequently, ANS Forth provides a <B>general purpose</B> replacement
    734 word POSTPONE that serves the purpose of the vast majority of uses of
    735 both COMPILE and [COMPILE], without requiring that the user know whether
    736 or not the <B>postponed</B> word is immediate.
    737 
    738 <P>
    739 
    740 Similarly, the use of ' and ['] with compiling words is unclear if the
    741 precise compilation behavior of those words is not specified, so ANS
    742 Forth does not permit a Standard Program to use ' or ['] with compiling
    743 words.
    744 
    745 <P>
    746 
    747 The traditional (non-immediate) definition of the word COMPILE has an
    748 additional problem.  Its traditional definition assumes a threaded code
    749 implementation technique, and its behavior can only be properly
    750 described in that context.  In the context of ANS Forth, which permits
    751 other implementation techniques in addition to threaded code, it is very
    752 difficult, if not impossible, to describe the behavior of the
    753 traditional COMPILE.  Rather than changing its behavior, and thus
    754 breaking existing code, ANS Forth does not include the word COMPILE.
    755 This allows existing implementations to continue to supply the word
    756 COMPILE with its traditional behavior, if that is appropriate for the
    757 implementation.
    758 
    759 <P>
    760 
    761 Impact: [COMPILE] remains in ANS Forth, since its proper use does not
    762 depend on knowledge of whether or not a word is immediate (Use of
    763 [COMPILE] with a non-immediate word is and has always been a no-op).
    764 Whether or not you need to use [COMPILE] requires knowledge of whether
    765 or not its target word is immediate, but it is always safe to use
    766 [COMPILE].  [COMPILE] is no longer in the (required) core word set,
    767 having been moved to the Core Extensions word set, but the committee
    768 anticipates that most vendors will supply it anyway.
    769 
    770 <P>
    771 
    772 In nearly all cases, it is correct to replace both [COMPILE] and COMPILE
    773 with POSTPONE.  Uses of [COMPILE] and COMPILE that are not suitable for
    774 <B>mindless</B> replacement by POSTPONE are quite infrequent, and fall
    775 into the following two categories:
    776 
    777 <P>
    778 
    779 a)      Use of [COMPILE] with non-immediate words.  This is sometimes done
    780 with the words '-(tick, which was immediate in Forth-79 but not in Forth-83)
    781 and LEAVE (which was immediate in Forth-83 but not in Forth-79), in order to
    782 force the compilation of those words without regard to whether you are using a
    783 Forth-79 or Forth-83 system.
    784 
    785 <P>
    786 
    787 b)      Use of the phrase  COMPILE [COMPILE] &lt;immediate word&gt; to
    788 <B>doubly
    789 postpone</B> an immediate word.
    790 
    791 <P>
    792 
    793 Transition/Conversion:  Many ANS Forth implementations will continue to
    794 implement both [COMPILE] and COMPILE in forms compatible with existing usage.
    795 In those environments, no conversion is necessary.
    796 
    797 <P>
    798 
    799 For complete portability, uses of COMPILE and [COMPILE] should be
    800 changed to POSTPONE , except in the rare cases indicated above.  Uses of
    801 [COMPILE] with non-immediate words may be left as-is, and the program
    802 may declare a requirement for the word [COMPILE] from the Core
    803 Extensions word set, or the [COMPILE] before the non-immediate word may
    804 be simply deleted if the target word is known to be non-immediate.
    805 
    806 <P>
    807 
    808 Uses of the phrase COMPILE [COMPILE] &lt;immediate-word&gt; may be handled by
    809 introducing an <B>intermediate word</B> (XX in the example below) and
    810 then postponing that word.  For example:
    811 
    812 
    813 <PRE>
    814 
    815 	: ABC  COMPILE [COMPILE] IF  ;
    816 
    817 </PRE>
    818 <P>
    819 
    820 changes to:
    821 <P>
    822 
    823 
    824 <PRE>
    825 	: XX  POSTPONE IF  ;
    826 	: ABC  POSTPONE XX  ;
    827 </PRE>
    828 <P>
    829 
    830 A non-standard case can occur with programs that <B>switch out of
    831 compilation state</B> to explicitly compile a thread in the dictionary
    832 following a COMPILE .  For example:
    833 
    834 
    835 <PRE>
    836 	: XYZ  COMPILE  [ ' ABC , ]  ;
    837 </PRE>
    838 <P>
    839 
    840 This depends heavily on knowledge of exactly how COMPILE and the
    841 threaded-code implementation works.  Cases like this cannot be handled
    842 mechanically; they must be translated by understanding exactly what the
    843 code is doing, and rewriting that section according to ANS Forth
    844 restrictions.
    845 
    846 <P>
    847 
    848 Use the phrase POSTPONE [COMPILE]
    849 to replace [COMPILE] [COMPILE].
    850 
    851 <P>
    852 
    853 <hr>
    854 <A name=D.6.8>
    855 <H3>D.6.8 Input character set</H3>
    856 </a>
    857 
    858 Forth-83 specifies that the full 7-bit ASCII character set is available
    859 through 
    860 KEY.  
    861 ANS Forth restricts it to the graphic characters of the
    862 ASCII set, with codes from hex 20 to hex 7E inclusive.
    863 
    864 <P>
    865 
    866 Words Affected:                 
    867 <a href=dpans6.htm#6.1.1750>KEY</a>
    868 <P>
    869 
    870 Reason: Many system environments <B>consume</B> certain control
    871 characters for such purposes as input editing, job control, or flow
    872 control.  A Forth implementation cannot always control this system
    873 behavior.
    874 
    875 <P>
    876 
    877 Impact: Standard Programs which require the ability to receive
    878 particular control characters through KEY must declare an environmental
    879 dependency on the input character set.
    880 
    881 <P>
    882 
    883 Transition/Conversion: For maximum portability, programs should restrict
    884 their required input character set to only the graphic characters.
    885 Control characters may be handled if available, but complete program
    886 functionality should be accessible using only graphic characters.
    887 
    888 <P>
    889 
    890 As stated above, an environmental dependency on the input character set
    891 may be declared.  Even so, it is recommended that the program should
    892 avoid the requirement for particularly-troublesome control characters,
    893 such as control-S and control-Q (often used for flow control, sometimes
    894 by communication hardware whose presence may be difficult to detect),
    895 ASCII NUL (difficult to type on many keyboards), and the distinction
    896 between carriage return and line feed (some systems translate carriage
    897 returns into line feeds, or vice versa).
    898 
    899 <P>
    900 
    901 <hr>
    902 <A name=D.6.9>
    903 <H3>D.6.9 Shifting with UM/MOD</H3>
    904 </a>
    905 
    906 Given Forth-83's two's-complement nature, and its requirement for
    907 floored (round toward minus infinity) division, shifting is equivalent
    908 to division.  Also, two's-complement representation implies that
    909 unsigned division by a power of two is equivalent to logical
    910 right-shifting, so UM/MOD could be used to perform a logical
    911 right-shift.
    912 
    913 <P>
    914 
    915 Words Affected: 
    916 <a href=dpans6.htm#6.1.2370>UM/MOD</a>
    917 <P>
    918 
    919 Reason: The problem with UM/MOD is a result of allowing
    920 non-two's-complement number representations, as already described.
    921 
    922 <P>
    923 
    924 ANS Forth provides the words 
    925 <a href=dpans6.htm#6.1.1805>LSHIFT</a> and 
    926 <a href=dpans6.htm#6.1.2162>RSHIFT</a> 
    927 to perform logical
    928 shifts.  This is usually more efficient, and certainly more descriptive,
    929 than the use of UM/MOD for logical shifting.
    930 
    931 <P>
    932 
    933 Impact: Programs running on ANS Forth systems with two's-complement
    934 arithmetic (the majority of machines), will not experience any
    935 incompatibility with UM/MOD .  Existing Forth-83 Standard programs
    936 intended to run on non-two's-complement machines will not be able to use
    937 UM/MOD for shifting on a non-two's-complement ANS Forth system.  This
    938 should not affect a significant number of existing programs (perhaps
    939 none at all), since the committee knows of no existing Forth-83
    940 implementations on non-two's-complement machines.
    941 
    942 <P>
    943 
    944 Transition/Conversion: A program that requires UM/MOD to behave as a
    945 shift operation may declare an environmental dependency on
    946 two's-complement arithmetic.
    947 
    948 <P>
    949 
    950 A program that cannot declare an environmental dependency on
    951 two's-complement arithmetic may require editing to replace incompatible
    952 uses of UM/MOD with other operators defined within the application.
    953 
    954 <P>
    955 
    956 <hr>
    957 <A name=D.6.10>
    958 <H3>D.6.10 Vocabularies / wordlists</H3>
    959 </a>
    960 
    961 ANS Forth does not define the words VOCABULARY, CONTEXT, and CURRENT ,
    962 which were present in Forth-83.  Instead, ANS Forth defines a primitive
    963 word set for search order specification and control, including words
    964 which have not existed in any previous standard.
    965 
    966 <P>
    967 
    968 Forth-83's 
    969 <a href=dpans16.htm#16.6.2.0715>ALSO</a>/<a href=dpans16.htm#16.6.2.1965>ONLY</a> 
    970 experimental search order word set is
    971 specified for the most part as the extension portion of the ANS Forth
    972 Search Order word set.
    973 
    974 <P>
    975 
    976 Words Affected: 
    977 <b><code>VOCABULARY CONTEXT CURRENT</code></b>
    978 <P>
    979 
    980 Reason: Vocabularies are an area of much divergence among existing
    981 systems.  Considering major vendors' systems and previous standards,
    982 there are at least 5 different and mutually incompatible behaviors of
    983 words defined by VOCABULARY.  Forth-83 took a step in the direction of
    984 <B>run-time search-order specification</B> by declining to specify a
    985 specific relationship between the hierarchy of compiled vocabularies and
    986 the run-time search order.  Forth-83 also specified an experimental
    987 mechanism for run-time search-order specification, the ALSO/ONLY scheme.
    988 ALSO/ONLY was implemented in numerous systems, and has achieved some
    989 measure of popularity in the Forth community.
    990 
    991 <P>
    992 
    993 However, several vendors refuse to implement it, citing technical
    994 limitations.  In an effort to address those limitations and thus
    995 hopefully make ALSO/ONLY more palatable to its critics, the committee
    996 specified a simple <B>primitive word set</B> that not only fixes some of
    997 the objections to ALSO/ONLY, but also provides sufficient power to
    998 implement ALSO/ONLY and all of the other search-order word sets that are
    999 currently popular.
   1000 
   1001 <P>
   1002 
   1003 The Forth-83 ALSO/ONLY word set is provided as an optional extension to
   1004 the search-order word set.  This allows implementors that are so
   1005 inclined to provide this word set, with well-defined standard behavior,
   1006 but does not compel implementors to do so.  Some vendors have publicly
   1007 stated that they will not implement ALSO/ONLY, no matter what, and one
   1008 major vendor stated an unwillingness to implement ANS Forth at all if
   1009 ALSO/ONLY is mandated.  The committee feels that its actions are
   1010 prudent, specifying ALSO/ONLY to the extent possible without mandating
   1011 its inclusion in all systems, and also providing a primitive
   1012 search-order word set that vendors may be more likely to implement, and
   1013 which can be used to synthesize ALSO/ONLY.
   1014 
   1015 <P>
   1016 
   1017 Transition/Conversion: Since Forth-83 did not mandate precise semantics
   1018 for VOCABULARY, existing Forth-83 Standard programs cannot use it except
   1019 in a trivial way.  Programs can declare a dependency on the existence of
   1020 the Search Order word set, and can implement whatever semantics are
   1021 required using that word set's primitives.  Forth-83 programs that need
   1022 ALSO/ONLY can declare a dependency on the Search Order Extensions word
   1023 set, or can implement the extensions in terms of the Search Order word
   1024 set itself.
   1025 
   1026 <P>
   1027 
   1028 <hr>
   1029 <A name=D.6.11>
   1030 <H3>D.6.11 Multiprogramming impact</H3>
   1031 </a>
   1032 
   1033 Forth-83 marked words with <B>multiprogramming impact</B> by the letter
   1034 <B>M</B> in the first lines of their descriptions.  ANS Forth has
   1035 removed the <B>M</B> designation from the word descriptions, moving the
   1036 discussion of multiprogramming impact to this non-normative annex.
   1037 
   1038 <P>
   1039 
   1040 Words affected: none
   1041 <P>
   1042 
   1043 Reason: The meaning of <B>multiprogramming impact</B> is precise only in
   1044 the context of a specific model for multiprogramming.  Although many
   1045 Forth systems do provide multiprogramming capabilities using a
   1046 particular round-robin, cooperative, block-buffer sharing model, that
   1047 model is not universal.  Even assuming the classical model, the <B>M</B>
   1048 designations did not contain enough information to enable writing of
   1049 applications that interacted in a multiprogrammed system.
   1050 
   1051 <P>
   1052 
   1053 Practically speaking, the <B>M</B> designations in Forth-83 served to
   1054 document usage rules for block buffer addresses in multiprogrammed
   1055 systems.  These addresses often become meaningless after a task has
   1056 relinquished the CPU for any reason, most often for the purposes of
   1057 performing I/O, awaiting an event, or voluntarily sharing CPU resources
   1058 using the word PAUSE.  It was essential that portable applications
   1059 respect those usage rules to make it practical to run them on
   1060 multiprogrammed systems; failure to adhere to the rules could easily
   1061 compromise the integrity of other applications running on those systems
   1062 as well as the applications actually in error.  Thus, <B>M</B> appeared
   1063 on all words that by design gave up the CPU, with the understanding that
   1064 other words NEVER gave it up.
   1065 
   1066 <P>
   1067 
   1068 These usage rules have been explicitly documented in the Block word set
   1069 where they are relevant.  The <B>M</B> designations have been removed
   1070 entirely.
   1071 
   1072 <P>
   1073 
   1074 Impact: In practice, none.
   1075 <P>
   1076 
   1077 In the sense that any application that depends on multiprogramming must
   1078 consist of at least two tasks that share some resource(s) and
   1079 communicate between themselves, Forth-83 did not contain enough
   1080 information to enable writing of a standard program that DEPENDED on
   1081 multiprogramming.  This is also true of ANS Forth.
   1082 
   1083 <P>
   1084 
   1085 Non-multiprogrammed applications in Forth-83 were required to respect
   1086 usage rules for 
   1087 <a href=dpans7.htm#7.6.1.0800>BLOCK</a> 
   1088 so that they could be run properly on
   1089 multiprogrammed systems.  The same is true of ANS Forth.
   1090 
   1091 <P>
   1092 
   1093 The only difference is the documentation method used to define the BLOCK
   1094 usage rules.  The Technical Committee believes that the current method
   1095 is clearer than the concept of <B>multiprogramming impact</B>.
   1096 
   1097 <P>
   1098 
   1099 Transition/Conversion:
   1100 none needed.
   1101 
   1102 <P>
   1103 
   1104 <hr>
   1105 <A name=D.6.12>
   1106 <H3>D.6.12 Words not provided in executable form</H3>
   1107 </a>
   1108 
   1109 ANS Forth allows an implementation to supply some words in source code
   1110 or <B>load as needed</B> form, rather than requiring all supplied words
   1111 to be available with no additional programmer action.
   1112 
   1113 <P>
   1114 
   1115 Words affected: all
   1116 <P>
   1117 
   1118 Reason: Forth systems are often used in environments where memory space
   1119 is at a premium.  Every word included in the system in executable form
   1120 consumes memory space.  The committee believes that allowing standard
   1121 words to be provided in source form will increase the probability that
   1122 implementors will provide complete ANS Forth implementations even in
   1123 systems designed for use in constrained environments.
   1124 
   1125 <P>
   1126 
   1127 Impact: In order to use a Standard Program with a given ANS Forth
   1128 implementation, it may be necessary to precede the program with an
   1129 implementation-dependent <B>preface</B> to make <B>source form</B> words
   1130 executable.  This is similar to the methods that other computer
   1131 languages require for selecting the library routines needed by a
   1132 particular application.
   1133 
   1134 <P>
   1135 
   1136 In languages like C, the goal of eliminating unnecessary routines from
   1137 the memory image of an application is usually accomplished by providing
   1138 libraries of routines, using a <B>linker</B> program to incorporate only
   1139 the necessary routines into an executable application.  The method of
   1140 invoking and controlling the linker is outside the scope of the language
   1141 definition.
   1142 
   1143 <P>
   1144 
   1145 Transition/Conversion: Before compiling a program, the programmer may
   1146 need to perform some action to make the words required by that program
   1147 available for execution.
   1148 <P>
   1149 
   1150 <hr>
   1151 <A href=dpans.htm#toc><IMG   src="up.gif" ></A>    Table of Contents 
   1152 <BR>
   1153 <A href=dpanse.htm><IMG   src="right.gif" ></A>
   1154 Next Section
   1155 <P>
   1156 </BODY>
   1157 </HTML>