| 1 : |
anton
|
1.1
|
\ assertions |
| 2 : |
|
|
|
| 3 : |
anton
|
1.12
|
\ Copyright (C) 1995,1996,1997,1999,2002 Free Software Foundation, Inc. |
| 4 : |
anton
|
1.5
|
|
| 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 : |
anton
|
1.10
|
\ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. |
| 20 : |
anton
|
1.5
|
|
| 21 : |
|
|
require source.fs |
| 22 : |
anton
|
1.1
|
|
| 23 : |
anton
|
1.4
|
variable assert-level ( -- a-addr ) \ gforth |
| 24 : |
crook
|
1.8
|
\G All assertions above this level are turned off. |
| 25 : |
anton
|
1.1
|
1 assert-level ! |
| 26 : |
|
|
|
| 27 : |
anton
|
1.4
|
: assertn ( n -- ) \ gforth assert-n |
| 28 : |
anton
|
1.2
|
\ this is internal (it is not immediate) |
| 29 : |
anton
|
1.1
|
assert-level @ > |
| 30 : |
|
|
if |
| 31 : |
|
|
POSTPONE ( |
| 32 : |
|
|
then ; |
| 33 : |
|
|
|
| 34 : |
anton
|
1.4
|
: assert0( ( -- ) \ gforth assert-zero |
| 35 : |
crook
|
1.8
|
\G Important assertions that should always be turned on. |
| 36 : |
anton
|
1.1
|
0 assertn ; immediate |
| 37 : |
anton
|
1.4
|
: assert1( ( -- ) \ gforth assert-one |
| 38 : |
crook
|
1.8
|
\G Normal assertions; turned on by default. |
| 39 : |
anton
|
1.1
|
1 assertn ; immediate |
| 40 : |
anton
|
1.4
|
: assert2( ( -- ) \ gforth assert-two |
| 41 : |
crook
|
1.8
|
\G Debugging assertions. |
| 42 : |
anton
|
1.1
|
2 assertn ; immediate |
| 43 : |
anton
|
1.4
|
: assert3( ( -- ) \ gforth assert-three |
| 44 : |
crook
|
1.8
|
\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. |
| 46 : |
anton
|
1.1
|
3 assertn ; immediate |
| 47 : |
anton
|
1.4
|
: assert( ( -- ) \ gforth |
| 48 : |
crook
|
1.8
|
\G Equivalent to @code{assert1(} |
| 49 : |
anton
|
1.1
|
POSTPONE assert1( ; immediate |
| 50 : |
|
|
|
| 51 : |
anton
|
1.11
|
: (end-assert) ( flag nfile nline -- ) \ gforth-internal |
| 52 : |
|
|
rot if |
| 53 : |
|
|
2drop |
| 54 : |
anton
|
1.1
|
else |
| 55 : |
anton
|
1.11
|
.sourcepos ." : failed assertion" |
| 56 : |
anton
|
1.1
|
true abort" assertion failed" \ !! or use a new throw code? |
| 57 : |
|
|
then ; |
| 58 : |
|
|
|
| 59 : |
anton
|
1.4
|
: ) ( -- ) \ gforth close-paren |
| 60 : |
anton
|
1.11
|
\G End an assertion. |
| 61 : |
|
|
compile-sourcepos POSTPONE (end-assert) ; immediate |