File:  [gforth] / gforth / kernel / tools.fs
Revision 1.27: download - view: text, annotated - select for diffs
Mon Dec 31 18:40:26 2007 UTC (14 years, 11 months ago) by anton
Branches: MAIN
CVS tags: v0-7-0, HEAD
updated copyright notices for GPL v3

    1: \ TOOLS.FS     Toolkit extentions                      2may93jaw
    2: 
    3: \ Copyright (C) 1995,1998,1999,2001,2003,2006,2007 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: \ May be cross-compiled
   21: 
   22: require ./io.fs		\ type ...
   23: require ./nio.fs	\ . <# ...
   24: require ./int.fs	\ wordlist-id ..
   25: 
   26: hex
   27: 
   28: \ .S            CORE / CORE EXT                         9may93jaw
   29: 
   30: variable maxdepth-.s ( -- addr ) \ gforth maxdepth-dot-s
   31: \G A variable containing 9 by default.  @code{.s} and @code{f.s}
   32: \G display at most that many stack items.
   33: 9 maxdepth-.s !
   34: 
   35: : .s ( -- ) \ tools dot-s
   36: \G Display the number of items on the data stack, followed by a list
   37: \G of the items (but not more than specified by @code{maxdepth-.s};
   38: \G TOS is the right-most item.
   39:     ." <" depth 0 .r ." > "
   40:     depth 0 max maxdepth-.s @ min
   41:     dup 0
   42:     ?do
   43: 	dup i - pick .
   44:     loop
   45:     drop ;
   46: 
   47: \ DUMP                       2may93jaw - 9may93jaw    06jul93py
   48: \ looks very nice, I know
   49: 
   50: Variable /dump
   51: 
   52: : .4 ( addr -- addr' )
   53:     3 FOR  -1 /dump +!  /dump @ 0<
   54:         IF  ."    "  ELSE  dup c@ 0 <<# # # #> type #>> space  THEN
   55:     char+ NEXT ;
   56: : .chars ( addr -- )
   57:     /dump @ bounds
   58:     ?DO I c@ dup 7f bl within
   59: 	IF  drop [char] .  THEN  emit
   60:     LOOP ;
   61: 
   62: : .line ( addr -- )
   63:   dup .4 space .4 ." - " .4 space .4 drop  10 /dump +!  space .chars ;
   64: 
   65: : dump  ( addr u -- ) \ tools dump
   66:     \G Display @var{u} lines of memory starting at address @var{addr}. Each line
   67:     \G displays the contents of 16 bytes. When Gforth is running under
   68:     \G an operating system you may get @file{Invalid memory address} errors
   69:     \G if you attempt to access arbitrary locations.
   70:     cr base @ >r hex        \ save base on return stack
   71:     0 ?DO  I' I - 10 min /dump !
   72: 	dup 8 u.r ." : " dup .line cr  10 +
   73: 	10 +LOOP
   74:     drop r> base ! ;
   75: 
   76: \ ?                                                     17may93jaw
   77: 
   78: : ? ( a-addr -- ) \ tools question
   79:     \G Display the contents of address @var{a-addr} in the current number base.
   80:     @ . ;
   81: 
   82: \ words visible in roots                               14may93py
   83: 
   84: include  ./../termsize.fs
   85: 
   86: : wordlist-words ( wid -- ) \ gforth
   87:     \G Display the contents of the wordlist wid.
   88:     [ has? ec 0= [IF] ] wordlist-id [ [THEN] ]
   89:     0 swap cr
   90:     BEGIN
   91: 	@ dup
   92:     WHILE
   93: 	2dup name>string nip 2 + dup >r +
   94: 	cols >=
   95: 	IF
   96: 	    cr nip 0 swap
   97: 	THEN
   98: 	dup name>string type space r> rot + swap
   99:     REPEAT
  100:     2drop ;
  101: 
  102: : words
  103:     \G ** this will not get annotated. See other defn in search.fs .. **
  104:     \G It does not work to use "wordset-" prefix since this file is glossed
  105:     \G by cross.fs which doesn't have the same functionalty as makedoc.fs
  106:     [ has? ec 0= [IF] ] context @ [ [ELSE] ] forth-wordlist [ [THEN] ]
  107:     wordlist-words ;
  108: 
  109: ' words alias vlist ( -- ) \ gforth
  110: \g Old (pre-Forth-83) name for @code{WORDS}.

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