comparison src/vim9execute.c @ 28249:4b322951ebac v8.2.4650

patch 8.2.4650: "import autoload" only works with using 'runtimepath' Commit: https://github.com/vim/vim/commit/c0ceeeb839b8c6bebd3a2abd1c07d40ec3c6edca Author: Bram Moolenaar <Bram@vim.org> Date: Wed Mar 30 21:12:27 2022 +0100 patch 8.2.4650: "import autoload" only works with using 'runtimepath' Problem: "import autoload" only works with using 'runtimepath'. Solution: Also support a relative and absolute file name.
author Bram Moolenaar <Bram@vim.org>
date Wed, 30 Mar 2022 22:15:04 +0200
parents e31f1a949d4e
children d817abf991df
comparison
equal deleted inserted replaced
28248:08964a0fe111 28249:4b322951ebac
1508 { 1508 {
1509 if (dfunc != NULL) 1509 if (dfunc != NULL)
1510 emsg(_(e_script_variable_type_changed)); 1510 emsg(_(e_script_variable_type_changed));
1511 return NULL; 1511 return NULL;
1512 } 1512 }
1513
1514 if (!sv->sv_export && sref->sref_sid != current_sctx.sc_sid)
1515 {
1516 if (dfunc != NULL)
1517 semsg(_(e_item_not_exported_in_script_str), sv->sv_name);
1518 return NULL;
1519 }
1513 return sv; 1520 return sv;
1514 } 1521 }
1515 1522
1516 /* 1523 /*
1517 * Function passed to do_cmdline() for splitting a script joined by NL 1524 * Function passed to do_cmdline() for splitting a script joined by NL
2621 tv->vval.v_instr->instr_ectx = ectx; 2628 tv->vval.v_instr->instr_ectx = ectx;
2622 tv->vval.v_instr->instr_instr = iptr->isn_arg.instr; 2629 tv->vval.v_instr->instr_instr = iptr->isn_arg.instr;
2623 } 2630 }
2624 break; 2631 break;
2625 2632
2633 case ISN_SOURCE:
2634 {
2635 scriptitem_T *si = SCRIPT_ITEM(iptr->isn_arg.number);
2636
2637 if (si->sn_state == SN_STATE_NOT_LOADED)
2638 {
2639 SOURCING_LNUM = iptr->isn_lnum;
2640 if (do_source(si->sn_name, FALSE, DOSO_NONE, NULL)
2641 == FAIL)
2642 goto on_error;
2643 }
2644 }
2645 break;
2646
2626 // execute :substitute with an expression 2647 // execute :substitute with an expression
2627 case ISN_SUBSTITUTE: 2648 case ISN_SUBSTITUTE:
2628 { 2649 {
2629 subs_T *subs = &iptr->isn_arg.subs; 2650 subs_T *subs = &iptr->isn_arg.subs;
2630 source_cookie_T cookie; 2651 source_cookie_T cookie;
2900 copy_tv(sv->sv_tv, STACK_TV_BOT(0)); 2921 copy_tv(sv->sv_tv, STACK_TV_BOT(0));
2901 ++ectx->ec_stack.ga_len; 2922 ++ectx->ec_stack.ga_len;
2902 } 2923 }
2903 break; 2924 break;
2904 2925
2905 // load s: variable in old script 2926 // load s: variable in old script or autoload import
2906 case ISN_LOADS: 2927 case ISN_LOADS:
2907 { 2928 case ISN_LOADEXPORT:
2908 hashtab_T *ht = &SCRIPT_VARS( 2929 {
2909 iptr->isn_arg.loadstore.ls_sid); 2930 int sid = iptr->isn_arg.loadstore.ls_sid;
2931 hashtab_T *ht = &SCRIPT_VARS(sid);
2910 char_u *name = iptr->isn_arg.loadstore.ls_name; 2932 char_u *name = iptr->isn_arg.loadstore.ls_name;
2911 dictitem_T *di = find_var_in_ht(ht, 0, name, TRUE); 2933 dictitem_T *di = find_var_in_ht(ht, 0, name, TRUE);
2912 2934
2913 if (di == NULL) 2935 if (di == NULL)
2914 { 2936 {
2916 semsg(_(e_undefined_variable_str), name); 2938 semsg(_(e_undefined_variable_str), name);
2917 goto on_error; 2939 goto on_error;
2918 } 2940 }
2919 else 2941 else
2920 { 2942 {
2943 if (iptr->isn_type == ISN_LOADEXPORT)
2944 {
2945 int idx = get_script_item_idx(sid, name, 0,
2946 NULL, NULL);
2947 svar_T *sv;
2948
2949 if (idx >= 0)
2950 {
2951 sv = ((svar_T *)SCRIPT_ITEM(sid)
2952 ->sn_var_vals.ga_data) + idx;
2953 if (!sv->sv_export)
2954 {
2955 SOURCING_LNUM = iptr->isn_lnum;
2956 semsg(_(e_item_not_exported_in_script_str),
2957 name);
2958 goto on_error;
2959 }
2960 }
2961 }
2921 if (GA_GROW_FAILS(&ectx->ec_stack, 1)) 2962 if (GA_GROW_FAILS(&ectx->ec_stack, 1))
2922 goto theend; 2963 goto theend;
2923 copy_tv(&di->di_tv, STACK_TV_BOT(0)); 2964 copy_tv(&di->di_tv, STACK_TV_BOT(0));
2924 ++ectx->ec_stack.ga_len; 2965 ++ectx->ec_stack.ga_len;
2925 } 2966 }
3037 tv = STACK_TV_VAR(iptr->isn_arg.number); 3078 tv = STACK_TV_VAR(iptr->isn_arg.number);
3038 clear_tv(tv); 3079 clear_tv(tv);
3039 *tv = *STACK_TV_BOT(0); 3080 *tv = *STACK_TV_BOT(0);
3040 break; 3081 break;
3041 3082
3042 // store s: variable in old script 3083 // store s: variable in old script or autoload import
3043 case ISN_STORES: 3084 case ISN_STORES:
3044 { 3085 case ISN_STOREEXPORT:
3045 hashtab_T *ht = &SCRIPT_VARS( 3086 {
3046 iptr->isn_arg.loadstore.ls_sid); 3087 int sid = iptr->isn_arg.loadstore.ls_sid;
3088 hashtab_T *ht = &SCRIPT_VARS(sid);
3047 char_u *name = iptr->isn_arg.loadstore.ls_name; 3089 char_u *name = iptr->isn_arg.loadstore.ls_name;
3048 dictitem_T *di = find_var_in_ht(ht, 0, name + 2, TRUE); 3090 dictitem_T *di = find_var_in_ht(ht, 0,
3091 iptr->isn_type == ISN_STORES
3092 ? name + 2 : name, TRUE);
3049 3093
3050 --ectx->ec_stack.ga_len; 3094 --ectx->ec_stack.ga_len;
3095 SOURCING_LNUM = iptr->isn_lnum;
3051 if (di == NULL) 3096 if (di == NULL)
3097 {
3098 if (iptr->isn_type == ISN_STOREEXPORT)
3099 {
3100 semsg(_(e_undefined_variable_str), name);
3101 goto on_error;
3102 }
3052 store_var(name, STACK_TV_BOT(0)); 3103 store_var(name, STACK_TV_BOT(0));
3104 }
3053 else 3105 else
3054 { 3106 {
3055 SOURCING_LNUM = iptr->isn_lnum; 3107 if (iptr->isn_type == ISN_STOREEXPORT)
3108 {
3109 int idx = get_script_item_idx(sid, name, 0,
3110 NULL, NULL);
3111
3112 if (idx >= 0)
3113 {
3114 svar_T *sv = ((svar_T *)SCRIPT_ITEM(sid)
3115 ->sn_var_vals.ga_data) + idx;
3116
3117 if (!sv->sv_export)
3118 {
3119 semsg(_(e_item_not_exported_in_script_str),
3120 name);
3121 goto on_error;
3122 }
3123 }
3124 }
3056 if (var_check_permission(di, name) == FAIL) 3125 if (var_check_permission(di, name) == FAIL)
3057 { 3126 {
3058 clear_tv(STACK_TV_BOT(0)); 3127 clear_tv(STACK_TV_BOT(0));
3059 goto on_error; 3128 goto on_error;
3060 } 3129 }
5407 cer->cer_cmdline); 5476 cer->cer_cmdline);
5408 } 5477 }
5409 #endif 5478 #endif
5410 break; 5479 break;
5411 case ISN_INSTR: 5480 case ISN_INSTR:
5412 { 5481 smsg("%s%4d INSTR", pfx, current);
5413 smsg("%s%4d INSTR", pfx, current); 5482 list_instructions(" ", iptr->isn_arg.instr, INT_MAX, NULL);
5414 list_instructions(" ", iptr->isn_arg.instr, 5483 msg(" -------------");
5415 INT_MAX, NULL); 5484 break;
5416 msg(" -------------"); 5485 case ISN_SOURCE:
5486 {
5487 scriptitem_T *si = SCRIPT_ITEM(iptr->isn_arg.number);
5488
5489 smsg("%s%4d SOURCE %s", pfx, current, si->sn_name);
5417 } 5490 }
5418 break; 5491 break;
5419 case ISN_SUBSTITUTE: 5492 case ISN_SUBSTITUTE:
5420 { 5493 {
5421 subs_T *subs = &iptr->isn_arg.subs; 5494 subs_T *subs = &iptr->isn_arg.subs;
5498 sref->sref_idx, 5571 sref->sref_idx,
5499 si->sn_name); 5572 si->sn_name);
5500 } 5573 }
5501 break; 5574 break;
5502 case ISN_LOADS: 5575 case ISN_LOADS:
5576 case ISN_LOADEXPORT:
5503 { 5577 {
5504 scriptitem_T *si = SCRIPT_ITEM( 5578 scriptitem_T *si = SCRIPT_ITEM(
5505 iptr->isn_arg.loadstore.ls_sid); 5579 iptr->isn_arg.loadstore.ls_sid);
5506 5580
5507 smsg("%s%4d LOADS s:%s from %s", pfx, current, 5581 smsg("%s%4d %s s:%s from %s", pfx, current,
5508 iptr->isn_arg.loadstore.ls_name, si->sn_name); 5582 iptr->isn_type == ISN_LOADS ? "LOADS"
5583 : "LOADEXPORT",
5584 iptr->isn_arg.loadstore.ls_name, si->sn_name);
5509 } 5585 }
5510 break; 5586 break;
5511 case ISN_LOADAUTO: 5587 case ISN_LOADAUTO:
5512 smsg("%s%4d LOADAUTO %s", pfx, current, iptr->isn_arg.string); 5588 smsg("%s%4d LOADAUTO %s", pfx, current, iptr->isn_arg.string);
5513 break; 5589 break;
5584 break; 5660 break;
5585 case ISN_STORET: 5661 case ISN_STORET:
5586 smsg("%s%4d STORET %s", pfx, current, iptr->isn_arg.string); 5662 smsg("%s%4d STORET %s", pfx, current, iptr->isn_arg.string);
5587 break; 5663 break;
5588 case ISN_STORES: 5664 case ISN_STORES:
5665 case ISN_STOREEXPORT:
5589 { 5666 {
5590 scriptitem_T *si = SCRIPT_ITEM( 5667 scriptitem_T *si = SCRIPT_ITEM(
5591 iptr->isn_arg.loadstore.ls_sid); 5668 iptr->isn_arg.loadstore.ls_sid);
5592 5669
5593 smsg("%s%4d STORES %s in %s", pfx, current, 5670 smsg("%s%4d %s %s in %s", pfx, current,
5671 iptr->isn_type == ISN_STORES
5672 ? "STORES" : "STOREEXPORT",
5594 iptr->isn_arg.loadstore.ls_name, si->sn_name); 5673 iptr->isn_arg.loadstore.ls_name, si->sn_name);
5595 } 5674 }
5596 break; 5675 break;
5597 case ISN_STORESCRIPT: 5676 case ISN_STORESCRIPT:
5598 { 5677 {