assert.fs (lib) ☞
assert.fs library contains words to add assertions to your code.
Simply write assertions in your code like this:
require assert.fs 1 assert-level! \ this is the default : main assert( depth 0= ) \ other code goes here... assert( 1 2 + 3 = ) ;
The code after the word
assert( should push a flag to the parameter stack that
indicates whether the assertion succeeded. The word
) consumes this flag and
displays an error on
Make sure to not modify the stack in any other way between the
assert-level is set to
1, which means that assertions defined
assert1( are enabled. Other assertions (at level 2 and 3)
will be skipped at compile-time and are not included in your final ROM.
The assert level can be set by calling
assert-level! at toplevel. This value
can not be modified at run-time.
assert-level! ( u – )
Set the assertion level. Valid levels are
3 (default is
Toplevel only, can not be used at run-time.
assert( ( – )
assert1(, the default assert.
assert0( ( – )
For important assertions that are always enabled.
assert1( ( – )
For regular assertions that are enabled by default.
assert2( ( – )
For debugging assertions that can be enabled manually.
assert3( ( – )
For extra slow assertions that can be enabled for thorough debugging.
) ( f – )
Ends the assertion. This word is doing the actual checking at run-time.