\ assert 05.1.22 NAB

module assert
public:

variable assert-level
1 assert-level !

private:

: assert-error ( x -- )
  abort" Assertion failure!" ;

: assertion(
\ ( n "...<)>" -- )
  assert-level @ 1+ < if
    [char] ) parse
    evaluate
    state @ if
      postpone 0=
      postpone assert-error
    else  0= assert-error
    then 
   else  postpone (  then
; immediate

public:

: assert0(
  0 postpone assertion( ; immediate

: assert1(
  1 postpone assertion( ; immediate

: assert2(
  2 postpone assertion( ; immediate

: assert3(
  3 postpone assertion( ; immediate

: assert(
  postpone assert1( ; immediate

end-module
