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