Annotation of gforth/assert.fs, revision 1.5

1.1       anton       1: \ assertions
                      2: 
1.5     ! anton       3: \ Copyright (C) 1995 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., 675 Mass Ave, Cambridge, MA 02139, USA.
        !            20: 
        !            21: require source.fs
1.1       anton      22: 
1.4       anton      23: variable assert-level ( -- a-addr ) \ gforth
1.3       anton      24: \G all assertions above this level are turned off
1.1       anton      25: 1 assert-level !
                     26: 
1.4       anton      27: : assertn ( n -- ) \ gforth assert-n
1.2       anton      28:     \ this is internal (it is not immediate)
1.1       anton      29:     assert-level @ >
                     30:     if
                     31:        POSTPONE (
                     32:     then ;
                     33: 
1.4       anton      34: : assert0( ( -- ) \ gforth assert-zero
1.3       anton      35:     \G important assertions that should always be turned on
1.1       anton      36:     0 assertn ; immediate
1.4       anton      37: : assert1( ( -- ) \ gforth assert-one
1.3       anton      38:     \G normal assertions; turned on by default
1.1       anton      39:     1 assertn ; immediate
1.4       anton      40: : assert2( ( -- ) \ gforth assert-two
1.3       anton      41:     \G debugging assertions
1.1       anton      42:     2 assertn ; immediate
1.4       anton      43: : assert3( ( -- ) \ gforth assert-three
1.3       anton      44:     \G slow assertions that you may not want to turn on in normal debugging;
                     45:     \G you would turn them on mainly for thorough checking
1.1       anton      46:     3 assertn ; immediate
1.4       anton      47: : assert( ( -- ) \ gforth
1.3       anton      48:     \G equivalent to assert1(
1.1       anton      49:     POSTPONE assert1( ; immediate
                     50: 
1.4       anton      51: : (endassert) ( flag -- ) \ gforth-internal
1.5     ! anton      52:     \ inline argument sourcepos
1.1       anton      53:     if
1.5     ! anton      54:        r> sourcepos drop + >r EXIT
1.1       anton      55:     else
1.5     ! anton      56:        r> print-sourcepos ." : failed assertion"
1.1       anton      57:        true abort" assertion failed" \ !! or use a new throw code?
                     58:     then ;
                     59: 
1.4       anton      60: : ) ( -- ) \ gforth    close-paren
                     61:     \G end an assertion
1.5     ! anton      62:     POSTPONE (endassert) sourcepos, ; immediate

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