Patch 8.2.1005
Problem:    Vim9: using TRUE/FALSE/MAYBE for ctx_skip is confusing.
Solution:   Use an enum value.
Files:      src/vim9compile.c


*** ../vim-8.2.1004/src/vim9compile.c   2020-06-18 18:26:18.959984391 +0200
--- src/vim9compile.c   2020-06-18 19:28:23.679332303 +0200
***************
*** 103,108 ****
--- 103,115 ----
      int               lv_arg;         // when TRUE this is an argument
  } lvar_T;
  
+ // values for ctx_skip
+ typedef enum {
+     SKIP_NOT,         // condition is a constant, produce code
+     SKIP_YES,         // condition is a constant, do NOT produce code
+     SKIP_UNKNONW      // condition is not a constant, produce code
+ } skip_T;
+ 
  /*
   * Context for compiling lines of Vim script.
   * Stores info about the local variables and condition stack.
***************
*** 121,128 ****
  
      garray_T  ctx_imports;        // imported items
  
!     int               ctx_skip;           // when TRUE skip commands, when 
FALSE skip
!                                   // commands after "else"
      scope_T   *ctx_scope;         // current scope, NULL at toplevel
  
      cctx_T    *ctx_outer;         // outer scope for lambda or nested
--- 128,134 ----
  
      garray_T  ctx_imports;        // imported items
  
!     skip_T    ctx_skip;
      scope_T   *ctx_scope;         // current scope, NULL at toplevel
  
      cctx_T    *ctx_outer;         // outer scope for lambda or nested
***************
*** 545,552 ****
  /////////////////////////////////////////////////////////////////////
  // Following generate_ functions expect the caller to call ga_grow().
  
! #define RETURN_NULL_IF_SKIP(cctx) if (cctx->ctx_skip == TRUE) return NULL
! #define RETURN_OK_IF_SKIP(cctx) if (cctx->ctx_skip == TRUE) return OK
  
  /*
   * Generate an instruction without arguments.
--- 551,558 ----
  /////////////////////////////////////////////////////////////////////
  // Following generate_ functions expect the caller to call ga_grow().
  
! #define RETURN_NULL_IF_SKIP(cctx) if (cctx->ctx_skip == SKIP_YES) return NULL
! #define RETURN_OK_IF_SKIP(cctx) if (cctx->ctx_skip == SKIP_YES) return OK
  
  /*
   * Generate an instruction without arguments.
***************
*** 2493,2499 ****
      int           ret = OK;
      int           save_skip = cctx->ctx_skip;
  
!     cctx->ctx_skip = FALSE;
      for (i = 0; i < ppconst->pp_used; ++i)
        if (generate_tv_PUSH(cctx, &ppconst->pp_tv[i]) == FAIL)
            ret = FAIL;
--- 2499,2505 ----
      int           ret = OK;
      int           save_skip = cctx->ctx_skip;
  
!     cctx->ctx_skip = SKIP_NOT;
      for (i = 0; i < ppconst->pp_used; ++i)
        if (generate_tv_PUSH(cctx, &ppconst->pp_tv[i]) == FAIL)
            ret = FAIL;
***************
*** 3851,3857 ****
        }
        start_leader = end_leader;   // don't apply again below
  
!       if (cctx->ctx_skip == TRUE)
            clear_tv(rettv);
        else
            // A constant expression can possibly be handled compile time,
--- 3857,3863 ----
        }
        start_leader = end_leader;   // don't apply again below
  
!       if (cctx->ctx_skip == SKIP_YES)
            clear_tv(rettv);
        else
            // A constant expression can possibly be handled compile time,
***************
*** 4347,4353 ****
            const_value = tv2bool(&ppconst->pp_tv[ppconst_used]);
            clear_tv(&ppconst->pp_tv[ppconst_used]);
            --ppconst->pp_used;
!           cctx->ctx_skip = save_skip == TRUE || !const_value;
        }
        else
        {
--- 4353,4360 ----
            const_value = tv2bool(&ppconst->pp_tv[ppconst_used]);
            clear_tv(&ppconst->pp_tv[ppconst_used]);
            --ppconst->pp_used;
!           cctx->ctx_skip = save_skip == SKIP_YES || !const_value
!                                                        ? SKIP_YES : SKIP_NOT;
        }
        else
        {
***************
*** 4393,4399 ****
  
        // evaluate the third expression
        if (has_const_expr)
!           cctx->ctx_skip = save_skip == TRUE || const_value;
        *arg = skipwhite(p + 1);
        if (may_get_next_line(p + 1, arg, cctx) == FAIL)
            return FAIL;
--- 4400,4407 ----
  
        // evaluate the third expression
        if (has_const_expr)
!           cctx->ctx_skip = save_skip == SKIP_YES || const_value
!                                                        ? SKIP_YES : SKIP_NOT;
        *arg = skipwhite(p + 1);
        if (may_get_next_line(p + 1, arg, cctx) == FAIL)
            return FAIL;
***************
*** 4521,4527 ****
      eap->arg = name_end;
      eap->getline = exarg_getline;
      eap->cookie = cctx;
!     eap->skip = cctx->ctx_skip == TRUE;
      eap->forceit = FALSE;
      ufunc = def_function(eap, name);
  
--- 4529,4535 ----
      eap->arg = name_end;
      eap->getline = exarg_getline;
      eap->cookie = cctx;
!     eap->skip = cctx->ctx_skip == SKIP_YES;
      eap->forceit = FALSE;
      ufunc = def_function(eap, name);
  
***************
*** 4728,4734 ****
            return NULL;
        end = p;
  
!       if (cctx->ctx_skip != TRUE)
        {
            type_T      *stacktype;
  
--- 4736,4742 ----
            return NULL;
        end = p;
  
!       if (cctx->ctx_skip != SKIP_YES)
        {
            type_T      *stacktype;
  
***************
*** 4787,4793 ****
        if (!heredoc)
            type = &t_any;
  
!       if (cctx->ctx_skip != TRUE)
        {
            if (*var_start == '&')
            {
--- 4795,4801 ----
        if (!heredoc)
            type = &t_any;
  
!       if (cctx->ctx_skip != SKIP_YES)
        {
            if (*var_start == '&')
            {
***************
*** 5013,5019 ****
            goto theend;
        }
  
!       if (lvar == NULL && dest == dest_local && cctx->ctx_skip != TRUE)
        {
            if (oplen > 1 && !heredoc)
            {
--- 5021,5027 ----
            goto theend;
        }
  
!       if (lvar == NULL && dest == dest_local && cctx->ctx_skip != SKIP_YES)
        {
            if (oplen > 1 && !heredoc)
            {
***************
*** 5067,5073 ****
  
        if (!heredoc)
        {
!           if (cctx->ctx_skip == TRUE)
            {
                if (oplen > 0 && var_count == 0)
                {
--- 5075,5081 ----
  
        if (!heredoc)
        {
!           if (cctx->ctx_skip == SKIP_YES)
            {
                if (oplen > 0 && var_count == 0)
                {
***************
*** 5227,5233 ****
        }
  
        // no need to parse more when skipping
!       if (cctx->ctx_skip == TRUE)
            break;
  
        if (oplen > 0 && *op != '=')
--- 5235,5241 ----
        }
  
        // no need to parse more when skipping
!       if (cctx->ctx_skip == SKIP_YES)
            break;
  
        if (oplen > 0 && *op != '=')
***************
*** 5668,5680 ****
      {
        // The expression results in a constant.
        // TODO: how about nesting?
!       cctx->ctx_skip = tv2bool(&ppconst.pp_tv[0]) ? FALSE : TRUE;
        clear_ppconst(&ppconst);
      }
      else
      {
        // Not a constant, generate instructions for the expression.
!       cctx->ctx_skip = MAYBE;
        if (generate_ppconst(cctx, &ppconst) == FAIL)
            return NULL;
      }
--- 5676,5688 ----
      {
        // The expression results in a constant.
        // TODO: how about nesting?
!       cctx->ctx_skip = tv2bool(&ppconst.pp_tv[0]) ? SKIP_NOT : SKIP_YES;
        clear_ppconst(&ppconst);
      }
      else
      {
        // Not a constant, generate instructions for the expression.
!       cctx->ctx_skip = SKIP_UNKNONW;
        if (generate_ppconst(cctx, &ppconst) == FAIL)
            return NULL;
      }
***************
*** 5683,5689 ****
      if (scope == NULL)
        return NULL;
  
!     if (cctx->ctx_skip == MAYBE)
      {
        // "where" is set when ":elseif", "else" or ":endif" is found
        scope->se_u.se_if.is_if_label = instr->ga_len;
--- 5691,5697 ----
      if (scope == NULL)
        return NULL;
  
!     if (cctx->ctx_skip == SKIP_UNKNONW)
      {
        // "where" is set when ":elseif", "else" or ":endif" is found
        scope->se_u.se_if.is_if_label = instr->ga_len;
***************
*** 5712,5718 ****
      }
      unwind_locals(cctx, scope->se_local_count);
  
!     if (cctx->ctx_skip == MAYBE)
      {
        if (compile_jump_to_end(&scope->se_u.se_if.is_end_label,
                                                    JUMP_ALWAYS, cctx) == FAIL)
--- 5720,5726 ----
      }
      unwind_locals(cctx, scope->se_local_count);
  
!     if (cctx->ctx_skip == SKIP_UNKNONW)
      {
        if (compile_jump_to_end(&scope->se_u.se_if.is_end_label,
                                                    JUMP_ALWAYS, cctx) == FAIL)
***************
*** 5733,5746 ****
      {
        // The expression results in a constant.
        // TODO: how about nesting?
!       cctx->ctx_skip = tv2bool(&ppconst.pp_tv[0]) ? FALSE : TRUE;
        clear_ppconst(&ppconst);
        scope->se_u.se_if.is_if_label = -1;
      }
      else
      {
        // Not a constant, generate instructions for the expression.
!       cctx->ctx_skip = MAYBE;
        if (generate_ppconst(cctx, &ppconst) == FAIL)
            return NULL;
  
--- 5741,5754 ----
      {
        // The expression results in a constant.
        // TODO: how about nesting?
!       cctx->ctx_skip = tv2bool(&ppconst.pp_tv[0]) ? SKIP_NOT : SKIP_YES;
        clear_ppconst(&ppconst);
        scope->se_u.se_if.is_if_label = -1;
      }
      else
      {
        // Not a constant, generate instructions for the expression.
!       cctx->ctx_skip = SKIP_UNKNONW;
        if (generate_ppconst(cctx, &ppconst) == FAIL)
            return NULL;
  
***************
*** 5768,5781 ****
      unwind_locals(cctx, scope->se_local_count);
  
      // jump from previous block to the end, unless the else block is empty
!     if (cctx->ctx_skip == MAYBE)
      {
        if (compile_jump_to_end(&scope->se_u.se_if.is_end_label,
                                                    JUMP_ALWAYS, cctx) == FAIL)
            return NULL;
      }
  
!     if (cctx->ctx_skip == MAYBE)
      {
        if (scope->se_u.se_if.is_if_label >= 0)
        {
--- 5776,5789 ----
      unwind_locals(cctx, scope->se_local_count);
  
      // jump from previous block to the end, unless the else block is empty
!     if (cctx->ctx_skip == SKIP_UNKNONW)
      {
        if (compile_jump_to_end(&scope->se_u.se_if.is_end_label,
                                                    JUMP_ALWAYS, cctx) == FAIL)
            return NULL;
      }
  
!     if (cctx->ctx_skip == SKIP_UNKNONW)
      {
        if (scope->se_u.se_if.is_if_label >= 0)
        {
***************
*** 5786,5793 ****
        }
      }
  
!     if (cctx->ctx_skip != MAYBE)
!       cctx->ctx_skip = !cctx->ctx_skip;
  
      return p;
  }
--- 5794,5801 ----
        }
      }
  
!     if (cctx->ctx_skip != SKIP_UNKNONW)
!       cctx->ctx_skip = cctx->ctx_skip == SKIP_YES ? SKIP_NOT : SKIP_YES;
  
      return p;
  }
***************
*** 5817,5823 ****
      // Fill in the "end" label in jumps at the end of the blocks.
      compile_fill_jump_to_end(&ifscope->is_end_label, cctx);
      // TODO: this should restore the value from before the :if
!     cctx->ctx_skip = MAYBE;
  
      drop_scope(cctx);
      return arg;
--- 5825,5831 ----
      // Fill in the "end" label in jumps at the end of the blocks.
      compile_fill_jump_to_end(&ifscope->is_end_label, cctx);
      // TODO: this should restore the value from before the :if
!     cctx->ctx_skip = SKIP_UNKNONW;
  
      drop_scope(cctx);
      return arg;
***************
*** 6416,6422 ****
      char_u  *p;
      int           has_expr = FALSE;
  
!     if (cctx->ctx_skip == TRUE)
        goto theend;
  
      if (eap->cmdidx >= 0 && eap->cmdidx < CMD_SIZE)
--- 6424,6430 ----
      char_u  *p;
      int           has_expr = FALSE;
  
!     if (cctx->ctx_skip == SKIP_YES)
        goto theend;
  
      if (eap->cmdidx >= 0 && eap->cmdidx < CMD_SIZE)
***************
*** 6781,6787 ****
  
        if (p == ea.cmd && ea.cmdidx != CMD_SIZE)
        {
!           if (cctx.ctx_skip == TRUE)
            {
                line += STRLEN(line);
                continue;
--- 6789,6795 ----
  
        if (p == ea.cmd && ea.cmdidx != CMD_SIZE)
        {
!           if (cctx.ctx_skip == SKIP_YES)
            {
                line += STRLEN(line);
                continue;
***************
*** 6806,6812 ****
  
        p = skipwhite(p);
  
!       if (cctx.ctx_skip == TRUE
                && ea.cmdidx != CMD_elseif
                && ea.cmdidx != CMD_else
                && ea.cmdidx != CMD_endif)
--- 6814,6820 ----
  
        p = skipwhite(p);
  
!       if (cctx.ctx_skip == SKIP_YES
                && ea.cmdidx != CMD_elseif
                && ea.cmdidx != CMD_else
                && ea.cmdidx != CMD_endif)
*** ../vim-8.2.1004/src/version.c       2020-06-18 19:14:58.901636994 +0200
--- src/version.c       2020-06-18 19:30:40.870779874 +0200
***************
*** 756,757 ****
--- 756,759 ----
  {   /* Add new patch number below this line */
+ /**/
+     1005,
  /**/

-- 
Be nice to your kids...  they'll be the ones choosing your nursing home.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/202006181731.05IHVYeV415455%40masaka.moolenaar.net.

Raspunde prin e-mail lui