This is NO page from the dpans'94 document.
It is an experimental draft for public review, here at FORTH.SF.NET
RFC
2002

TOC


A.19 The optional Environment word set

The extensibility of the environment hints and the environment source files are used to enable implementations to ship system functionality as source files. The functionality is not present in the initial system.

There are usually options to put additional environment library sources under the environment library path prefix so they can be used later.

Some systems may also chose to detect usage of environment queries ending with the four chars "-EXT". The query string gets surrounded by the environment path prefix and a possibly a file suffix, and execute otherwise like REQUIRED.

Environment source files may register additional environment hints by creating words in the ENVIRONMENT-WORDLIST.


A.19.2 Additional terms

library path
Note that the use of the term path prefix and contained sources does not necessarily imply implementation as files inside of directories.


A.19.3 ENVIRONMENT? implementation

A common implementation of ENVIRONMENT? would look like
   : ENVIRONMENT?
      ENVIRONMENT-WORDLIST SEARCH-WORDLIST
      IF EXECUTE TRUE
      ELSE FALSE
      THEN
   ;
and including the REQUIRED-EXT option could follow a scheme not unlike
   : ENVIRONMENT?
      2DUP
      ENVIRONMENT-WORDLIST SEARCH-WORDLIST
      IF 2DROP EXECUTE TRUE EXIT THEN

      DUP 4 < IF 2R> 4DROP EXIT THEN
      2DUP 4- /STRING S" -EXT" COMPARE IF 2DROP EXIT THEN
      2DUP 2>R REQUIRED 2R>

      ENVIRONMENT-WORDLIST SEARCH-WORDLIST
      IF EXECUTE TRUE EXIT THEN
      FALSE
    ;


The initial environment hints could answer environment queries from table 3.5, possibly setup by a source like
GET-CURRENT ENVIRONMENT-WORDLIST SET-CURRENT
         MAXCOUNTED  CONSTANT /COUNTED-STRING
               0x50  CONSTANT /HOLD
          MAXSTRING  CONSTANT /PAD
                  8  CONSTANT ADDRESS-UNIT-BITS
               TRUE  CONSTANT CORE
               TRUE  CONSTANT CORE-EXT
        -10 7 / -2 = CONSTANT FLOORED
         0xFFFFFFFF  CONSTANT MAX-CHAR
0x7FFFFFFF.FFFFFFFF 2CONSTANT MAX-D
         0x7FFFFFFF  CONSTANT MAX-N
         0xFFFFFFFF  CONSTANT MAX-U
0xFFFFFFFF.FFFFFFFF 2CONSTANT MAX-UD
              0x100  CONSTANT RETURN-STACK-CELLS
              0x100  CONSTANT STACK-CELLS
               TRUE  CONSTANT DOUBLE
               TRUE  CONSTANT DOUBLE-EXT
               TRUE  CONSTANT EXCEPTION
               TRUE  CONSTANT EXCEPTION-EXT
               TRUE  CONSTANT FACILITY
              FALSE  CONSTANT FACILITY-EXT
              FALSE  CONSTANT MEMORY-ALLOC
              FALSE  CONSTANT MEMORY-ALLOC-EXT
               TRUE  CONSTANT FILE
               TRUE  CONSTANT FILE-EXT
               TRUE  CONSTANT TOOLS
               TRUE  CONSTANT TOOLS-EXT
               TRUE  CONSTANT SEARCH-ORDER
               TRUE  CONSTANT SEARCH-ORDER-EXT
              #VOCS  CONSTANT WORDLISTS
               TRUE  CONSTANT STRING
               TRUE  CONSTANT STRING-EXT
           #-LOCALS  CONSTANT #LOCALS
( previous ) SET-CURRENT

example:
a call of S" /HOLD" ENVIRONMENT?" will have a general stack effect of ( -- false | size true ) depending on the result of the SEARCH-WORDLIST. If a definition is not found, a FALSE flag is pushed on to the parameter stack, but if it finds the name in the ENVIRONMENT-WORDLIST then the call to SEARCH-WORDLIST returns its execution token. For the case of /HOLD it is a CONSTANT xt - calling the execution-token via EXECUTE will leave the value of the constant on the parameter stack, and the ENVIRONMENT? definition will add a TRUE flag on top.

A word calling ENVIRONMENT? is supposed to use an IF statement that consumes the true/false flag, and in the true case to handle the additional values returned through execution of the symbol found in the ENVIRONMENT-WORDLIST. When an implementation of this wordsets implements the extension of the ENVIRONEMENT word, the following two code fragmant are almost identical.

  : .HOLD S" /HOLD" ENVIRONMENT? IF . ELSE ." unknown" THEN ;
  \ and
  S" /HOLD" ENVIRONMENT? [IF] DROP
  : .HOLD [ ALSO ENVIRONMENT ] /HOLD [ PREVIOUS ] . ;
  [ELSE]
  : .HOLD ." unknown" ;
  [THEN]
The difference is that the latter is faster while the earlier will allow later compiling to add a definition of /HOLD to the ENVIRONMENT-WORDLIST to be found during execution of the word.
Table of Contents
Next Section