Annotation of gforth/assert.fs, revision 1.18
1.1 anton 1: \ assertions
2:
1.17 anton 3: \ Copyright (C) 1995,1996,1997,1999,2002,2003,2007,2010 Free Software Foundation, Inc.
1.5 anton 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
1.14 anton 9: \ as published by the Free Software Foundation, either version 3
1.5 anton 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
1.14 anton 18: \ along with this program. If not, see http://www.gnu.org/licenses/.
1.5 anton 19:
20: require source.fs
1.1 anton 21:
1.4 anton 22: variable assert-level ( -- a-addr ) \ gforth
1.8 crook 23: \G All assertions above this level are turned off.
1.1 anton 24: 1 assert-level !
25:
1.18 ! pazsan 26: : (end-assert) ( flag nfile nline -- ) \ gforth-internal
! 27: rot if
! 28: 2drop
! 29: else
! 30: .sourcepos ." : failed assertion"
! 31: true abort" assertion failed" \ !! or use a new throw code?
! 32: then ;
! 33:
! 34: : assert) ( -- )
! 35: compile-sourcepos POSTPONE (end-assert) ;
! 36:
! 37: 6 Constant assert-canary
! 38:
1.4 anton 39: : assertn ( n -- ) \ gforth assert-n
1.2 anton 40: \ this is internal (it is not immediate)
1.1 anton 41: assert-level @ >
42: if
43: POSTPONE (
1.18 ! pazsan 44: else
! 45: ['] assert) assert-canary
1.1 anton 46: then ;
47:
1.18 ! pazsan 48: : ) ( -- ) \ gforth close-paren
! 49: \G End an assertion. Generic end, can be used for other similar purposes
! 50: assert-canary <> abort" unmatched assertion"
! 51: execute ; immediate
! 52:
1.4 anton 53: : assert0( ( -- ) \ gforth assert-zero
1.8 crook 54: \G Important assertions that should always be turned on.
1.16 anton 55: 0 assertn ; immediate compile-only
1.4 anton 56: : assert1( ( -- ) \ gforth assert-one
1.8 crook 57: \G Normal assertions; turned on by default.
1.16 anton 58: 1 assertn ; immediate compile-only
1.4 anton 59: : assert2( ( -- ) \ gforth assert-two
1.8 crook 60: \G Debugging assertions.
1.16 anton 61: 2 assertn ; immediate compile-only
1.4 anton 62: : assert3( ( -- ) \ gforth assert-three
1.8 crook 63: \G Slow assertions that you may not want to turn on in normal debugging;
64: \G you would turn them on mainly for thorough checking.
1.16 anton 65: 3 assertn ; immediate compile-only
1.4 anton 66: : assert( ( -- ) \ gforth
1.8 crook 67: \G Equivalent to @code{assert1(}
1.16 anton 68: POSTPONE assert1( ; immediate compile-only
1.1 anton 69:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>