To: vim_dev@googlegroups.com Subject: Patch 8.2.4367 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.4367 Problem: Calling in_vim9script() multiple times. Solution: Call it once and keep the result. Files: src/userfunc.c, src/eval.c *** ../vim-8.2.4366/src/userfunc.c 2022-02-12 22:13:02.259074450 +0000 --- src/userfunc.c 2022-02-13 11:51:11.163442587 +0000 *************** *** 1328,1335 **** int equal_arrow = **arg == '('; int white_error = FALSE; int called_emsg_start = called_emsg; ! if (equal_arrow && !in_vim9script()) return NOTDONE; ga_init(&newargs); --- 1328,1336 ---- int equal_arrow = **arg == '('; int white_error = FALSE; int called_emsg_start = called_emsg; + int vim9script = in_vim9script(); ! if (equal_arrow && !vim9script) return NOTDONE; ga_init(&newargs); *************** *** 1360,1366 **** FALSE, NULL, NULL); if (ret == FAIL || (s = skip_arrow(*arg, equal_arrow, &ret_type, ! equal_arrow || in_vim9script() ? &white_error : NULL)) == NULL) { if (types_optional) ga_clear_strings(&argtypes); --- 1361,1367 ---- FALSE, NULL, NULL); if (ret == FAIL || (s = skip_arrow(*arg, equal_arrow, &ret_type, ! equal_arrow || vim9script ? &white_error : NULL)) == NULL) { if (types_optional) ga_clear_strings(&argtypes); *************** *** 1485,1491 **** if (types_optional) { if (parse_argument_types(fp, &argtypes, ! in_vim9script() && varargs) == FAIL) goto errret; if (ret_type != NULL) { --- 1486,1492 ---- if (types_optional) { if (parse_argument_types(fp, &argtypes, ! vim9script && varargs) == FAIL) goto errret; if (ret_type != NULL) { *************** *** 1514,1520 **** flags |= FC_SANDBOX; // In legacy script a lambda can be called with more args than // uf_args.ga_len. In Vim9 script "...name" has to be used. ! fp->uf_varargs = !in_vim9script() || varargs; fp->uf_flags = flags; fp->uf_calls = 0; fp->uf_script_ctx = current_sctx; --- 1515,1521 ---- flags |= FC_SANDBOX; // In legacy script a lambda can be called with more args than // uf_args.ga_len. In Vim9 script "...name" has to be used. ! fp->uf_varargs = !vim9script || varargs; fp->uf_flags = flags; fp->uf_calls = 0; fp->uf_script_ctx = current_sctx; *************** *** 1779,1785 **** } ret = call_func(name, len, rettv, argcount, argvars, funcexe); ! if (in_vim9script() && did_emsg > did_emsg_before) { // An error in a builtin function does not return FAIL, but we do // want to abort further processing if an error was given. --- 1780,1786 ---- } ret = call_func(name, len, rettv, argcount, argvars, funcexe); ! if (vim9script && did_emsg > did_emsg_before) { // An error in a builtin function does not return FAIL, but we do // want to abort further processing if an error was given. *************** *** 1800,1806 **** while (--argcount >= 0) clear_tv(&argvars[argcount]); ! if (in_vim9script()) *arg = argp; else *arg = skipwhite(argp); --- 1801,1807 ---- while (--argcount >= 0) clear_tv(&argvars[argcount]); ! if (vim9script) *arg = argp; else *arg = skipwhite(argp); *************** *** 3714,3720 **** int extra = 0; int prefix_g = FALSE; lval_T lv; ! int vim9script; if (fdp != NULL) CLEAR_POINTER(fdp); --- 3715,3722 ---- int extra = 0; int prefix_g = FALSE; lval_T lv; ! int vim9script = in_vim9script(); ! int vim9_local; if (fdp != NULL) CLEAR_POINTER(fdp); *************** *** 3739,3745 **** // Note that TFN_ flags use the same values as GLV_ flags. end = get_lval(start, NULL, &lv, FALSE, skip, flags | GLV_READ_ONLY, lead > 2 ? 0 : FNE_CHECK_START); ! if (end == start || (in_vim9script() && end != NULL && end[-1] == AUTOLOAD_CHAR && *end == '(')) { if (!skip) --- 3741,3747 ---- // Note that TFN_ flags use the same values as GLV_ flags. end = get_lval(start, NULL, &lv, FALSE, skip, flags | GLV_READ_ONLY, lead > 2 ? 0 : FNE_CHECK_START); ! if (end == start || (vim9script && end != NULL && end[-1] == AUTOLOAD_CHAR && *end == '(')) { if (!skip) *************** *** 3905,3911 **** // In Vim9 script a user function is script-local by default, unless it // starts with a lower case character: dict.func(). ! vim9script = ASCII_ISUPPER(*start) && in_vim9script(); /* * Copy the function name to allocated memory. --- 3907,3913 ---- // In Vim9 script a user function is script-local by default, unless it // starts with a lower case character: dict.func(). ! vim9_local = ASCII_ISUPPER(*start) && vim9script; /* * Copy the function name to allocated memory. *************** *** 3914,3926 **** */ if (skip) lead = 0; // do nothing ! else if (lead > 0 || vim9script) { ! if (!vim9script) { ! if (in_vim9script() && lead == 2 && !ASCII_ISUPPER(*lv.ll_name)) { ! semsg(_(in_vim9script() ? e_function_name_must_start_with_capital_str : e_function_name_must_start_with_capital_or_s_str), start); --- 3916,3928 ---- */ if (skip) lead = 0; // do nothing ! else if (lead > 0 || vim9_local) { ! if (!vim9_local) { ! if (vim9script && lead == 2 && !ASCII_ISUPPER(*lv.ll_name)) { ! semsg(_(vim9script ? e_function_name_must_start_with_capital_str : e_function_name_must_start_with_capital_or_s_str), start); *************** *** 3928,3934 **** } lead = 3; } ! if (vim9script || (lv.ll_exp_name != NULL && eval_fname_sid(lv.ll_exp_name)) || eval_fname_sid(*pp)) { --- 3930,3936 ---- } lead = 3; } ! if (vim9_local || (lv.ll_exp_name != NULL && eval_fname_sid(lv.ll_exp_name)) || eval_fname_sid(*pp)) { *************** *** 3939,3955 **** goto theend; } sprintf((char *)sid_buf, "%ld_", (long)current_sctx.sc_sid); ! if (vim9script) extra = 3 + (int)STRLEN(sid_buf); else lead += (int)STRLEN(sid_buf); } } else if (!(flags & TFN_INT) && (builtin_function(lv.ll_name, len) ! || (in_vim9script() && *lv.ll_name == '_'))) { ! semsg(_(in_vim9script() ! ? e_function_name_must_start_with_capital_str : e_function_name_must_start_with_capital_or_s_str), start); goto theend; --- 3941,3956 ---- goto theend; } sprintf((char *)sid_buf, "%ld_", (long)current_sctx.sc_sid); ! if (vim9_local) extra = 3 + (int)STRLEN(sid_buf); else lead += (int)STRLEN(sid_buf); } } else if (!(flags & TFN_INT) && (builtin_function(lv.ll_name, len) ! || (vim9script && *lv.ll_name == '_'))) { ! semsg(_(vim9script ? e_function_name_must_start_with_capital_str : e_function_name_must_start_with_capital_or_s_str), start); goto theend; *************** *** 3968,3979 **** name = alloc(len + lead + extra + 1); if (name != NULL) { ! if (!skip && (lead > 0 || vim9script)) { name[0] = K_SPECIAL; name[1] = KS_EXTRA; name[2] = (int)KE_SNR; ! if (vim9script || lead > 3) // If it's "" STRCPY(name + 3, sid_buf); } else if (prefix_g) --- 3969,3980 ---- name = alloc(len + lead + extra + 1); if (name != NULL) { ! if (!skip && (lead > 0 || vim9_local)) { name[0] = K_SPECIAL; name[1] = KS_EXTRA; name[2] = (int)KE_SNR; ! if (vim9_local || lead > 3) // If it's "" STRCPY(name + 3, sid_buf); } else if (prefix_g) *************** *** 4546,4552 **** int ffed_flags = is_global ? FFED_IS_GLOBAL : 0; v = find_var(name, &ht, TRUE); ! if (v != NULL && (in_vim9script() || v->di_tv.v_type == VAR_FUNC)) var_conflict = TRUE; if (SCRIPT_ID_VALID(current_sctx.sc_sid)) --- 4547,4553 ---- int ffed_flags = is_global ? FFED_IS_GLOBAL : 0; v = find_var(name, &ht, TRUE); ! if (v != NULL && (vim9script || v->di_tv.v_type == VAR_FUNC)) var_conflict = TRUE; if (SCRIPT_ID_VALID(current_sctx.sc_sid)) *************** *** 5299,5304 **** --- 5300,5306 ---- evalarg_T evalarg; type_T *type = NULL; int found_var = FALSE; + int vim9script = in_vim9script(); fill_evalarg_from_eap(&evalarg, eap, eap->skip); if (eap->skip) *************** *** 5315,5321 **** } tofree = trans_function_name(&arg, NULL, eap->skip, TFN_INT, ! &fudi, &partial, in_vim9script() ? &type : NULL); if (fudi.fd_newkey != NULL) { // Still need to give an error message for missing key. --- 5317,5323 ---- } tofree = trans_function_name(&arg, NULL, eap->skip, TFN_INT, ! &fudi, &partial, vim9script ? &type : NULL); if (fudi.fd_newkey != NULL) { // Still need to give an error message for missing key. *************** *** 5335,5341 **** // from trans_function_name(). len = (int)STRLEN(tofree); name = deref_func_name(tofree, &len, partial != NULL ? NULL : &partial, ! in_vim9script() && type == NULL ? &type : NULL, FALSE, FALSE, &found_var); // Skip white space to allow ":call func ()". Not good, but required for --- 5337,5343 ---- // from trans_function_name(). len = (int)STRLEN(tofree); name = deref_func_name(tofree, &len, partial != NULL ? NULL : &partial, ! vim9script && type == NULL ? &type : NULL, FALSE, FALSE, &found_var); // Skip white space to allow ":call func ()". Not good, but required for *************** *** 5346,5352 **** semsg(_(e_missing_parenthesis_str), eap->arg); goto end; } ! if (in_vim9script() && startarg > arg) { semsg(_(e_no_white_space_allowed_before_str_str), "(", eap->arg); goto end; --- 5348,5354 ---- semsg(_(e_missing_parenthesis_str), eap->arg); goto end; } ! if (vim9script && startarg > arg) { semsg(_(e_no_white_space_allowed_before_str_str), "(", eap->arg); goto end; *** ../vim-8.2.4366/src/eval.c 2022-02-12 19:52:22.024702251 +0000 --- src/eval.c 2022-02-13 11:56:02.771316433 +0000 *************** *** 865,870 **** --- 865,871 ---- hashtab_T *ht = NULL; int quiet = flags & GLV_QUIET; int writing; + int vim9script = in_vim9script(); // Clear everything in "lp". CLEAR_POINTER(lp); *************** *** 879,885 **** } // Cannot use "s:var" at the Vim9 script level. "s: type" is OK. ! if (in_vim9script() && at_script_level() && name[0] == 's' && name[1] == ':' && !VIM_ISWHITE(name[2])) { semsg(_(e_cannot_use_s_colon_in_vim9_script_str), name); --- 880,886 ---- } // Cannot use "s:var" at the Vim9 script level. "s: type" is OK. ! if (vim9script && at_script_level() && name[0] == 's' && name[1] == ':' && !VIM_ISWHITE(name[2])) { semsg(_(e_cannot_use_s_colon_in_vim9_script_str), name); *************** *** 918,924 **** { lp->ll_name = name; ! if (in_vim9script()) { // "a: type" is declaring variable "a" with a type, not "a:". if (p == name + 2 && p[-1] == ':') --- 919,925 ---- { lp->ll_name = name; ! if (vim9script) { // "a: type" is declaring variable "a" with a type, not "a:". if (p == name + 2 && p[-1] == ':') *************** *** 996,1002 **** if ((*p != '[' && *p != '.')) return p; ! if (in_vim9script() && lval_root != NULL) { // using local variable lp->ll_tv = lval_root; --- 997,1003 ---- if ((*p != '[' && *p != '.')) return p; ! if (vim9script && lval_root != NULL) { // using local variable lp->ll_tv = lval_root; *************** *** 1018,1024 **** lp->ll_tv = &v->di_tv; } ! if (in_vim9script() && (flags & GLV_NO_DECL) == 0) { if (!quiet) semsg(_(e_variable_already_declared), lp->ll_name); --- 1019,1025 ---- lp->ll_tv = &v->di_tv; } ! if (vim9script && (flags & GLV_NO_DECL) == 0) { if (!quiet) semsg(_(e_variable_already_declared), lp->ll_name); *************** *** 1061,1067 **** return NULL; } ! if (in_vim9script() && lp->ll_valtype == NULL && v != NULL && lp->ll_tv == &v->di_tv && ht != NULL && ht == get_script_local_ht()) --- 1062,1068 ---- return NULL; } ! if (vim9script && lp->ll_valtype == NULL && v != NULL && lp->ll_tv == &v->di_tv && ht != NULL && ht == get_script_local_ht()) *************** *** 2612,2618 **** *arg = eval_next_line(evalarg_used); else { ! if (evaluate && in_vim9script() && !VIM_ISWHITE(p[-1])) { error_white_both(p, 2); clear_tv(rettv); --- 2613,2619 ---- *arg = eval_next_line(evalarg_used); else { ! if (evaluate && vim9script && !VIM_ISWHITE(p[-1])) { error_white_both(p, 2); clear_tv(rettv); *************** *** 2624,2630 **** /* * Get the second variable. */ ! if (evaluate && in_vim9script() && !IS_WHITE_OR_NUL((*arg)[2])) { error_white_both(*arg, 2); clear_tv(rettv); --- 2625,2631 ---- /* * Get the second variable. */ ! if (evaluate && vim9script && !IS_WHITE_OR_NUL((*arg)[2])) { error_white_both(*arg, 2); clear_tv(rettv); *************** *** 2750,2756 **** /* * Get the second variable. */ ! if (evaluate && in_vim9script() && !IS_WHITE_OR_NUL((*arg)[2])) { error_white_both(*arg, 2); clear_tv(rettv); --- 2751,2757 ---- /* * Get the second variable. */ ! if (evaluate && vim9script && !IS_WHITE_OR_NUL((*arg)[2])) { error_white_both(*arg, 2); clear_tv(rettv); *************** *** 3527,3533 **** char_u *start_leader, *end_leader; int ret = OK; char_u *alias; ! static int recurse = 0; /* * Initialise variable so that clear_tv() can't mistake this for a --- 3528,3535 ---- char_u *start_leader, *end_leader; int ret = OK; char_u *alias; ! static int recurse = 0; ! int vim9script = in_vim9script(); /* * Initialise variable so that clear_tv() can't mistake this for a *************** *** 3539,3545 **** * Skip '!', '-' and '+' characters. They are handled later. */ start_leader = *arg; ! if (eval_leader(arg, in_vim9script()) == FAIL) return FAIL; end_leader = *arg; --- 3541,3547 ---- * Skip '!', '-' and '+' characters. They are handled later. */ start_leader = *arg; ! if (eval_leader(arg, vim9script) == FAIL) return FAIL; end_leader = *arg; *************** *** 3614,3620 **** /* * Dictionary: #{key: val, key: val} */ ! case '#': if (in_vim9script()) { ret = vim9_bad_comment(*arg) ? FAIL : NOTDONE; } --- 3616,3622 ---- /* * Dictionary: #{key: val, key: val} */ ! case '#': if (vim9script) { ret = vim9_bad_comment(*arg) ? FAIL : NOTDONE; } *************** *** 3631,3640 **** * Lambda: {arg, arg -> expr} * Dictionary: {'key': val, 'key': val} */ ! case '{': if (in_vim9script()) ret = NOTDONE; else ! ret = get_lambda_tv(arg, rettv, in_vim9script(), evalarg); if (ret == NOTDONE) ret = eval_dict(arg, rettv, evalarg, FALSE); break; --- 3633,3642 ---- * Lambda: {arg, arg -> expr} * Dictionary: {'key': val, 'key': val} */ ! case '{': if (vim9script) ret = NOTDONE; else ! ret = get_lambda_tv(arg, rettv, vim9script, evalarg); if (ret == NOTDONE) ret = eval_dict(arg, rettv, evalarg, FALSE); break; *************** *** 3657,3665 **** case '@': ++*arg; if (evaluate) { ! if (in_vim9script() && IS_WHITE_OR_NUL(**arg)) semsg(_(e_syntax_error_at_str), *arg); ! else if (in_vim9script() && !valid_yank_reg(**arg, FALSE)) emsg_invreg(**arg); else { --- 3659,3667 ---- case '@': ++*arg; if (evaluate) { ! if (vim9script && IS_WHITE_OR_NUL(**arg)) semsg(_(e_syntax_error_at_str), *arg); ! else if (vim9script && !valid_yank_reg(**arg, FALSE)) emsg_invreg(**arg); else { *************** *** 3677,3683 **** * or lambda: (arg) => expr */ case '(': ret = NOTDONE; ! if (in_vim9script()) { ret = get_lambda_tv(arg, rettv, TRUE, evalarg); if (ret == OK && evaluate) --- 3679,3685 ---- * or lambda: (arg) => expr */ case '(': ret = NOTDONE; ! if (vim9script) { ret = get_lambda_tv(arg, rettv, TRUE, evalarg); if (ret == OK && evaluate) *************** *** 3735,3752 **** { int flags = evalarg == NULL ? 0 : evalarg->eval_flags; ! if (evaluate && in_vim9script() && len == 1 && *s == '_') { emsg(_(e_cannot_use_underscore_here)); ret = FAIL; } ! else if (evaluate && in_vim9script() && len > 2 && s[0] == 's' && s[1] == ':') { semsg(_(e_cannot_use_s_colon_in_vim9_script_str), s); ret = FAIL; } ! else if ((in_vim9script() ? **arg : *skipwhite(*arg)) == '(') { // "name(..." recursive! *arg = skipwhite(*arg); --- 3737,3754 ---- { int flags = evalarg == NULL ? 0 : evalarg->eval_flags; ! if (evaluate && vim9script && len == 1 && *s == '_') { emsg(_(e_cannot_use_underscore_here)); ret = FAIL; } ! else if (evaluate && vim9script && len > 2 && s[0] == 's' && s[1] == ':') { semsg(_(e_cannot_use_s_colon_in_vim9_script_str), s); ret = FAIL; } ! else if ((vim9script ? **arg : *skipwhite(*arg)) == '(') { // "name(..." recursive! *arg = skipwhite(*arg); *************** *** 3757,3777 **** else if (evaluate) { // get the value of "true", "false" or a variable ! if (len == 4 && in_vim9script() && STRNCMP(s, "true", 4) == 0) { rettv->v_type = VAR_BOOL; rettv->vval.v_number = VVAL_TRUE; ret = OK; } ! else if (len == 5 && in_vim9script() ! && STRNCMP(s, "false", 5) == 0) { rettv->v_type = VAR_BOOL; rettv->vval.v_number = VVAL_FALSE; ret = OK; } ! else if (len == 4 && in_vim9script() ! && STRNCMP(s, "null", 4) == 0) { rettv->v_type = VAR_SPECIAL; rettv->vval.v_number = VVAL_NULL; --- 3759,3777 ---- else if (evaluate) { // get the value of "true", "false" or a variable ! if (len == 4 && vim9script && STRNCMP(s, "true", 4) == 0) { rettv->v_type = VAR_BOOL; rettv->vval.v_number = VVAL_TRUE; ret = OK; } ! else if (len == 5 && vim9script && STRNCMP(s, "false", 5) == 0) { rettv->v_type = VAR_BOOL; rettv->vval.v_number = VVAL_FALSE; ret = OK; } ! else if (len == 4 && vim9script && STRNCMP(s, "null", 4) == 0) { rettv->v_type = VAR_SPECIAL; rettv->vval.v_number = VVAL_NULL; *************** *** 3826,3831 **** --- 3826,3832 ---- int error = FALSE; varnumber_T val = 0; vartype_T type = rettv->v_type; + int vim9script = in_vim9script(); #ifdef FEAT_FLOAT float_T f = 0.0; *************** *** 3836,3842 **** { while (VIM_ISWHITE(end_leader[-1])) --end_leader; ! if (in_vim9script() && end_leader[-1] == '!') val = tv2bool(rettv); else val = tv_get_number_chk(rettv, &error); --- 3837,3843 ---- { while (VIM_ISWHITE(end_leader[-1])) --end_leader; ! if (vim9script && end_leader[-1] == '!') val = tv2bool(rettv); else val = tv_get_number_chk(rettv, &error); *************** *** 3861,3867 **** #ifdef FEAT_FLOAT if (rettv->v_type == VAR_FLOAT) { ! if (in_vim9script()) { rettv->v_type = VAR_BOOL; val = f == 0.0 ? VVAL_TRUE : VVAL_FALSE; --- 3862,3868 ---- #ifdef FEAT_FLOAT if (rettv->v_type == VAR_FLOAT) { ! if (vim9script) { rettv->v_type = VAR_BOOL; val = f == 0.0 ? VVAL_TRUE : VVAL_FALSE; *************** *** 3899,3905 **** #endif { clear_tv(rettv); ! if (in_vim9script()) rettv->v_type = type; else rettv->v_type = VAR_NUMBER; --- 3900,3906 ---- #endif { clear_tv(rettv); ! if (vim9script) rettv->v_type = type; else rettv->v_type = VAR_NUMBER; *************** *** 4151,4157 **** int range = FALSE; char_u *key = NULL; int keylen = -1; ! int vim9 = in_vim9script(); if (check_can_index(rettv, evaluate, verbose) == FAIL) return FAIL; --- 4152,4158 ---- int range = FALSE; char_u *key = NULL; int keylen = -1; ! int vim9script = in_vim9script(); if (check_can_index(rettv, evaluate, verbose) == FAIL) return FAIL; *************** *** 4182,4188 **** empty1 = TRUE; else if (eval1(arg, &var1, evalarg) == FAIL) // recursive! return FAIL; ! else if (vim9 && **arg == ':') { semsg(_(e_white_space_required_before_and_after_str_at_str), ":", *arg); --- 4183,4189 ---- empty1 = TRUE; else if (eval1(arg, &var1, evalarg) == FAIL) // recursive! return FAIL; ! else if (vim9script && **arg == ':') { semsg(_(e_white_space_required_before_and_after_str_at_str), ":", *arg); *************** *** 4195,4208 **** #ifdef FEAT_FLOAT // allow for indexing with float ! if (vim9 && rettv->v_type == VAR_DICT && var1.v_type == VAR_FLOAT) { var1.vval.v_string = typval_tostring(&var1, TRUE); var1.v_type = VAR_STRING; } #endif ! if (vim9 && rettv->v_type == VAR_LIST) tv_get_number_chk(&var1, &error); else error = tv_get_string_chk(&var1) == NULL; --- 4196,4209 ---- #ifdef FEAT_FLOAT // allow for indexing with float ! if (vim9script && rettv->v_type == VAR_DICT && var1.v_type == VAR_FLOAT) { var1.vval.v_string = typval_tostring(&var1, TRUE); var1.v_type = VAR_STRING; } #endif ! if (vim9script && rettv->v_type == VAR_LIST) tv_get_number_chk(&var1, &error); else error = tv_get_string_chk(&var1) == NULL; *************** *** 4222,4228 **** { range = TRUE; ++*arg; ! if (vim9 && !IS_WHITE_OR_NUL(**arg) && **arg != ']') { semsg(_(e_white_space_required_before_and_after_str_at_str), ":", *arg - 1); --- 4223,4229 ---- { range = TRUE; ++*arg; ! if (vim9script && !IS_WHITE_OR_NUL(**arg) && **arg != ']') { semsg(_(e_white_space_required_before_and_after_str_at_str), ":", *arg - 1); *** ../vim-8.2.4366/src/version.c 2022-02-13 11:45:05.407225148 +0000 --- src/version.c 2022-02-13 11:56:19.619304045 +0000 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 4367, /**/ -- He who laughs last, thinks slowest. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///