File: depth-changes.fs

package info (click to toggle)
gforth 0.7.0%2Bds2-0.1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 5,808 kB
  • sloc: ansic: 8,506; sh: 3,660; lisp: 1,783; makefile: 993; yacc: 186; sed: 141; lex: 102; awk: 21
file content (69 lines) | stat: -rw-r--r-- 1,874 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
\ report stack depth changes in source code in various (optional) ways

\ Copyright (C) 2004,2007 Free Software Foundation, Inc.

\ This file is part of Gforth.

\ Gforth is free software; you can redistribute it and/or
\ modify it under the terms of the GNU General Public License
\ as published by the Free Software Foundation, either version 3
\ of the License, or (at your option) any later version.

\ This program is distributed in the hope that it will be useful,
\ but WITHOUT ANY WARRANTY; without even the implied warranty of
\ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
\ GNU General Public License for more details.

\ You should have received a copy of the GNU General Public License
\ along with this program. If not, see http://www.gnu.org/licenses/.


\ Use this program like this:
\ include it, then the program you want to check
\ e.g., start it with
\  gforth depth-changes.fs myprog.fs

\ By default this will report stack depth changes at every empty line
\ in interpret state.  You can vary this by using

\  gforth depth-changes.fs -e "' <word> IS depth-changes-filter" myprog.fs

\ with the following values for <word>:

\ <word>      meaning
\ all-lines   every line in interpret state
\ most-lines  every line in interpret state not ending with "\"

2variable last-depths

defer depth-changes-filter ( -- f )
\G true if the line should be checked for depth changes
    
: all-lines ( -- f )
    state @ 0= ;

: empty-lines ( -- f )
    source (parse-white) nip 0= all-lines and ;

: most-lines ( -- f )
    source dup if
	1- chars + c@ '\ <>
    else
	2drop true
    endif
    all-lines and ;

' empty-lines is depth-changes-filter

: check-line ( -- )
    depth-changes-filter if
	sp@ fp@ last-depths 2@
	2over last-depths 2!
	d<> if
	    ['] ~~ execute
	endif
    endif ;

sp@ fp@ last-depths 2!

' check-line is line-end-hook