From 88fe78acc63adaff2d25e81b369f1395290e0e18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Wed, 18 Oct 2023 13:59:39 +0200 Subject: Add "unreachable". --- doc/ref/general/util-exceptions.texi | 11 +++++++++++ module/hnh/util/exceptions.scm | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/doc/ref/general/util-exceptions.texi b/doc/ref/general/util-exceptions.texi index 34ba33f9..4c2b432d 100644 --- a/doc/ref/general/util-exceptions.texi +++ b/doc/ref/general/util-exceptions.texi @@ -38,3 +38,14 @@ signal SIGINT, which kills the program. @defun filter-stack pred? stack @c TODO document me @end defun + + +@defun unreachable procedure fmt args +Marks that a code path should be unreachable. Throws an exception +which should never be caught (an @code{(exit -1)} would also have +worked, but would make debugging harder). + +@var{procedure} is the procedure which reached an ``impossible'' +state, @var{fmt} a format string, and @var{args} arguments to that +format string. +@end defun diff --git a/module/hnh/util/exceptions.scm b/module/hnh/util/exceptions.scm index 1c3de8c7..9b6b25a8 100644 --- a/module/hnh/util/exceptions.scm +++ b/module/hnh/util/exceptions.scm @@ -11,6 +11,7 @@ warning fatal filter-stack + unreachable )) @@ -40,3 +41,7 @@ (concatenate (for i in (iota (stack-length stk)) (filter pred? (map binding-ref (frame-bindings (stack-ref stk i))))))) + + +(define (unreachable procedure fmt args) + (scm-error 'unreachable procedure fmt args #f)) -- cgit v1.2.3