To: vim_dev@googlegroups.com Subject: Patch 8.2.0723 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.0723 Problem: Vim9: nested constant expression not evaluated compile time. Solution: Use compile_expr1() for parenthesis. Files: src/vim9compile.c, src/testdir/test_vim9_disassemble.vim *** ../vim-8.2.0722/src/vim9compile.c 2020-05-09 17:35:50.052198310 +0200 --- src/vim9compile.c 2020-05-09 18:17:56.599960479 +0200 *************** *** 136,142 **** static char e_var_notfound[] = N_("E1001: variable not found: %s"); static char e_syntax_at[] = N_("E1002: Syntax error at %s"); - static int compile_expr0(char_u **arg, cctx_T *cctx); static void delete_def_function_contents(dfunc_T *dfunc); static void arg_type_mismatch(type_T *expected, type_T *actual, int argidx); static int check_type(type_T *expected, type_T *actual, int give_msg); --- 136,141 ---- *************** *** 2358,2368 **** // possible expressions on these constants are applied at compile time. If // that is not possible, the code to push the constants needs to be generated // before other instructions. typedef struct { ! typval_T pp_tv[10]; // stack of ppconst constants int pp_used; // active entries in pp_tv[] } ppconst_T; /* * Generate a PUSH instruction for "tv". * "tv" will be consumed or cleared. --- 2357,2372 ---- // possible expressions on these constants are applied at compile time. If // that is not possible, the code to push the constants needs to be generated // before other instructions. + // Using 50 should be more than enough of 5 levels of (). + #define PPSIZE 50 typedef struct { ! typval_T pp_tv[PPSIZE]; // stack of ppconst constants int pp_used; // active entries in pp_tv[] } ppconst_T; + static int compile_expr0(char_u **arg, cctx_T *cctx); + static int compile_expr1(char_u **arg, cctx_T *cctx, ppconst_T *ppconst); + /* * Generate a PUSH instruction for "tv". * "tv" will be consumed or cleared. *************** *** 3590,3595 **** --- 3594,3600 ---- char_u *start_leader, *end_leader; int ret = OK; typval_T *rettv = &ppconst->pp_tv[ppconst->pp_used]; + int used_before = ppconst->pp_used; /* * Skip '!', '-' and '+' characters. They are handled later. *************** *** 3725,3731 **** * nested expression: (expression). */ case '(': *arg = skipwhite(*arg + 1); ! ret = compile_expr0(arg, cctx); // recursive! *arg = skipwhite(*arg); if (**arg == ')') ++*arg; --- 3730,3748 ---- * nested expression: (expression). */ case '(': *arg = skipwhite(*arg + 1); ! ! // recursive! ! if (ppconst->pp_used <= PPSIZE - 10) ! { ! ret = compile_expr1(arg, cctx, ppconst); ! } ! else ! { ! // Not enough space in ppconst, flush constants. ! if (generate_ppconst(cctx, ppconst) == FAIL) ! return FAIL; ! ret = compile_expr0(arg, cctx); ! } *arg = skipwhite(*arg); if (**arg == ')') ++*arg; *************** *** 3742,3748 **** if (ret == FAIL) return FAIL; ! if (rettv->v_type != VAR_UNKNOWN) { // apply the '!', '-' and '+' before the constant if (apply_leader(rettv, start_leader, end_leader) == FAIL) --- 3759,3765 ---- if (ret == FAIL) return FAIL; ! if (rettv->v_type != VAR_UNKNOWN && used_before == ppconst->pp_used) { // apply the '!', '-' and '+' before the constant if (apply_leader(rettv, start_leader, end_leader) == FAIL) *** ../vim-8.2.0722/src/testdir/test_vim9_disassemble.vim 2020-05-09 15:43:58.322878209 +0200 --- src/testdir/test_vim9_disassemble.vim 2020-05-09 18:17:46.679995690 +0200 *************** *** 1053,1058 **** --- 1053,1062 ---- return 2 + 3 * 4 / 6 + 7 enddef + def s:ComputeConstParen(): number + return ((2 + 4) * (8 / 2)) / (3 + 4) + enddef + def Test_simplify_const_expr() let res = execute('disass s:ConcatStrings') assert_match('\\d*_ConcatStrings.*' .. *************** *** 1065,1070 **** --- 1069,1080 ---- '\d PUSHNR 11.*' .. '\d RETURN', res) + + res = execute('disass s:ComputeConstParen') + assert_match('\\d*_ComputeConstParen.*' .. + '\d PUSHNR 3\>.*' .. + '\d RETURN', + res) enddef " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker *** ../vim-8.2.0722/src/version.c 2020-05-09 17:35:50.052198310 +0200 --- src/version.c 2020-05-09 18:04:34.219108951 +0200 *************** *** 748,749 **** --- 748,751 ---- { /* Add new patch number below this line */ + /**/ + 723, /**/ -- hundred-and-one symptoms of being an internet addict: 80. At parties, you introduce your spouse as your "service provider." /// 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 ///