From 45412f6aef55df4f83f54b2b5445f673bfeee691 Mon Sep 17 00:00:00 2001
From: Kaz Kylheku <kaz@kylheku.com>
Date: Fri, 6 Dec 2019 06:15:49 -0800
Subject: unwind: new function uw_warningf.

Convenience function for throwing warnings.

* unwind.c (uw_warningf): New function.

* unwind.h (uw_warningf): Declared.
---
 unwind.c | 22 ++++++++++++++++++++++
 unwind.h |  1 +
 2 files changed, 23 insertions(+)

diff --git a/unwind.c b/unwind.c
index 3495213d..93b09fe1 100644
--- a/unwind.c
+++ b/unwind.c
@@ -793,6 +793,28 @@ val uw_errorfv(val fmt, struct args *args)
   abort();
 }
 
+val uw_warningf(val fmt, ...)
+{
+  va_list vl;
+
+  val stream = make_string_output_stream();
+  va_start (vl, fmt);
+  (void) vformat(stream, fmt, vl);
+  va_end (vl);
+
+  uw_catch_begin (cons(continue_s, nil), exsym, exvals);
+
+  uw_throw(warning_s, get_string_from_stream(stream));
+
+  uw_catch(exsym, exvals) { (void) exsym; (void) exvals; }
+
+  uw_unwind;
+
+  uw_catch_end;
+
+  return nil;
+}
+
 val type_mismatch(val fmt, ...)
 {
   va_list vl;
diff --git a/unwind.h b/unwind.h
index 30ab70c2..64f21a02 100644
--- a/unwind.h
+++ b/unwind.h
@@ -154,6 +154,7 @@ noreturn val uw_throwf(val sym, val fmt, ...);
 noreturn val uw_throwfv(val sym, val fmt, struct args *);
 noreturn val uw_errorf(val fmt, ...);
 noreturn val uw_errorfv(val fmt, struct args *args);
+val uw_warningf(val fmt, ...);
 val uw_defer_warning(val args);
 val uw_warning_exists(val tag);
 val uw_dump_deferred_warnings(val stream);
-- 
cgit v1.2.3