File:  [gforth] / gforth / depth-changes.fs
Revision 1.1: download - view: text, annotated - select for diffs
Fri May 14 17:09:22 2004 UTC (19 years ago) by anton
Branches: MAIN
CVS tags: HEAD
added Athlon64 benchmark result
added depth-changes.fs and hook for that in kernel/input.fs
made ~~ work in interpret state
documented clearstacks

    1: \ report stack depth changes in source code in various (optional) ways
    2: 
    3: \ Copyright (C) 2004 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: 
   22: \ Use this program like this:
   23: \ include it, then the program you want to check
   24: \ e.g., start it with
   25: \  gforth depth-changes.fs myprog.fs
   26: 
   27: \ By default this will report stack depth changes at every empty line
   28: \ in interpret state.  You can vary this by using
   29: 
   30: \  gforth depth-changes.fs -e "' <word> IS depth-changes-filter" myprog.fs
   31: 
   32: \ with the following values for <word>:
   33: 
   34: \ <word>      meaning
   35: \ all-lines   every line in interpret state
   36: \ most-lines  every line in interpret state not ending with "\"
   37: 
   38: 2variable last-depths
   39: 
   40: defer depth-changes-filter ( -- f )
   41: \G true if the line should be checked for depth changes
   42:     
   43: : all-lines ( -- f )
   44:     state @ 0= ;
   45: 
   46: : empty-lines ( -- f )
   47:     source (parse-white) nip 0= all-lines and ;
   48: 
   49: : most-lines ( -- f )
   50:     source dup if
   51: 	1- chars + c@ '\ <>
   52:     else
   53: 	2drop true
   54:     endif
   55:     all-lines and ;
   56: 
   57: ' empty-lines is depth-changes-filter
   58: 
   59: : check-line ( -- )
   60:     depth-changes-filter if
   61: 	sp@ fp@ last-depths 2@
   62: 	2over last-depths 2!
   63: 	d<> if
   64: 	    ['] ~~ execute
   65: 	endif
   66:     endif ;
   67: 
   68: sp@ fp@ last-depths 2!
   69: 
   70: ' check-line is line-end-hook

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