To: vim_dev@googlegroups.com Subject: Patch 8.2.0188 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.0188 Problem: Check commands don't work well with Vim9 script. Solution: Improve constant expression handling. Files: src/vim9compile.c, src/testdir/check.vim, src/testdir/test_vim9_expr.vim *** ../vim-8.2.0187/src/vim9compile.c 2020-01-31 21:20:47.268673901 +0100 --- src/vim9compile.c 2020-01-31 21:46:01.918655312 +0100 *************** *** 3460,3473 **** } /* ! * Evaluate an expression that is a constant: has(arg) * Return FAIL if the expression is not a constant. */ static int ! evaluate_const_expr4(char_u **arg, cctx_T *cctx UNUSED, typval_T *tv) { typval_T argvars[2]; if (STRNCMP("has(", *arg, 4) != 0) return FAIL; *arg = skipwhite(*arg + 4); --- 3460,3490 ---- } /* ! * Evaluate an expression that is a constant: ! * has(arg) ! * ! * Also handle: ! * ! in front logical NOT ! * * Return FAIL if the expression is not a constant. */ static int ! evaluate_const_expr7(char_u **arg, cctx_T *cctx UNUSED, typval_T *tv) { typval_T argvars[2]; + char_u *start_leader, *end_leader; + /* + * Skip '!' characters. They are handled later. + */ + start_leader = *arg; + while (**arg == '!') + *arg = skipwhite(*arg + 1); + end_leader = *arg; + + /* + * Recognize only has() for now. + */ if (STRNCMP("has(", *arg, 4) != 0) return FAIL; *arg = skipwhite(*arg + 4); *************** *** 3497,3502 **** --- 3514,3526 ---- f_has(argvars, tv); clear_tv(&argvars[0]); + while (start_leader < end_leader) + { + if (*start_leader == '!') + tv->vval.v_number = !tv->vval.v_number; + ++start_leader; + } + return OK; } *************** *** 3529,3535 **** *arg = skipwhite(p + 2); tv2.v_type = VAR_UNKNOWN; if ((opchar == '|' ? evaluate_const_expr3(arg, cctx, &tv2) ! : evaluate_const_expr4(arg, cctx, &tv2)) == FAIL) { clear_tv(&tv2); return FAIL; --- 3553,3559 ---- *arg = skipwhite(p + 2); tv2.v_type = VAR_UNKNOWN; if ((opchar == '|' ? evaluate_const_expr3(arg, cctx, &tv2) ! : evaluate_const_expr7(arg, cctx, &tv2)) == FAIL) { clear_tv(&tv2); return FAIL; *************** *** 3558,3564 **** evaluate_const_expr3(char_u **arg, cctx_T *cctx, typval_T *tv) { // evaluate the first expression ! if (evaluate_const_expr4(arg, cctx, tv) == FAIL) return FAIL; // || and && work almost the same --- 3582,3588 ---- evaluate_const_expr3(char_u **arg, cctx_T *cctx, typval_T *tv) { // evaluate the first expression ! if (evaluate_const_expr7(arg, cctx, tv) == FAIL) return FAIL; // || and && work almost the same *** ../vim-8.2.0187/src/testdir/check.vim 2019-11-29 20:22:31.000000000 +0100 --- src/testdir/check.vim 2020-01-31 22:03:26.206940097 +0100 *************** *** 1,10 **** source shared.vim " Command to check for the presence of a feature. command -nargs=1 CheckFeature call CheckFeature() func CheckFeature(name) if !has(a:name) ! throw 'Skipped: ' .. a:name .. ' feature missing' endif endfunc --- 1,12 ---- source shared.vim + command -nargs=1 MissingFeature throw 'Skipped: ' .. .. ' feature missing' + " Command to check for the presence of a feature. command -nargs=1 CheckFeature call CheckFeature() func CheckFeature(name) if !has(a:name) ! MissingFeature a:name endif endfunc *** ../vim-8.2.0187/src/testdir/test_vim9_expr.vim 2020-01-30 18:24:47.001204003 +0100 --- src/testdir/test_vim9_expr.vim 2020-01-31 22:07:58.934029510 +0100 *************** *** 31,37 **** assert_equal('two', false ? 'one' : 'two') assert_equal('two', 0 ? 'one' : 'two') ! assert_equal('two', 0.0 ? 'one' : 'two') assert_equal('two', '' ? 'one' : 'two') " assert_equal('one', 0z ? 'one' : 'two') assert_equal('two', [] ? 'one' : 'two') --- 31,39 ---- assert_equal('two', false ? 'one' : 'two') assert_equal('two', 0 ? 'one' : 'two') ! if has('float') ! assert_equal('two', 0.0 ? 'one' : 'two') ! endif assert_equal('two', '' ? 'one' : 'two') " assert_equal('one', 0z ? 'one' : 'two') assert_equal('two', [] ? 'one' : 'two') *************** *** 420,441 **** enddef def Test_expr5_float() ! CheckFeature float ! assert_equal(66.0, 60.0 + 6.0) ! assert_equal(66.0, 60.0 + 6) ! assert_equal(66.0, 60 + 6.0) ! assert_equal(5.1, g:afloat + 5) ! assert_equal(8.1, 8 + g:afloat) ! assert_equal(10.1, g:anint + g:afloat) ! assert_equal(10.1, g:afloat + g:anint) ! ! assert_equal(54.0, 60.0 - 6.0) ! assert_equal(54.0, 60.0 - 6) ! assert_equal(54.0, 60 - 6.0) ! assert_equal(-4.9, g:afloat - 5) ! assert_equal(7.9, 8 - g:afloat) ! assert_equal(9.9, g:anint - g:afloat) ! assert_equal(-9.9, g:afloat - g:anint) enddef func Test_expr5_fails() --- 422,446 ---- enddef def Test_expr5_float() ! if !has('float') ! MissingFeature 'float' ! else ! assert_equal(66.0, 60.0 + 6.0) ! assert_equal(66.0, 60.0 + 6) ! assert_equal(66.0, 60 + 6.0) ! assert_equal(5.1, g:afloat + 5) ! assert_equal(8.1, 8 + g:afloat) ! assert_equal(10.1, g:anint + g:afloat) ! assert_equal(10.1, g:afloat + g:anint) ! ! assert_equal(54.0, 60.0 - 6.0) ! assert_equal(54.0, 60.0 - 6) ! assert_equal(54.0, 60 - 6.0) ! assert_equal(-4.9, g:afloat - 5) ! assert_equal(7.9, 8 - g:afloat) ! assert_equal(9.9, g:anint - g:afloat) ! assert_equal(-9.9, g:afloat - g:anint) ! endif enddef func Test_expr5_fails() *************** *** 476,502 **** enddef def Test_expr6_float() ! CheckFeature float ! ! assert_equal(36.0, 6.0 * 6) ! assert_equal(36.0, 6 * 6.0) ! assert_equal(36.0, 6.0 * 6.0) ! assert_equal(1.0, g:afloat * g:anint) ! ! assert_equal(10.0, 60 / 6.0) ! assert_equal(10.0, 60.0 / 6) ! assert_equal(10.0, 60.0 / 6.0) ! assert_equal(0.01, g:afloat / g:anint) ! ! assert_equal(4.0, 6.0 * 4 / 6) ! assert_equal(4.0, 6 * 4.0 / 6) ! assert_equal(4.0, 6 * 4 / 6.0) ! assert_equal(4.0, 6.0 * 4.0 / 6) ! assert_equal(4.0, 6 * 4.0 / 6.0) ! assert_equal(4.0, 6.0 * 4 / 6.0) ! assert_equal(4.0, 6.0 * 4.0 / 6.0) ! assert_equal(4.0, 6.0 * 4.0 / 6.0) enddef func Test_expr6_fails() --- 481,509 ---- enddef def Test_expr6_float() ! if !has('float') ! MissingFeature 'float' ! else ! assert_equal(36.0, 6.0 * 6) ! assert_equal(36.0, 6 * 6.0) ! assert_equal(36.0, 6.0 * 6.0) ! assert_equal(1.0, g:afloat * g:anint) ! ! assert_equal(10.0, 60 / 6.0) ! assert_equal(10.0, 60.0 / 6) ! assert_equal(10.0, 60.0 / 6.0) ! assert_equal(0.01, g:afloat / g:anint) ! ! assert_equal(4.0, 6.0 * 4 / 6) ! assert_equal(4.0, 6 * 4.0 / 6) ! assert_equal(4.0, 6 * 4 / 6.0) ! assert_equal(4.0, 6.0 * 4.0 / 6) ! assert_equal(4.0, 6 * 4.0 / 6.0) ! assert_equal(4.0, 6.0 * 4 / 6.0) ! assert_equal(4.0, 6.0 * 4.0 / 6.0) ! assert_equal(4.0, 6.0 * 4.0 / 6.0) ! endif enddef func Test_expr6_fails() *************** *** 581,587 **** def Test_expr7_float() " float constant ! if has('float') assert_equal(g:float_zero, .0) assert_equal(g:float_zero, 0.0) assert_equal(g:float_neg, -9.8) --- 588,596 ---- def Test_expr7_float() " float constant ! if !has('float') ! MissingFeature 'float' ! else assert_equal(g:float_zero, .0) assert_equal(g:float_zero, 0.0) assert_equal(g:float_neg, -9.8) *** ../vim-8.2.0187/src/version.c 2020-01-31 21:20:47.268673901 +0100 --- src/version.c 2020-01-31 22:10:35.101489364 +0100 *************** *** 744,745 **** --- 744,747 ---- { /* Add new patch number below this line */ + /**/ + 188, /**/ -- hundred-and-one symptoms of being an internet addict: 27. You refer to your age as 3.x. /// Bram Moolenaar -- Bram@Moolenaar.net -- 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 ///