From 19de2ff4e803f9926331e96914478b79ebcfd683 Mon Sep 17 00:00:00 2001
From: MadMaurice <madmaurice@zom.bi>
Date: Sat, 10 Apr 2021 22:14:02 +0200
Subject: [PATCH] Add implicit tagbody to the do macro

---
 lib/Minilisp.pm |  2 +-
 t/do.t          | 16 +++++++++++++++-
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/lib/Minilisp.pm b/lib/Minilisp.pm
index 57c5f4b..e01a4ba 100644
--- a/lib/Minilisp.pm
+++ b/lib/Minilisp.pm
@@ -960,7 +960,7 @@ sub macro_do {
 
   slurp_token($ts, RPAREN, "Expected ) after resultform");
 
-  my $body = macro_progn($ts);
+  my $body = macro_tagbody($ts);
 
   return create_block("nil", sub {
     my $octx = shift;
diff --git a/t/do.t b/t/do.t
index c09bd9f..fc322eb 100644
--- a/t/do.t
+++ b/t/do.t
@@ -1,4 +1,6 @@
-(plan 3)
+(plan 4)
+
+(defun nop () nil)
 
 (expect "do - simple example"
         (equal (do ((n 1)) (t n)) 1))
@@ -20,3 +22,15 @@
                       (do () (t)
                           (return 'fail))
                       'ok)))
+
+(expect "do - implicit tagbody"
+        (equal 'ok
+               (catch 'test
+                 (do ((n 0 (+ 1 n))) ((> n 0))
+                     (nop)
+                     (nop)
+                     (go end)
+                     middle
+                     (throw 'test 'fail)
+                     end)
+                 'ok)))