pt icon indicating copy to clipboard operation
pt copied to clipboard

pt_loop - some comprehension comments

Open culyun opened this issue 5 years ago • 0 comments

Ok, you got me. I don't understand pt_loop. I don't get all the while(1) if (1) statements. I'm guessing you're trying to ensure that braced and non-braced loops can be implemented, but it's somewhat impenertrable.

As a suggestion..

Label the various loops and if statements with comments then refer to those labels in a prologue.

Eg. something like this:


#define pt_loop(pt, cond)                                                      \
  for (int _intr = 0; _intr == 0;)                                             \
    if (1) {  /* if_a */                                                                 \
      pt_label(pt, PT_STATUS_BLOCKED);                                         \
      if (!(cond)) { /* if_b */                                                           \
        break;                                                                 \
      }                                                                        \
      goto _pt_line(body);                                                     \
    } else                                                                     \
      while (1) /* while_a */                                                                \
        if (1) {  /* if_c */                                                             \
          _intr = 1;                                                           \
          break;                                                               \
        } else                                                                 \
          while (1)  /* while_b */                                                          \
            if (1) { /* if_d */                                                          \
              return;                                                          \
            } else                                                             \
  _pt_line(body) :

culyun avatar Dec 18 '20 10:12 culyun