Patch 8.2.0224
Problem:    compiling :elseif not tested yet.
Solution:   Add test for :elseif.  Fix generating jumps.
Files:      src/testdir/test_vim9_script.vim, src/vim9compile.c,
            src/testdir/test_vim9_disassemble.vim


*** ../vim-8.2.0223/src/testdir/test_vim9_script.vim    2020-02-06 
19:25:02.624298180 +0100
--- src/testdir/test_vim9_script.vim    2020-02-06 20:31:30.935293032 +0100
***************
*** 459,492 ****
  EOF
  endfunc
  
! def HasEval()
!   if has('eval')
!     echo 'yes'
    else
!     echo 'no'
    endif
  enddef
  
! def HasNothing()
!   if has('nothing')
!     echo 'yes'
!   else
!     echo 'no'
!   endif
! enddef
! 
! def Test_compile_const_expr()
!   assert_equal("\nyes", execute('call HasEval()'))
!   let instr = execute('disassemble HasEval')
!   assert_match('PUSHS "yes"', instr)
!   assert_notmatch('PUSHS "no"', instr)
!   assert_notmatch('JUMP', instr)
! 
!   assert_equal("\nno", execute('call HasNothing()'))
!   instr = execute('disassemble HasNothing')
!   assert_notmatch('PUSHS "yes"', instr)
!   assert_match('PUSHS "no"', instr)
!   assert_notmatch('JUMP', instr)
  enddef
  
  
--- 459,480 ----
  EOF
  endfunc
  
! def IfElse(what: number): string
!   let res = ''
!   if what == 1
!     res = "one"
!   elseif what == 2
!     res = "two"
    else
!     res = "three"
    endif
+   return res
  enddef
  
! def Test_if_elseif_else()
!   assert_equal('one', IfElse(1))
!   assert_equal('two', IfElse(2))
!   assert_equal('three', IfElse(3))
  enddef
  
  
*** ../vim-8.2.0223/src/vim9compile.c   2020-02-06 19:25:02.624298180 +0100
--- src/vim9compile.c   2020-02-06 20:37:55.629634016 +0100
***************
*** 3891,3897 ****
      }
      cctx->ctx_locals.ga_len = scope->se_local_count;
  
!     if (cctx->ctx_skip != TRUE)
      {
        if (compile_jump_to_end(&scope->se_u.se_if.is_end_label,
                                                    JUMP_ALWAYS, cctx) == FAIL)
--- 3891,3897 ----
      }
      cctx->ctx_locals.ga_len = 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)
***************
*** 3947,3959 ****
            return NULL;
      }
  
!     if (cctx->ctx_skip != TRUE)
      {
        if (scope->se_u.se_if.is_if_label >= 0)
        {
            // previous "if" or "elseif" jumps here
            isn = ((isn_T *)instr->ga_data) + scope->se_u.se_if.is_if_label;
            isn->isn_arg.jump.jump_where = instr->ga_len;
        }
      }
  
--- 3947,3960 ----
            return NULL;
      }
  
!     if (cctx->ctx_skip == MAYBE)
      {
        if (scope->se_u.se_if.is_if_label >= 0)
        {
            // previous "if" or "elseif" jumps here
            isn = ((isn_T *)instr->ga_data) + scope->se_u.se_if.is_if_label;
            isn->isn_arg.jump.jump_where = instr->ga_len;
+           scope->se_u.se_if.is_if_label = -1;
        }
      }
  
*** ../vim-8.2.0223/src/testdir/test_vim9_disassemble.vim       2020-02-06 
19:25:02.624298180 +0100
--- src/testdir/test_vim9_disassemble.vim       2020-02-06 20:24:28.309184832 
+0100
***************
*** 216,220 ****
--- 216,282 ----
          \, res)
  enddef
  
+ def HasEval()
+   if has("eval")
+     echo "yes"
+   else
+     echo "no"
+   endif
+ enddef
+ 
+ def HasNothing()
+   if has("nothing")
+     echo "yes"
+   else
+     echo "no"
+   endif
+ enddef
+ 
+ def HasSomething()
+   if has("nothing")
+     echo "nothing"
+   elseif has("something")
+     echo "something"
+   elseif has("eval")
+     echo "eval"
+   elseif has("less")
+     echo "less"
+   endif
+ enddef
+ 
+ def Test_compile_const_expr()
+   assert_equal("\nyes", execute('call HasEval()'))
+   let instr = execute('disassemble HasEval')
+   assert_match('HasEval.*'
+         \ .. 'if has("eval").*'
+         \ .. ' PUSHS "yes".*'
+         \, instr)
+   assert_notmatch('JUMP', instr)
+ 
+   assert_equal("\nno", execute('call HasNothing()'))
+   instr = execute('disassemble HasNothing')
+   assert_match('HasNothing.*'
+         \ .. 'if has("nothing").*'
+         \ .. 'else.*'
+         \ .. ' PUSHS "no".*'
+         \, instr)
+   assert_notmatch('PUSHS "yes"', instr)
+   assert_notmatch('JUMP', instr)
+ 
+   assert_equal("\neval", execute('call HasSomething()'))
+   instr = execute('disassemble HasSomething')
+   assert_match('HasSomething.*'
+         \ .. 'if has("nothing").*'
+         \ .. 'elseif has("something").*'
+         \ .. 'elseif has("eval").*'
+         \ .. ' PUSHS "eval".*'
+         \ .. 'elseif has("less").*'
+         \, instr)
+   assert_notmatch('PUSHS "nothing"', instr)
+   assert_notmatch('PUSHS "something"', instr)
+   assert_notmatch('PUSHS "less"', instr)
+   assert_notmatch('JUMP', instr)
+ enddef
+ 
  
  " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
*** ../vim-8.2.0223/src/version.c       2020-02-06 19:25:02.628298164 +0100
--- src/version.c       2020-02-06 20:16:05.155661022 +0100
***************
*** 744,745 ****
--- 744,747 ----
  {   /* Add new patch number below this line */
+ /**/
+     224,
  /**/

-- 
Micro$oft: where do you want to go today?
    Linux: where do you want to go tomorrow?
  FreeBSD: are you guys coming, or what?

 /// 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/202002061940.016JeMRF004259%40masaka.moolenaar.net.

Raspunde prin e-mail lui