File:  [gforth] / gforth / environ.fs
Revision 1.36: download - view: text, annotated - select for diffs
Mon Dec 31 15:25:18 2012 UTC (6 years, 9 months ago) by anton
Branches: MAIN
CVS tags: HEAD
updated copyright year

    1: \ environmental queries
    2: 
    3: \ Copyright (C) 1995,1996,1997,1998,2000,2003,2007,2012 Free Software Foundation, Inc.
    4: 
    5: \ This file is part of Gforth.
    6: 
    7: \ Gforth is free software; you can redistribute it and/or
    8: \ modify it under the terms of the GNU General Public License
    9: \ as published by the Free Software Foundation, either version 3
   10: \ of the License, or (at your option) any later version.
   11: 
   12: \ This program is distributed in the hope that it will be useful,
   13: \ but WITHOUT ANY WARRANTY; without even the implied warranty of
   14: \ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   15: \ GNU General Public License for more details.
   16: 
   17: \ You should have received a copy of the GNU General Public License
   18: \ along with this program. If not, see http://www.gnu.org/licenses/.
   19: 
   20: [IFUNDEF] cell/ : cell/ 1 cells / ; [THEN]
   21: [IFUNDEF] float/ : float/ 1 floats / ; [THEN]
   22: 
   23: \ wordlist constant environment-wordlist
   24: 
   25: vocabulary environment ( -- ) \ gforth
   26: \ for win32forth compatibility
   27: 
   28: ' environment >body constant environment-wordlist ( -- wid ) \ gforth
   29:   \G @i{wid} identifies the word list that is searched by environmental
   30:   \G queries.
   31: 
   32: 
   33: : environment? ( c-addr u -- false / ... true ) \ core environment-query
   34:     \G @i{c-addr, u} specify a counted string. If the string is not
   35:     \G recognised, return a @code{false} flag. Otherwise return a
   36:     \G @code{true} flag and some (string-specific) information about
   37:     \G the queried string.
   38:     environment-wordlist search-wordlist if
   39: 	execute true
   40:     else
   41: 	false
   42:     endif ;
   43: 
   44: : e? name environment? 0= ABORT" environmental dependency not existing" ;
   45: 
   46: : $has? environment? 0= IF false THEN ;
   47: 
   48: : has? name $has? ;
   49: 
   50: environment-wordlist set-current
   51: get-order environment-wordlist swap 1+ set-order
   52: 
   53: \ assumes that chars, cells and doubles use an integral number of aus
   54: 
   55: \ this should be computed in C as CHAR_BITS/sizeof(char),
   56: \ but I don't know any machine with gcc where an au does not have 8 bits.
   57: 8 constant ADDRESS-UNIT-BITS ( -- n ) \ environment
   58: \G Size of one address unit, in bits.
   59: 
   60: 1 ADDRESS-UNIT-BITS chars lshift 1- constant MAX-CHAR ( -- u ) \ environment
   61: \G Maximum value of any character in the character set
   62: 
   63: MAX-CHAR constant /COUNTED-STRING ( -- n ) \ environment
   64: \G Maximum size of a counted string, in characters.
   65: 
   66: ADDRESS-UNIT-BITS cells 2* 2 + constant /HOLD ( -- n ) \ environment
   67: \G Size of the pictured numeric string output buffer, in characters.
   68: 
   69: &84 constant /PAD ( -- n ) \ environment
   70: \G Size of the scratch area pointed to by @code{PAD}, in characters.
   71: 
   72: true constant CORE ( -- f ) \ environment
   73: \G True if the complete core word set is present. Always true for Gforth.
   74: 
   75: true constant CORE-EXT ( -- f ) \ environment
   76: \G True if the complete core extension word set is present. Always true for Gforth.
   77: 
   78: 1 -3 mod 0< constant FLOORED ( -- f ) \ environment
   79: \G True if @code{/} etc. perform floored division
   80: 
   81: 1 ADDRESS-UNIT-BITS cells 1- lshift 1- constant MAX-N ( -- n ) \ environment
   82: \G Largest usable signed integer.
   83: 
   84: -1 constant MAX-U ( -- u ) \ environment
   85: \G Largest usable unsigned integer.
   86: 
   87: -1 MAX-N 2constant MAX-D ( -- d ) \ environment
   88: \G Largest usable signed double.
   89: 
   90: -1. 2constant MAX-UD ( -- ud ) \ environment
   91: \G Largest usable unsigned double.
   92: 
   93: version-string 2constant gforth ( -- c-addr u ) \ gforth-environment
   94: \G Counted string representing a version string for this version of
   95: \G Gforth (for versions>0.3.0).  The version strings of the various
   96: \G versions are guaranteed to be ordered lexicographically.
   97: 
   98: : return-stack-cells ( -- n ) \ environment
   99:     \G Maximum size of the return stack, in cells.
  100:     [ forthstart 6 cells + ] literal @ cell/ ;
  101: 
  102: : stack-cells ( -- n ) \ environment
  103:     \G Maximum size of the data stack, in cells.
  104:     [ forthstart 4 cells + ] literal @ cell/ ;
  105: 
  106: : floating-stack ( -- n ) \ environment
  107:     \G @var{n} is non-zero, showing that Gforth maintains a separate
  108:     \G floating-point stack of depth @var{n}.
  109:     [ forthstart 5 cells + ] literal @
  110:     [IFDEF] float/  float/  [ELSE]  [ 1 floats ] Literal / [THEN] ;
  111: 
  112: 15 constant #locals \ 1000 64 /
  113:     \ One local can take up to 64 bytes, the size of locals-buffer is 1000
  114: maxvp constant wordlists
  115: 
  116: forth definitions
  117: previous
  118: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>