utils/control.h: Allow statement block without terminating semicolon.
authorMark Wooding <mdw@distorted.org.uk>
Mon, 8 May 2023 23:42:32 +0000 (00:42 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Mon, 8 May 2023 23:51:06 +0000 (00:51 +0100)
utils/control.h
utils/t/control-test.c

index 77d985a..8be1cf1 100644 (file)
@@ -64,7 +64,7 @@
  * will then be to the statement following the containing action sequence and
  * its body.
  */
-#define MC_ACT(stmt)   if (1) stmt else
+#define MC_ACT(stmt)   if (1) { stmt; } else
 #define MC_PASS                MC_ACT(;)
 
 
  * action in its own right, in place of @MC_ACT@.
  */
 #define MC_LABEL(tag)  MCTRL__LABEL(tag):
-#define MC_GOTO(tag)   MC_ACT({ goto MCTRL__LABEL(tag); })
+#define MC_GOTO(tag)   MC_ACT(goto MCTRL__LABEL(tag))
 
 /* @BEFORE(tag, stmt_0) stmt_1@
  *
  * Execute @stmt_0@ and then @stmt_1@.
  */
 #define BEFORE(tag, stmt)                                              \
-                       MC_ACT({ stmt MC_GOTO(tag##__body); })          \
+                       MC_ACT(stmt; MC_GOTO(tag##__body))              \
   MC_LABEL(tag##__body)
 
 /* @AFTER(tag, stmt_0) stmt_1@
  * statements behave as one would expect from their context.
  */
 #define WRAP(tag, before, onend, onbreak)                              \
-                       MC_ACT({ before MC_GOTO(tag##__body); })        \
+                       MC_ACT(before; MC_GOTO(tag##__body))            \
   MC_LABEL(tag##__end) MC_ACT(onend)                                   \
   MC_LABEL(tag##__brk) MC_ACT(onbreak)                                 \
                        for (;;)                                        \
 #  define DECL(tag, decl)                                              \
                        for (decl;;)                                    \
                          MC_GOTO(tag##__body)                          \
-  MC_LABEL(tag##__end)   MC_ACT({ break; })                            \
+  MC_LABEL(tag##__end)   MC_ACT(break)                                 \
                          for (;;)                                      \
                            MC_GOTO(tag##__end)                         \
   MC_LABEL(tag##__body)
index d69572b..0f47e26 100644 (file)
@@ -55,9 +55,9 @@ static void laststep(int s, const char *where)
 
 #define FORELSE(head)                                                  \
                        MC_GOTO(top)                                    \
-  MC_LABEL(out)                MC_ACT({ ; })                                   \
+  MC_LABEL(out)                MC_ACT(;)                                       \
   MC_LABEL(top)                ALLOWELSE(els)                                  \
-                       AFTER(outer, { GOELSE(els); })                  \
+                       AFTER(outer, GOELSE(els))                       \
                        for (head)                                      \
                          WRAP(inner, { ; },                            \
                                      { ; },                            \
@@ -94,17 +94,17 @@ int main(void)
 {
   int i;
 
-  BEFORE(before0, { STEP(0); }) STEP(1);
-  AFTER(after0, { STEP(3); }) STEP(2);
+  BEFORE(before0, STEP(0)) STEP(1);
+  AFTER(after0, STEP(3)) STEP(2);
   LASTSTEP(4);
 
-  WRAP(wrap0, { STEP(0); }, { STEP(2); }, { MISSTEP; }) STEP(1);
-  WRAP(wrap1, { STEP(3); }, { MISSTEP; }, { STEP(5); }) { STEP(4); break; }
+  WRAP(wrap0, STEP(0), STEP(2), MISSTEP) STEP(1);
+  WRAP(wrap1, STEP(3), MISSTEP, STEP(5)) { STEP(4); break; }
   LASTSTEP(6);
 
   STEP(0);
   for (;;) {
-    AFTER(after1, { STEP(2); break; }) STEP(1);
+    AFTER(after1, STEP(2); break) STEP(1);
     MISSTEP; break;
   }
   LASTSTEP(3);
@@ -124,8 +124,8 @@ int main(void)
   LASTSTEP(11);
 
 #define TEST                                                           \
-                       MC_ACT({ STEP(0); MC_GOTO(in_plain); })         \
-  MC_LABEL(done_plain) MC_ACT({ STEP(5); GOELSE(elsie); })             \
+                       MC_ACT(STEP(0); MC_GOTO(in_plain))              \
+  MC_LABEL(done_plain) MC_ACT(STEP(5); GOELSE(elsie))                  \
   MC_LABEL(in_plain)   WRAP(outer_wrap, { STEP(1); },                  \
                                         { STEP(7); },                  \
                                         { MISSTEP; })                  \