File:  [gforth] / gforth / kernel / vars.fs
Revision 1.43: download - view: text, annotated - select for diffs
Fri May 26 21:18:45 2006 UTC (15 years, 4 months ago) by pazsan
Branches: MAIN
CVS tags: HEAD
Fixed problem with error stack leftovers

    1: \ VARS.FS      Kernal variables
    2: 
    3: \ Copyright (C) 1995,1996,1997,1998,2000,2003 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 2
   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, write to the Free Software
   19: \ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
   20: 
   21: hex \ everything now hex!                               11may93jaw
   22: 
   23: \ important constants                                  17dec92py
   24: 
   25: \ dpANS6 (sect 3.1.3.1) says 
   26: \ "a true flag ... [is] a single-cell value with all bits set"
   27: \ better definition: 0 0= constant true ( no dependence on 2's compl)
   28:  -1 Constant true ( -- f ) \ core-ext
   29: \G @code{Constant} -- @i{f} is a cell with all bits set.
   30: \ see starts looking for primitives after this word!
   31: 
   32:   0 Constant false ( -- f ) \ core-ext
   33: \G @code{Constant} -- @i{f} is a cell with all bits clear.
   34: 
   35: [IFUNDEF] cell 
   36: 1 cells Constant cell ( -- u ) \ gforth
   37: \G @code{Constant} -- @code{1 cells}
   38: [THEN]
   39: 
   40: has? floating [IF]
   41: 1 floats Constant float ( -- u ) \ gforth
   42: \G @code{Constant} -- the number of address units corresponding to a floating-point number.
   43: [THEN]
   44: 
   45: 20 Constant bl ( -- c-char ) \ core b-l
   46: \G @i{c-char} is the character value for a space.
   47: \ used by docon:, must be constant
   48: 
   49: has? EC [IF] 40 [ELSE] FF [THEN] Constant /line
   50: 
   51: has? file [IF]
   52: 40 Constant c/l
   53: 10 Constant l/s
   54: 400 Constant chars/block
   55: [THEN]
   56: 
   57: 20 8 2* cells + 2 + cell+ constant word-pno-size ( -- u )
   58: 
   59: has? EC 0= [IF]
   60: create holdbuf word-pno-size chars allot
   61: holdbuf word-pno-size chars + aconstant holdbuf-end
   62: avariable holdptr holdbuf-end holdptr a!
   63: avariable holdend holdbuf-end holdend a!
   64: [THEN]
   65: 
   66: 84 constant pad-minsize ( -- u )
   67: 
   68: $400 Value def#tib
   69: \G default size of terminal input buffer. Default size is 1K
   70: 
   71: \ that's enough so long
   72: 
   73: \ User variables                                       13feb93py
   74: 
   75: \ initialized by COLD
   76: 
   77: has? no-userspace 0= [IF]
   78: Create main-task  has? OS [IF] 100 [ELSE] 40 [THEN] cells dup allot
   79: 
   80: \ set user-pointer from cross-compiler right
   81: main-task 
   82: UNLOCK swap region user-region user-region setup-region LOCK
   83: 
   84: Variable udp ( -- a-addr ) \ gforth
   85: \G user area size
   86: 
   87: AUser next-task        main-task next-task !
   88: AUser prev-task        main-task prev-task !
   89: AUser save-task        0 save-task !
   90: [THEN]
   91: AUser sp0 ( -- a-addr ) \ gforth
   92: \G @code{User} variable -- initial value of the data stack pointer.
   93: \ sp0 is used by douser:, must be user
   94: \    ' sp0 Alias s0 ( -- a-addr ) \ gforth
   95: \G OBSOLETE alias of @code{sp0}
   96: 
   97: AUser rp0 ( -- a-addr ) \ gforth
   98: \G @code{User} variable -- initial value of the return stack pointer.
   99: \    ' rp0 Alias r0 ( -- a-addr ) \ gforth
  100: \G OBSOLETE alias of @code{rp0}
  101: 
  102: has? floating [IF]
  103: AUser fp0 ( -- a-addr ) \ gforth
  104: \G @code{User} variable -- initial value of the floating-point stack pointer.
  105: \ no f0, because this leads to unexpected results when using hex
  106: [THEN]
  107: 
  108: has? glocals [IF]
  109: AUser lp0 ( -- a-addr ) \ gforth
  110: \G @code{User} variable -- initial value of the locals stack pointer.
  111: \    ' lp0 Alias l0 ( -- a-addr ) \ gforth
  112: \G OBSOLETE alias of @code{lp0}
  113: [THEN]
  114: 
  115: AUser handler	\ pointer to last throw frame
  116: has? backtrace [IF]
  117: AUser backtrace-rp0 \ rp at last call of interpret
  118: [THEN]
  119: \ AUser output
  120: \ AUser input
  121: 
  122: AUser errorhandler
  123: 
  124: AUser "error            0 "error !
  125: 
  126: has? new-input [IF]
  127:     User current-input
  128: [ELSE]
  129:     [IFUNDEF] #tib		\ in ec-Version we may define this ourself
  130: 	User tibstack		\ saves >tib in execute
  131: 	User >tib		\ pointer to terminal input buffer
  132: 	User #tib ( -- a-addr ) \ core-ext number-t-i-b
  133: 	\G @code{User} variable -- @i{a-addr} is the address of a cell containing
  134: 	\G the number of characters in the terminal input buffer.
  135: 	\G OBSOLESCENT: @code{source} superceeds the function of this word.
  136: 	
  137: 	User >in ( -- a-addr ) \ core to-in
  138: 	\G @code{User} variable -- @i{a-addr} is the address of a cell containing the
  139: 	\G char offset from the start of the input buffer to the start of the
  140: 	\G parse area.
  141: 	0 >in ! \ char number currently processed in tib
  142:     [THEN]
  143: 
  144: has? file [IF]
  145:  User blk ( -- a-addr ) \ block b-l-k
  146:  \G @code{User} variable -- @i{a-addr} is the address of a cell containing zero
  147:  \G (in which case the input source is not a block and can be identified
  148:  \G by @code{source-id}) or the number of the block currently being
  149:  \G interpreted. A Standard program should not alter @code{blk} directly.
  150: 			0 blk !
  151: 
  152:  User loadfile          0 loadfile !
  153: 
  154:  2user loadfilename	0 0 loadfilename 2! \ addr u for sourcefilename
  155:      
  156:  User loadline          \ number of the currently interpreted
  157:                         \ (in TIB) line if the interpretation
  158:                         \ is in a textfile
  159:                         \ the first line is 1
  160: 
  161: 2User linestart         \ starting file postition of
  162:                         \ the current interpreted line (in TIB)
  163: [THEN]
  164: [THEN]
  165: 
  166:  2user includefilename  0 0 includefilename 2! \ innermost included file
  167: 
  168: 
  169: User base ( -- a-addr ) \ core
  170: \G @code{User} variable -- @i{a-addr} is the address of a cell that stores the
  171: \G number base used by default for number conversion during input and output.
  172:                        A base !
  173: User dpl ( -- a-addr ) \ gforth
  174: \G @code{User} variable -- @i{a-addr} is the address of a cell that stores the 		
  175: \G position of the decimal point in the most recent numeric conversion.
  176: \G Initialised to -1. After the conversion of a number containing no
  177: \G decimal point, @code{dpl} is -1. After the conversion of @code{2.} it holds
  178: \G 0. After the conversion of 234123.9 it contains 1, and so forth.
  179: -1 dpl !
  180: 
  181: User state ( -- a-addr ) \ core,tools-ext
  182: \G @code{User} variable -- @i{a-addr} is the address of a cell
  183: \G containing the compilation state flag. 0 => interpreting, -1 =>
  184: \G compiling.  A program shall not directly alter the value of
  185: \G @code{state}. The following Standard words alter the value in
  186: \G @code{state}: @code{:} (colon) @code{;} (semicolon) @code{abort}
  187: \G @code{quit} @code{:noname} @code{[} (left-bracket) @code{]}
  188: \G (right-bracket) @code{;code}. Don't use @code{state}! For an
  189: \G alternative see @ref{Interpretation and Compilation Semantics}.
  190: \ Recommended reading: @cite{@code{State}-smartness--Why it is evil
  191: \ and how to exorcise it},
  192: \ @url{http://www.complang.tuwien.ac.at/papers/ertl98.ps.gz}; short
  193: \ version: Don't use @code{state}!
  194: 0 state !
  195: 
  196: AUser normal-dp		\ the usual dictionary pointer
  197: AUser dpp		normal-dp dpp !
  198: 			\ the pointer to the current dictionary pointer
  199:                         \ ist reset to normal-dp on (doerror)
  200:                         \  (i.e. any throw caught by quit)
  201: AUser LastCFA
  202: AUser Last
  203: 
  204: has? flash [IF]
  205:     AUser flash-dp
  206:     : rom  flash-dp dpp ! ;
  207:     : ram  normal-dp dpp ! ;
  208: [THEN]
  209: 
  210: User max-name-length \ maximum length of all names defined yet
  211: 32 max-name-length !
  212:     
  213: \  has? peephole  [IF]
  214: \  0 value peeptable \ initialized in boot
  215: \  [THEN]
  216: 
  217: has? glocals [IF]
  218: User locals-size \ this is the current size of the locals stack
  219: 		 \ frame of the current word
  220: [THEN]
  221: 

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