Mercurial > vim
annotate src/vim9script.c @ 26197:2093cc976da8 v8.2.3630
patch 8.2.3630: printf() with %S does not handle multi-byte correctly
Commit: https://github.com/vim/vim/commit/d85fccdfed58108c4e0958d0b17c64690b5f073f
Author: presuku <presuku@users.noreply.github.com>
Date: Sat Nov 20 19:38:31 2021 +0000
patch 8.2.3630: printf() with %S does not handle multi-byte correctly
Problem: Printf() with %S does not handle multi-byte correctly.
Solution: Count cells instead of bytes. (closes https://github.com/vim/vim/issues/9169, closes https://github.com/vim/vim/issues/7486)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 20 Nov 2021 20:45:02 +0100 |
parents | 4003fc2340dc |
children | 7351926fbe9e |
rev | line source |
---|---|
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2 * |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3 * VIM - Vi IMproved by Bram Moolenaar |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4 * |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5 * Do ":help uganda" in Vim to read copying and usage conditions. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6 * Do ":help credits" in Vim to see a list of people who contributed. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7 * See README.txt for an overview of the Vim source code. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
8 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
9 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
10 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
11 * vim9script.c: :vim9script, :import, :export and friends |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
12 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
13 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
14 #include "vim.h" |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
15 |
23390
9a5f12b36273
patch 8.2.2238: Vim9: cannot load a Vim9 script without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
23364
diff
changeset
|
16 #if defined(FEAT_EVAL) |
9a5f12b36273
patch 8.2.2238: Vim9: cannot load a Vim9 script without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
23364
diff
changeset
|
17 # include "vim9.h" |
9a5f12b36273
patch 8.2.2238: Vim9: cannot load a Vim9 script without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
23364
diff
changeset
|
18 #endif |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
19 |
24279
e3dbf2e58c6a
patch 8.2.2680: Vim9: problem defining a script variable from legacy function
Bram Moolenaar <Bram@vim.org>
parents:
24176
diff
changeset
|
20 /* |
e3dbf2e58c6a
patch 8.2.2680: Vim9: problem defining a script variable from legacy function
Bram Moolenaar <Bram@vim.org>
parents:
24176
diff
changeset
|
21 * Return TRUE when currently using Vim9 script syntax. |
e3dbf2e58c6a
patch 8.2.2680: Vim9: problem defining a script variable from legacy function
Bram Moolenaar <Bram@vim.org>
parents:
24176
diff
changeset
|
22 * Does not go up the stack, a ":function" inside vim9script uses legacy |
e3dbf2e58c6a
patch 8.2.2680: Vim9: problem defining a script variable from legacy function
Bram Moolenaar <Bram@vim.org>
parents:
24176
diff
changeset
|
23 * syntax. |
e3dbf2e58c6a
patch 8.2.2680: Vim9: problem defining a script variable from legacy function
Bram Moolenaar <Bram@vim.org>
parents:
24176
diff
changeset
|
24 */ |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
25 int |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
26 in_vim9script(void) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
27 { |
24279
e3dbf2e58c6a
patch 8.2.2680: Vim9: problem defining a script variable from legacy function
Bram Moolenaar <Bram@vim.org>
parents:
24176
diff
changeset
|
28 // "sc_version" is also set when compiling a ":def" function in legacy |
e3dbf2e58c6a
patch 8.2.2680: Vim9: problem defining a script variable from legacy function
Bram Moolenaar <Bram@vim.org>
parents:
24176
diff
changeset
|
29 // script. |
24531
3bfec39ce31c
patch 8.2.2805: Vim9: cannot use legacy syntax in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
24469
diff
changeset
|
30 return (current_sctx.sc_version == SCRIPT_VERSION_VIM9 |
3bfec39ce31c
patch 8.2.2805: Vim9: cannot use legacy syntax in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
24469
diff
changeset
|
31 || (cmdmod.cmod_flags & CMOD_VIM9CMD)) |
3bfec39ce31c
patch 8.2.2805: Vim9: cannot use legacy syntax in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
24469
diff
changeset
|
32 && !(cmdmod.cmod_flags & CMOD_LEGACY); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
33 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
34 |
24285
28b8ede0d2b9
patch 8.2.2683: build failure without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
24283
diff
changeset
|
35 #if defined(FEAT_EVAL) || defined(PROTO) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
36 /* |
25622
15b54e0a576b
patch 8.2.3347: check for legacy script is incomplete
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
37 * Return TRUE when currently in a script with script version smaller than |
15b54e0a576b
patch 8.2.3347: check for legacy script is incomplete
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
38 * "max_version" or command modifiers forced it. |
15b54e0a576b
patch 8.2.3347: check for legacy script is incomplete
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
39 */ |
15b54e0a576b
patch 8.2.3347: check for legacy script is incomplete
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
40 int |
15b54e0a576b
patch 8.2.3347: check for legacy script is incomplete
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
41 in_old_script(int max_version) |
15b54e0a576b
patch 8.2.3347: check for legacy script is incomplete
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
42 { |
25626
4e13cde003a8
patch 8.2.3349: eval test for scriptversion fails
Bram Moolenaar <Bram@vim.org>
parents:
25622
diff
changeset
|
43 return (current_sctx.sc_version < max_version |
4e13cde003a8
patch 8.2.3349: eval test for scriptversion fails
Bram Moolenaar <Bram@vim.org>
parents:
25622
diff
changeset
|
44 && !(cmdmod.cmod_flags & CMOD_VIM9CMD)) |
25622
15b54e0a576b
patch 8.2.3347: check for legacy script is incomplete
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
45 || (cmdmod.cmod_flags & CMOD_LEGACY); |
15b54e0a576b
patch 8.2.3347: check for legacy script is incomplete
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
46 } |
15b54e0a576b
patch 8.2.3347: check for legacy script is incomplete
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
47 |
15b54e0a576b
patch 8.2.3347: check for legacy script is incomplete
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
48 /* |
24279
e3dbf2e58c6a
patch 8.2.2680: Vim9: problem defining a script variable from legacy function
Bram Moolenaar <Bram@vim.org>
parents:
24176
diff
changeset
|
49 * Return TRUE if the current script is Vim9 script. |
e3dbf2e58c6a
patch 8.2.2680: Vim9: problem defining a script variable from legacy function
Bram Moolenaar <Bram@vim.org>
parents:
24176
diff
changeset
|
50 * This also returns TRUE in a legacy function in a Vim9 script. |
e3dbf2e58c6a
patch 8.2.2680: Vim9: problem defining a script variable from legacy function
Bram Moolenaar <Bram@vim.org>
parents:
24176
diff
changeset
|
51 */ |
e3dbf2e58c6a
patch 8.2.2680: Vim9: problem defining a script variable from legacy function
Bram Moolenaar <Bram@vim.org>
parents:
24176
diff
changeset
|
52 int |
e3dbf2e58c6a
patch 8.2.2680: Vim9: problem defining a script variable from legacy function
Bram Moolenaar <Bram@vim.org>
parents:
24176
diff
changeset
|
53 current_script_is_vim9(void) |
e3dbf2e58c6a
patch 8.2.2680: Vim9: problem defining a script variable from legacy function
Bram Moolenaar <Bram@vim.org>
parents:
24176
diff
changeset
|
54 { |
e3dbf2e58c6a
patch 8.2.2680: Vim9: problem defining a script variable from legacy function
Bram Moolenaar <Bram@vim.org>
parents:
24176
diff
changeset
|
55 return SCRIPT_ID_VALID(current_sctx.sc_sid) |
e3dbf2e58c6a
patch 8.2.2680: Vim9: problem defining a script variable from legacy function
Bram Moolenaar <Bram@vim.org>
parents:
24176
diff
changeset
|
56 && SCRIPT_ITEM(current_sctx.sc_sid)->sn_version |
e3dbf2e58c6a
patch 8.2.2680: Vim9: problem defining a script variable from legacy function
Bram Moolenaar <Bram@vim.org>
parents:
24176
diff
changeset
|
57 == SCRIPT_VERSION_VIM9; |
e3dbf2e58c6a
patch 8.2.2680: Vim9: problem defining a script variable from legacy function
Bram Moolenaar <Bram@vim.org>
parents:
24176
diff
changeset
|
58 } |
24285
28b8ede0d2b9
patch 8.2.2683: build failure without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
24283
diff
changeset
|
59 #endif |
24279
e3dbf2e58c6a
patch 8.2.2680: Vim9: problem defining a script variable from legacy function
Bram Moolenaar <Bram@vim.org>
parents:
24176
diff
changeset
|
60 |
e3dbf2e58c6a
patch 8.2.2680: Vim9: problem defining a script variable from legacy function
Bram Moolenaar <Bram@vim.org>
parents:
24176
diff
changeset
|
61 /* |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
62 * ":vim9script". |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
63 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
64 void |
23390
9a5f12b36273
patch 8.2.2238: Vim9: cannot load a Vim9 script without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
23364
diff
changeset
|
65 ex_vim9script(exarg_T *eap UNUSED) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
66 { |
23390
9a5f12b36273
patch 8.2.2238: Vim9: cannot load a Vim9 script without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
23364
diff
changeset
|
67 #ifdef FEAT_EVAL |
23358
b3142fc0a414
patch 8.2.2222: Vim9: cannot keep script variables when reloading
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
68 int sid = current_sctx.sc_sid; |
20881
58137dbee8da
patch 8.2.0992: Vim9: crash when using :import in the Vim command
Bram Moolenaar <Bram@vim.org>
parents:
20846
diff
changeset
|
69 scriptitem_T *si; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
70 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
71 if (!getline_equal(eap->getline, eap->cookie, getsourceline)) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
72 { |
21821
0deb6f96a5a3
patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
73 emsg(_(e_vim9script_can_only_be_used_in_script)); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
74 return; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
75 } |
23358
b3142fc0a414
patch 8.2.2222: Vim9: cannot keep script variables when reloading
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
76 |
b3142fc0a414
patch 8.2.2222: Vim9: cannot keep script variables when reloading
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
77 si = SCRIPT_ITEM(sid); |
b3142fc0a414
patch 8.2.2222: Vim9: cannot keep script variables when reloading
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
78 if (si->sn_state == SN_STATE_HAD_COMMAND) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
79 { |
21821
0deb6f96a5a3
patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
80 emsg(_(e_vim9script_must_be_first_command_in_script)); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
81 return; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
82 } |
23358
b3142fc0a414
patch 8.2.2222: Vim9: cannot keep script variables when reloading
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
83 if (!IS_WHITE_OR_NUL(*eap->arg) && STRCMP(eap->arg, "noclear") != 0) |
b3142fc0a414
patch 8.2.2222: Vim9: cannot keep script variables when reloading
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
84 { |
b3142fc0a414
patch 8.2.2222: Vim9: cannot keep script variables when reloading
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
85 semsg(_(e_invarg2), eap->arg); |
b3142fc0a414
patch 8.2.2222: Vim9: cannot keep script variables when reloading
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
86 return; |
b3142fc0a414
patch 8.2.2222: Vim9: cannot keep script variables when reloading
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
87 } |
b3142fc0a414
patch 8.2.2222: Vim9: cannot keep script variables when reloading
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
88 if (si->sn_state == SN_STATE_RELOAD && IS_WHITE_OR_NUL(*eap->arg)) |
b3142fc0a414
patch 8.2.2222: Vim9: cannot keep script variables when reloading
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
89 { |
b3142fc0a414
patch 8.2.2222: Vim9: cannot keep script variables when reloading
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
90 hashtab_T *ht = &SCRIPT_VARS(sid); |
b3142fc0a414
patch 8.2.2222: Vim9: cannot keep script variables when reloading
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
91 |
b3142fc0a414
patch 8.2.2222: Vim9: cannot keep script variables when reloading
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
92 // Reloading a script without the "noclear" argument: clear |
b3142fc0a414
patch 8.2.2222: Vim9: cannot keep script variables when reloading
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
93 // script-local variables and functions. |
b3142fc0a414
patch 8.2.2222: Vim9: cannot keep script variables when reloading
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
94 hashtab_free_contents(ht); |
b3142fc0a414
patch 8.2.2222: Vim9: cannot keep script variables when reloading
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
95 hash_init(ht); |
b3142fc0a414
patch 8.2.2222: Vim9: cannot keep script variables when reloading
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
96 delete_script_functions(sid); |
b3142fc0a414
patch 8.2.2222: Vim9: cannot keep script variables when reloading
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
97 |
b3142fc0a414
patch 8.2.2222: Vim9: cannot keep script variables when reloading
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
98 // old imports and script variables are no longer valid |
b3142fc0a414
patch 8.2.2222: Vim9: cannot keep script variables when reloading
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
99 free_imports_and_script_vars(sid); |
b3142fc0a414
patch 8.2.2222: Vim9: cannot keep script variables when reloading
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
100 } |
b3142fc0a414
patch 8.2.2222: Vim9: cannot keep script variables when reloading
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
101 si->sn_state = SN_STATE_HAD_COMMAND; |
b3142fc0a414
patch 8.2.2222: Vim9: cannot keep script variables when reloading
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
102 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
103 current_sctx.sc_version = SCRIPT_VERSION_VIM9; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
104 si->sn_version = SCRIPT_VERSION_VIM9; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
105 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
106 if (STRCMP(p_cpo, CPO_VIM) != 0) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
107 { |
22643
71b57779177d
patch 8.2.1870: Vim9: no need to keep all script variables
Bram Moolenaar <Bram@vim.org>
parents:
22596
diff
changeset
|
108 si->sn_save_cpo = vim_strsave(p_cpo); |
24079
a9ff8368d35f
patch 8.2.2581: Vim9: sourcing Vim9 script triggers a redraw
Bram Moolenaar <Bram@vim.org>
parents:
24049
diff
changeset
|
109 set_option_value((char_u *)"cpo", 0L, (char_u *)CPO_VIM, OPT_NO_REDRAW); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
110 } |
23390
9a5f12b36273
patch 8.2.2238: Vim9: cannot load a Vim9 script without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
23364
diff
changeset
|
111 #else |
9a5f12b36273
patch 8.2.2238: Vim9: cannot load a Vim9 script without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
23364
diff
changeset
|
112 // No check for this being the first command, it doesn't matter. |
9a5f12b36273
patch 8.2.2238: Vim9: cannot load a Vim9 script without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
23364
diff
changeset
|
113 current_sctx.sc_version = SCRIPT_VERSION_VIM9; |
9a5f12b36273
patch 8.2.2238: Vim9: cannot load a Vim9 script without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
23364
diff
changeset
|
114 #endif |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
115 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
116 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
117 /* |
21516
c7b2ce90c2de
patch 8.2.1308: Vim9: accidentally using "x" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents:
21473
diff
changeset
|
118 * When in Vim9 script give an error and return FAIL. |
c7b2ce90c2de
patch 8.2.1308: Vim9: accidentally using "x" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents:
21473
diff
changeset
|
119 */ |
c7b2ce90c2de
patch 8.2.1308: Vim9: accidentally using "x" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents:
21473
diff
changeset
|
120 int |
c7b2ce90c2de
patch 8.2.1308: Vim9: accidentally using "x" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents:
21473
diff
changeset
|
121 not_in_vim9(exarg_T *eap) |
c7b2ce90c2de
patch 8.2.1308: Vim9: accidentally using "x" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents:
21473
diff
changeset
|
122 { |
21522
e17d0b882194
patch 8.2.1311: test failures with legacy Vim script
Bram Moolenaar <Bram@vim.org>
parents:
21516
diff
changeset
|
123 if (in_vim9script()) |
e17d0b882194
patch 8.2.1311: test failures with legacy Vim script
Bram Moolenaar <Bram@vim.org>
parents:
21516
diff
changeset
|
124 switch (eap->cmdidx) |
e17d0b882194
patch 8.2.1311: test failures with legacy Vim script
Bram Moolenaar <Bram@vim.org>
parents:
21516
diff
changeset
|
125 { |
23980
bee8c78c0c6a
patch 8.2.2532: Vim9: confusing error if :k is used with a range
Bram Moolenaar <Bram@vim.org>
parents:
23978
diff
changeset
|
126 case CMD_k: |
bee8c78c0c6a
patch 8.2.2532: Vim9: confusing error if :k is used with a range
Bram Moolenaar <Bram@vim.org>
parents:
23978
diff
changeset
|
127 if (eap->addr_count > 0) |
bee8c78c0c6a
patch 8.2.2532: Vim9: confusing error if :k is used with a range
Bram Moolenaar <Bram@vim.org>
parents:
23978
diff
changeset
|
128 { |
bee8c78c0c6a
patch 8.2.2532: Vim9: confusing error if :k is used with a range
Bram Moolenaar <Bram@vim.org>
parents:
23978
diff
changeset
|
129 emsg(_(e_norange)); |
bee8c78c0c6a
patch 8.2.2532: Vim9: confusing error if :k is used with a range
Bram Moolenaar <Bram@vim.org>
parents:
23978
diff
changeset
|
130 return FAIL; |
bee8c78c0c6a
patch 8.2.2532: Vim9: confusing error if :k is used with a range
Bram Moolenaar <Bram@vim.org>
parents:
23978
diff
changeset
|
131 } |
bee8c78c0c6a
patch 8.2.2532: Vim9: confusing error if :k is used with a range
Bram Moolenaar <Bram@vim.org>
parents:
23978
diff
changeset
|
132 // FALLTHROUGH |
21522
e17d0b882194
patch 8.2.1311: test failures with legacy Vim script
Bram Moolenaar <Bram@vim.org>
parents:
21516
diff
changeset
|
133 case CMD_append: |
e17d0b882194
patch 8.2.1311: test failures with legacy Vim script
Bram Moolenaar <Bram@vim.org>
parents:
21516
diff
changeset
|
134 case CMD_change: |
21584
d0c76ce48326
patch 8.2.1342: Vim9: accidentally using "t" gives a confusing error
Bram Moolenaar <Bram@vim.org>
parents:
21522
diff
changeset
|
135 case CMD_insert: |
24114
291c57cf4731
patch 8.2.2598: Vim9: :open does not need to be supported
Bram Moolenaar <Bram@vim.org>
parents:
24112
diff
changeset
|
136 case CMD_open: |
21584
d0c76ce48326
patch 8.2.1342: Vim9: accidentally using "t" gives a confusing error
Bram Moolenaar <Bram@vim.org>
parents:
21522
diff
changeset
|
137 case CMD_t: |
21522
e17d0b882194
patch 8.2.1311: test failures with legacy Vim script
Bram Moolenaar <Bram@vim.org>
parents:
21516
diff
changeset
|
138 case CMD_xit: |
23390
9a5f12b36273
patch 8.2.2238: Vim9: cannot load a Vim9 script without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
23364
diff
changeset
|
139 semsg(_(e_command_not_supported_in_vim9_script_missing_var_str), eap->cmd); |
21522
e17d0b882194
patch 8.2.1311: test failures with legacy Vim script
Bram Moolenaar <Bram@vim.org>
parents:
21516
diff
changeset
|
140 return FAIL; |
e17d0b882194
patch 8.2.1311: test failures with legacy Vim script
Bram Moolenaar <Bram@vim.org>
parents:
21516
diff
changeset
|
141 default: break; |
e17d0b882194
patch 8.2.1311: test failures with legacy Vim script
Bram Moolenaar <Bram@vim.org>
parents:
21516
diff
changeset
|
142 } |
21516
c7b2ce90c2de
patch 8.2.1308: Vim9: accidentally using "x" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents:
21473
diff
changeset
|
143 return OK; |
c7b2ce90c2de
patch 8.2.1308: Vim9: accidentally using "x" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents:
21473
diff
changeset
|
144 } |
c7b2ce90c2de
patch 8.2.1308: Vim9: accidentally using "x" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents:
21473
diff
changeset
|
145 |
23392
517fca70e084
patch 8.2.2239: Vim9: concatenating lines with backslash is inconvenient
Bram Moolenaar <Bram@vim.org>
parents:
23390
diff
changeset
|
146 /* |
24158
93e69703a290
patch 8.2.2620: Vim9: Using #{ for a dictionary gives strange errors
Bram Moolenaar <Bram@vim.org>
parents:
24114
diff
changeset
|
147 * Give an error message if "p" points at "#{" and return TRUE. |
93e69703a290
patch 8.2.2620: Vim9: Using #{ for a dictionary gives strange errors
Bram Moolenaar <Bram@vim.org>
parents:
24114
diff
changeset
|
148 * This avoids that using a legacy style #{} dictionary leads to difficult to |
93e69703a290
patch 8.2.2620: Vim9: Using #{ for a dictionary gives strange errors
Bram Moolenaar <Bram@vim.org>
parents:
24114
diff
changeset
|
149 * understand errors. |
93e69703a290
patch 8.2.2620: Vim9: Using #{ for a dictionary gives strange errors
Bram Moolenaar <Bram@vim.org>
parents:
24114
diff
changeset
|
150 */ |
93e69703a290
patch 8.2.2620: Vim9: Using #{ for a dictionary gives strange errors
Bram Moolenaar <Bram@vim.org>
parents:
24114
diff
changeset
|
151 int |
93e69703a290
patch 8.2.2620: Vim9: Using #{ for a dictionary gives strange errors
Bram Moolenaar <Bram@vim.org>
parents:
24114
diff
changeset
|
152 vim9_bad_comment(char_u *p) |
93e69703a290
patch 8.2.2620: Vim9: Using #{ for a dictionary gives strange errors
Bram Moolenaar <Bram@vim.org>
parents:
24114
diff
changeset
|
153 { |
24176
12378fbc99bc
patch 8.2.2629: Vim9: error for #{{ is not desired
Bram Moolenaar <Bram@vim.org>
parents:
24160
diff
changeset
|
154 if (p[0] == '#' && p[1] == '{' && p[2] != '{') |
24158
93e69703a290
patch 8.2.2620: Vim9: Using #{ for a dictionary gives strange errors
Bram Moolenaar <Bram@vim.org>
parents:
24114
diff
changeset
|
155 { |
93e69703a290
patch 8.2.2620: Vim9: Using #{ for a dictionary gives strange errors
Bram Moolenaar <Bram@vim.org>
parents:
24114
diff
changeset
|
156 emsg(_(e_cannot_use_hash_curly_to_start_comment)); |
93e69703a290
patch 8.2.2620: Vim9: Using #{ for a dictionary gives strange errors
Bram Moolenaar <Bram@vim.org>
parents:
24114
diff
changeset
|
157 return TRUE; |
93e69703a290
patch 8.2.2620: Vim9: Using #{ for a dictionary gives strange errors
Bram Moolenaar <Bram@vim.org>
parents:
24114
diff
changeset
|
158 } |
93e69703a290
patch 8.2.2620: Vim9: Using #{ for a dictionary gives strange errors
Bram Moolenaar <Bram@vim.org>
parents:
24114
diff
changeset
|
159 return FALSE; |
93e69703a290
patch 8.2.2620: Vim9: Using #{ for a dictionary gives strange errors
Bram Moolenaar <Bram@vim.org>
parents:
24114
diff
changeset
|
160 } |
93e69703a290
patch 8.2.2620: Vim9: Using #{ for a dictionary gives strange errors
Bram Moolenaar <Bram@vim.org>
parents:
24114
diff
changeset
|
161 |
93e69703a290
patch 8.2.2620: Vim9: Using #{ for a dictionary gives strange errors
Bram Moolenaar <Bram@vim.org>
parents:
24114
diff
changeset
|
162 /* |
24176
12378fbc99bc
patch 8.2.2629: Vim9: error for #{{ is not desired
Bram Moolenaar <Bram@vim.org>
parents:
24160
diff
changeset
|
163 * Return TRUE if "p" points at a "#" not followed by one '{'. |
24158
93e69703a290
patch 8.2.2620: Vim9: Using #{ for a dictionary gives strange errors
Bram Moolenaar <Bram@vim.org>
parents:
24114
diff
changeset
|
164 * Does not check for white space. |
23392
517fca70e084
patch 8.2.2239: Vim9: concatenating lines with backslash is inconvenient
Bram Moolenaar <Bram@vim.org>
parents:
23390
diff
changeset
|
165 */ |
517fca70e084
patch 8.2.2239: Vim9: concatenating lines with backslash is inconvenient
Bram Moolenaar <Bram@vim.org>
parents:
23390
diff
changeset
|
166 int |
517fca70e084
patch 8.2.2239: Vim9: concatenating lines with backslash is inconvenient
Bram Moolenaar <Bram@vim.org>
parents:
23390
diff
changeset
|
167 vim9_comment_start(char_u *p) |
517fca70e084
patch 8.2.2239: Vim9: concatenating lines with backslash is inconvenient
Bram Moolenaar <Bram@vim.org>
parents:
23390
diff
changeset
|
168 { |
24176
12378fbc99bc
patch 8.2.2629: Vim9: error for #{{ is not desired
Bram Moolenaar <Bram@vim.org>
parents:
24160
diff
changeset
|
169 return p[0] == '#' && (p[1] != '{' || p[2] == '{'); |
23392
517fca70e084
patch 8.2.2239: Vim9: concatenating lines with backslash is inconvenient
Bram Moolenaar <Bram@vim.org>
parents:
23390
diff
changeset
|
170 } |
517fca70e084
patch 8.2.2239: Vim9: concatenating lines with backslash is inconvenient
Bram Moolenaar <Bram@vim.org>
parents:
23390
diff
changeset
|
171 |
23390
9a5f12b36273
patch 8.2.2238: Vim9: cannot load a Vim9 script without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
23364
diff
changeset
|
172 #if defined(FEAT_EVAL) || defined(PROTO) |
9a5f12b36273
patch 8.2.2238: Vim9: cannot load a Vim9 script without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
23364
diff
changeset
|
173 |
21516
c7b2ce90c2de
patch 8.2.1308: Vim9: accidentally using "x" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents:
21473
diff
changeset
|
174 /* |
24533
9c404d78d767
patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents:
24531
diff
changeset
|
175 * "++nr" and "--nr" commands. |
9c404d78d767
patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents:
24531
diff
changeset
|
176 */ |
9c404d78d767
patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents:
24531
diff
changeset
|
177 void |
9c404d78d767
patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents:
24531
diff
changeset
|
178 ex_incdec(exarg_T *eap) |
9c404d78d767
patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents:
24531
diff
changeset
|
179 { |
9c404d78d767
patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents:
24531
diff
changeset
|
180 char_u *cmd = eap->cmd; |
25020
91f396f149d5
patch 8.2.3047: increment and decrement don't allow for next command
Bram Moolenaar <Bram@vim.org>
parents:
24888
diff
changeset
|
181 char_u *nextcmd = eap->nextcmd; |
91f396f149d5
patch 8.2.3047: increment and decrement don't allow for next command
Bram Moolenaar <Bram@vim.org>
parents:
24888
diff
changeset
|
182 size_t len = STRLEN(eap->cmd) + 8; |
24533
9c404d78d767
patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents:
24531
diff
changeset
|
183 |
25022
39551b6e0112
patch 8.2.3048: strange error for white space after ++ command
Bram Moolenaar <Bram@vim.org>
parents:
25020
diff
changeset
|
184 if (VIM_ISWHITE(cmd[2])) |
39551b6e0112
patch 8.2.3048: strange error for white space after ++ command
Bram Moolenaar <Bram@vim.org>
parents:
25020
diff
changeset
|
185 { |
39551b6e0112
patch 8.2.3048: strange error for white space after ++ command
Bram Moolenaar <Bram@vim.org>
parents:
25020
diff
changeset
|
186 semsg(_(e_no_white_space_allowed_after_str_str), |
39551b6e0112
patch 8.2.3048: strange error for white space after ++ command
Bram Moolenaar <Bram@vim.org>
parents:
25020
diff
changeset
|
187 eap->cmdidx == CMD_increment ? "++" : "--", eap->cmd); |
39551b6e0112
patch 8.2.3048: strange error for white space after ++ command
Bram Moolenaar <Bram@vim.org>
parents:
25020
diff
changeset
|
188 return; |
39551b6e0112
patch 8.2.3048: strange error for white space after ++ command
Bram Moolenaar <Bram@vim.org>
parents:
25020
diff
changeset
|
189 } |
39551b6e0112
patch 8.2.3048: strange error for white space after ++ command
Bram Moolenaar <Bram@vim.org>
parents:
25020
diff
changeset
|
190 |
24533
9c404d78d767
patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents:
24531
diff
changeset
|
191 // This works like "nr += 1" or "nr -= 1". |
25020
91f396f149d5
patch 8.2.3047: increment and decrement don't allow for next command
Bram Moolenaar <Bram@vim.org>
parents:
24888
diff
changeset
|
192 // Add a '|' to avoid looking in the next line. |
24533
9c404d78d767
patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents:
24531
diff
changeset
|
193 eap->cmd = alloc(len); |
9c404d78d767
patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents:
24531
diff
changeset
|
194 if (eap->cmd == NULL) |
9c404d78d767
patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents:
24531
diff
changeset
|
195 return; |
25020
91f396f149d5
patch 8.2.3047: increment and decrement don't allow for next command
Bram Moolenaar <Bram@vim.org>
parents:
24888
diff
changeset
|
196 vim_snprintf((char *)eap->cmd, len, "%s %c= 1 |", cmd + 2, |
24533
9c404d78d767
patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents:
24531
diff
changeset
|
197 eap->cmdidx == CMD_increment ? '+' : '-'); |
9c404d78d767
patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents:
24531
diff
changeset
|
198 eap->arg = eap->cmd; |
9c404d78d767
patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents:
24531
diff
changeset
|
199 eap->cmdidx = CMD_var; |
25020
91f396f149d5
patch 8.2.3047: increment and decrement don't allow for next command
Bram Moolenaar <Bram@vim.org>
parents:
24888
diff
changeset
|
200 eap->nextcmd = NULL; |
24533
9c404d78d767
patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents:
24531
diff
changeset
|
201 ex_let(eap); |
9c404d78d767
patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents:
24531
diff
changeset
|
202 vim_free(eap->cmd); |
9c404d78d767
patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents:
24531
diff
changeset
|
203 eap->cmd = cmd; |
25020
91f396f149d5
patch 8.2.3047: increment and decrement don't allow for next command
Bram Moolenaar <Bram@vim.org>
parents:
24888
diff
changeset
|
204 eap->nextcmd = nextcmd; |
24533
9c404d78d767
patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents:
24531
diff
changeset
|
205 } |
9c404d78d767
patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents:
24531
diff
changeset
|
206 |
9c404d78d767
patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents:
24531
diff
changeset
|
207 /* |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
208 * ":export let Name: type" |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
209 * ":export const Name: type" |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
210 * ":export def Name(..." |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
211 * ":export class Name ..." |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
212 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
213 void |
20339
7587d892c00c
patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20189
diff
changeset
|
214 ex_export(exarg_T *eap) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
215 { |
21279
8d1d11afd8c8
patch 8.2.1190: Vim9: checking for Vim9 syntax is spread out
Bram Moolenaar <Bram@vim.org>
parents:
21218
diff
changeset
|
216 if (!in_vim9script()) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
217 { |
21821
0deb6f96a5a3
patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
218 emsg(_(e_export_can_only_be_used_in_vim9script)); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
219 return; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
220 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
221 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
222 eap->cmd = eap->arg; |
24049
fc4c2beea99a
patch 8.2.2566: Vim9: Function name is not recognized
Bram Moolenaar <Bram@vim.org>
parents:
24033
diff
changeset
|
223 (void)find_ex_command(eap, NULL, lookup_scriptitem, NULL); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
224 switch (eap->cmdidx) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
225 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
226 case CMD_let: |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22250
diff
changeset
|
227 case CMD_var: |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22250
diff
changeset
|
228 case CMD_final: |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
229 case CMD_const: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
230 case CMD_def: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
231 // case CMD_class: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
232 is_export = TRUE; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
233 do_cmdline(eap->cmd, eap->getline, eap->cookie, |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
234 DOCMD_VERBOSE + DOCMD_NOWAIT); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
235 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
236 // The command will reset "is_export" when exporting an item. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
237 if (is_export) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
238 { |
21821
0deb6f96a5a3
patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
239 emsg(_(e_export_with_invalid_argument)); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
240 is_export = FALSE; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
241 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
242 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
243 default: |
21821
0deb6f96a5a3
patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
244 emsg(_(e_invalid_command_after_export)); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
245 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
246 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
247 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
248 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
249 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
250 * Add a new imported item entry to the current script. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
251 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
252 static imported_T * |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
253 new_imported(garray_T *gap) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
254 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
255 if (ga_grow(gap, 1) == OK) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
256 return ((imported_T *)gap->ga_data + gap->ga_len++); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
257 return NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
258 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
259 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
260 /* |
25567
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
261 * Free the script variables from "sn_all_vars". |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
262 */ |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
263 static void |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
264 free_all_script_vars(scriptitem_T *si) |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
265 { |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
266 int todo; |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
267 hashtab_T *ht = &si->sn_all_vars.dv_hashtab; |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
268 hashitem_T *hi; |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
269 sallvar_T *sav; |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
270 sallvar_T *sav_next; |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
271 |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
272 hash_lock(ht); |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
273 todo = (int)ht->ht_used; |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
274 for (hi = ht->ht_array; todo > 0; ++hi) |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
275 { |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
276 if (!HASHITEM_EMPTY(hi)) |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
277 { |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
278 --todo; |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
279 |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
280 // Free the variable. Don't remove it from the hashtab, ht_array |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
281 // might change then. hash_clear() takes care of it later. |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
282 sav = HI2SAV(hi); |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
283 while (sav != NULL) |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
284 { |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
285 sav_next = sav->sav_next; |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
286 if (sav->sav_di == NULL) |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
287 clear_tv(&sav->sav_tv); |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
288 vim_free(sav); |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
289 sav = sav_next; |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
290 } |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
291 } |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
292 } |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
293 hash_clear(ht); |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
294 hash_init(ht); |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
295 |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
296 ga_clear(&si->sn_var_vals); |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
297 |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
298 // existing commands using script variable indexes are no longer valid |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
299 si->sn_script_seq = current_sctx.sc_seq; |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
300 } |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
301 |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
302 /* |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
303 * Free all imported items in script "sid". |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
304 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
305 void |
22594
209c7aa56325
patch 8.2.1845: Vim9: function defined in a block can't use block variables
Bram Moolenaar <Bram@vim.org>
parents:
22529
diff
changeset
|
306 free_imports_and_script_vars(int sid) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
307 { |
19191
133ef7ba4e4e
patch 8.2.0154: reallocating the list of scripts is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
308 scriptitem_T *si = SCRIPT_ITEM(sid); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
309 int idx; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
310 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
311 for (idx = 0; idx < si->sn_imports.ga_len; ++idx) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
312 { |
19726
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
313 imported_T *imp = ((imported_T *)si->sn_imports.ga_data) + idx; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
314 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
315 vim_free(imp->imp_name); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
316 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
317 ga_clear(&si->sn_imports); |
22594
209c7aa56325
patch 8.2.1845: Vim9: function defined in a block can't use block variables
Bram Moolenaar <Bram@vim.org>
parents:
22529
diff
changeset
|
318 |
209c7aa56325
patch 8.2.1845: Vim9: function defined in a block can't use block variables
Bram Moolenaar <Bram@vim.org>
parents:
22529
diff
changeset
|
319 free_all_script_vars(si); |
209c7aa56325
patch 8.2.1845: Vim9: function defined in a block can't use block variables
Bram Moolenaar <Bram@vim.org>
parents:
22529
diff
changeset
|
320 |
21218
1f4d0375f947
patch 8.2.1160: Vim9: memory leak in allocated types
Bram Moolenaar <Bram@vim.org>
parents:
21194
diff
changeset
|
321 clear_type_list(&si->sn_type_list); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
322 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
323 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
324 /* |
23364
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
325 * Mark all imports as possible to redefine. Used when a script is loaded |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
326 * again but not cleared. |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
327 */ |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
328 void |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
329 mark_imports_for_reload(int sid) |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
330 { |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
331 scriptitem_T *si = SCRIPT_ITEM(sid); |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
332 int idx; |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
333 |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
334 for (idx = 0; idx < si->sn_imports.ga_len; ++idx) |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
335 { |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
336 imported_T *imp = ((imported_T *)si->sn_imports.ga_data) + idx; |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
337 |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
338 imp->imp_flags |= IMP_FLAGS_RELOAD; |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
339 } |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
340 } |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
341 |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
342 /* |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
343 * Handle an ":import" command and add the resulting imported_T to "gap", when |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
344 * not NULL, or script "import_sid" sn_imports. |
22596
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22594
diff
changeset
|
345 * "cctx" is NULL at the script level. |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
346 * Returns a pointer to after the command or NULL in case of failure |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
347 */ |
25567
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
348 static char_u * |
21146
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
349 handle_import( |
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
350 char_u *arg_start, |
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
351 garray_T *gap, |
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
352 int import_sid, |
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
353 evalarg_T *evalarg, |
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
354 void *cctx) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
355 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
356 char_u *arg = arg_start; |
21146
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
357 char_u *cmd_end = NULL; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
358 int ret = FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
359 typval_T tv; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
360 int sid = -1; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
361 int res; |
24029
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
362 int mult = FALSE; |
21146
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
363 garray_T names; |
24029
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
364 garray_T as_names; |
25423
3e56078569ca
patch 8.2.3248: Vim9: error message for wrong input uses wrong line number
Bram Moolenaar <Bram@vim.org>
parents:
25358
diff
changeset
|
365 long start_lnum = SOURCING_LNUM; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
366 |
25282
9bce044c7643
patch 8.2.3178: Vim9: the file name of an :import cannot be an expression
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
367 tv.v_type = VAR_UNKNOWN; |
21146
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
368 ga_init2(&names, sizeof(char_u *), 10); |
24029
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
369 ga_init2(&as_names, sizeof(char_u *), 10); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
370 if (*arg == '{') |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
371 { |
21146
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
372 // "import {item, item} from ..." |
24029
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
373 mult = TRUE; |
21146
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
374 arg = skipwhite_and_linebreak(arg + 1, evalarg); |
24029
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
375 } |
21146
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
376 |
24029
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
377 for (;;) |
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
378 { |
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
379 char_u *p = arg; |
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
380 int had_comma = FALSE; |
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
381 char_u *as_name = NULL; |
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
382 |
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
383 // accept "*" or "Name" |
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
384 if (!mult && arg[0] == '*' && IS_WHITE_OR_NUL(arg[1])) |
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
385 ++arg; |
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
386 else |
21146
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
387 while (eval_isnamec(*arg)) |
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
388 ++arg; |
24029
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
389 if (p == arg) |
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
390 break; |
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
391 if (ga_grow(&names, 1) == FAIL || ga_grow(&as_names, 1) == FAIL) |
21146
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
392 goto erret; |
24029
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
393 ((char_u **)names.ga_data)[names.ga_len] = vim_strnsave(p, arg - p); |
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
394 ++names.ga_len; |
21146
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
395 |
24029
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
396 arg = skipwhite_and_linebreak(arg, evalarg); |
21146
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
397 if (STRNCMP("as", arg, 2) == 0 && IS_WHITE_OR_NUL(arg[2])) |
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
398 { |
25755
33ebec729787
patch 8.2.3413: Vim9: too many characters are allowed in import name
Bram Moolenaar <Bram@vim.org>
parents:
25626
diff
changeset
|
399 // Skip over "as Name "; no line break allowed after "as". |
33ebec729787
patch 8.2.3413: Vim9: too many characters are allowed in import name
Bram Moolenaar <Bram@vim.org>
parents:
25626
diff
changeset
|
400 // Do not allow for ':' and '#'. |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
401 arg = skipwhite(arg + 2); |
21146
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
402 p = arg; |
19511
7e76d5fba19f
patch 8.2.0313: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents:
19509
diff
changeset
|
403 if (eval_isnamec1(*arg)) |
25755
33ebec729787
patch 8.2.3413: Vim9: too many characters are allowed in import name
Bram Moolenaar <Bram@vim.org>
parents:
25626
diff
changeset
|
404 while (ASCII_ISALNUM(*arg) || *arg == '_') |
19511
7e76d5fba19f
patch 8.2.0313: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents:
19509
diff
changeset
|
405 ++arg; |
25755
33ebec729787
patch 8.2.3413: Vim9: too many characters are allowed in import name
Bram Moolenaar <Bram@vim.org>
parents:
25626
diff
changeset
|
406 if (p == arg || !(IS_WHITE_OR_NUL(*arg) |
33ebec729787
patch 8.2.3413: Vim9: too many characters are allowed in import name
Bram Moolenaar <Bram@vim.org>
parents:
25626
diff
changeset
|
407 || (mult && (*arg == ',' || *arg == '}')))) |
33ebec729787
patch 8.2.3413: Vim9: too many characters are allowed in import name
Bram Moolenaar <Bram@vim.org>
parents:
25626
diff
changeset
|
408 { |
33ebec729787
patch 8.2.3413: Vim9: too many characters are allowed in import name
Bram Moolenaar <Bram@vim.org>
parents:
25626
diff
changeset
|
409 semsg(_(e_syntax_error_in_import_str), p); |
33ebec729787
patch 8.2.3413: Vim9: too many characters are allowed in import name
Bram Moolenaar <Bram@vim.org>
parents:
25626
diff
changeset
|
410 goto erret; |
33ebec729787
patch 8.2.3413: Vim9: too many characters are allowed in import name
Bram Moolenaar <Bram@vim.org>
parents:
25626
diff
changeset
|
411 } |
24033
308d29307910
patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents:
24031
diff
changeset
|
412 if (check_defined(p, arg - p, cctx, FALSE) == FAIL) |
21146
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
413 goto erret; |
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
414 as_name = vim_strnsave(p, arg - p); |
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
415 arg = skipwhite_and_linebreak(arg, evalarg); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
416 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
417 else if (*arg_start == '*') |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
418 { |
21821
0deb6f96a5a3
patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
419 emsg(_(e_missing_as_after_star)); |
21146
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
420 goto erret; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
421 } |
24029
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
422 // without "as Name" the as_names entry is NULL |
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
423 ((char_u **)as_names.ga_data)[as_names.ga_len] = as_name; |
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
424 ++as_names.ga_len; |
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
425 |
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
426 if (!mult) |
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
427 break; |
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
428 if (*arg == ',') |
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
429 { |
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
430 had_comma = TRUE; |
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
431 ++arg; |
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
432 } |
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
433 arg = skipwhite_and_linebreak(arg, evalarg); |
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
434 if (*arg == '}') |
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
435 { |
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
436 ++arg; |
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
437 break; |
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
438 } |
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
439 if (!had_comma) |
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
440 { |
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
441 emsg(_(e_missing_comma_in_import)); |
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
442 goto erret; |
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
443 } |
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
444 } |
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
445 arg = skipwhite_and_linebreak(arg, evalarg); |
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
446 |
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
447 if (names.ga_len == 0) |
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
448 { |
25755
33ebec729787
patch 8.2.3413: Vim9: too many characters are allowed in import name
Bram Moolenaar <Bram@vim.org>
parents:
25626
diff
changeset
|
449 semsg(_(e_syntax_error_in_import_str), arg_start); |
24029
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
450 goto erret; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
451 } |
21146
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
452 |
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
453 if (STRNCMP("from", arg, 4) != 0 || !IS_WHITE_OR_NUL(arg[4])) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
454 { |
21821
0deb6f96a5a3
patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
455 emsg(_(e_missing_from)); |
21146
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
456 goto erret; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
457 } |
21146
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
458 |
25282
9bce044c7643
patch 8.2.3178: Vim9: the file name of an :import cannot be an expression
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
459 // The name of the file can be an expression, which must evaluate to a |
9bce044c7643
patch 8.2.3178: Vim9: the file name of an :import cannot be an expression
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
460 // string. |
21148
667192c5938b
patch 8.2.1125: Vim9: double quote can be a string or a comment
Bram Moolenaar <Bram@vim.org>
parents:
21146
diff
changeset
|
461 arg = skipwhite_and_linebreak(arg + 4, evalarg); |
25282
9bce044c7643
patch 8.2.3178: Vim9: the file name of an :import cannot be an expression
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
462 ret = eval0(arg, &tv, NULL, evalarg); |
9bce044c7643
patch 8.2.3178: Vim9: the file name of an :import cannot be an expression
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
463 if (ret == FAIL) |
9bce044c7643
patch 8.2.3178: Vim9: the file name of an :import cannot be an expression
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
464 goto erret; |
9bce044c7643
patch 8.2.3178: Vim9: the file name of an :import cannot be an expression
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
465 if (tv.v_type != VAR_STRING |
9bce044c7643
patch 8.2.3178: Vim9: the file name of an :import cannot be an expression
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
466 || tv.vval.v_string == NULL || *tv.vval.v_string == NUL) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
467 { |
21821
0deb6f96a5a3
patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
468 emsg(_(e_invalid_string_after_from)); |
21146
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
469 goto erret; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
470 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
471 cmd_end = arg; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
472 |
25423
3e56078569ca
patch 8.2.3248: Vim9: error message for wrong input uses wrong line number
Bram Moolenaar <Bram@vim.org>
parents:
25358
diff
changeset
|
473 // Give error messages for the start of the line. |
3e56078569ca
patch 8.2.3248: Vim9: error message for wrong input uses wrong line number
Bram Moolenaar <Bram@vim.org>
parents:
25358
diff
changeset
|
474 SOURCING_LNUM = start_lnum; |
3e56078569ca
patch 8.2.3248: Vim9: error message for wrong input uses wrong line number
Bram Moolenaar <Bram@vim.org>
parents:
25358
diff
changeset
|
475 |
21146
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
476 /* |
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
477 * find script file |
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
478 */ |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
479 if (*tv.vval.v_string == '.') |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
480 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
481 size_t len; |
19191
133ef7ba4e4e
patch 8.2.0154: reallocating the list of scripts is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
482 scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
483 char_u *tail = gettail(si->sn_name); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
484 char_u *from_name; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
485 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
486 // Relative to current script: "./name.vim", "../../name.vim". |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
487 len = STRLEN(si->sn_name) - STRLEN(tail) + STRLEN(tv.vval.v_string) + 2; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
488 from_name = alloc((int)len); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
489 if (from_name == NULL) |
21146
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
490 goto erret; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
491 vim_strncpy(from_name, si->sn_name, tail - si->sn_name); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
492 add_pathsep(from_name); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
493 STRCAT(from_name, tv.vval.v_string); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
494 simplify_filename(from_name); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
495 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
496 res = do_source(from_name, FALSE, DOSO_NONE, &sid); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
497 vim_free(from_name); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
498 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
499 else if (mch_isFullName(tv.vval.v_string)) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
500 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
501 // Absolute path: "/tmp/name.vim" |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
502 res = do_source(tv.vval.v_string, FALSE, DOSO_NONE, &sid); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
503 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
504 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
505 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
506 size_t len = 7 + STRLEN(tv.vval.v_string) + 1; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
507 char_u *from_name; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
508 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
509 // Find file in "import" subdirs in 'runtimepath'. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
510 from_name = alloc((int)len); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
511 if (from_name == NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
512 { |
21146
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
513 goto erret; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
514 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
515 vim_snprintf((char *)from_name, len, "import/%s", tv.vval.v_string); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
516 res = source_in_path(p_rtp, from_name, DIP_NOAFTER, &sid); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
517 vim_free(from_name); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
518 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
519 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
520 if (res == FAIL || sid <= 0) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
521 { |
21821
0deb6f96a5a3
patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
522 semsg(_(e_could_not_import_str), tv.vval.v_string); |
21146
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
523 goto erret; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
524 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
525 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
526 if (*arg_start == '*') |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
527 { |
24029
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
528 imported_T *imported; |
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
529 char_u *as_name = ((char_u **)as_names.ga_data)[0]; |
23364
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
530 |
24029
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
531 // "import * as That" |
23364
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
532 imported = find_imported(as_name, STRLEN(as_name), cctx); |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
533 if (imported != NULL && imported->imp_sid == sid) |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
534 { |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
535 if (imported->imp_flags & IMP_FLAGS_RELOAD) |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
536 // import already defined on a previous script load |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
537 imported->imp_flags &= ~IMP_FLAGS_RELOAD; |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
538 else |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
539 { |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
540 semsg(_(e_name_already_defined_str), as_name); |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
541 goto erret; |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
542 } |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
543 } |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
544 |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
545 imported = new_imported(gap != NULL ? gap |
19191
133ef7ba4e4e
patch 8.2.0154: reallocating the list of scripts is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
546 : &SCRIPT_ITEM(import_sid)->sn_imports); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
547 if (imported == NULL) |
21146
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
548 goto erret; |
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
549 imported->imp_name = as_name; |
24029
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
550 ((char_u **)as_names.ga_data)[0] = NULL; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
551 imported->imp_sid = sid; |
23364
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
552 imported->imp_flags = IMP_FLAGS_STAR; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
553 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
554 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
555 { |
21146
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
556 int i; |
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
557 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
558 arg = arg_start; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
559 if (*arg == '{') |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
560 arg = skipwhite(arg + 1); |
21146
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
561 for (i = 0; i < names.ga_len; ++i) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
562 { |
21146
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
563 char_u *name = ((char_u **)names.ga_data)[i]; |
24029
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
564 char_u *as_name = ((char_u **)as_names.ga_data)[i]; |
23364
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
565 size_t len = STRLEN(name); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
566 int idx; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
567 imported_T *imported; |
19509
17f0d6dc6a73
patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents:
19227
diff
changeset
|
568 ufunc_T *ufunc = NULL; |
17f0d6dc6a73
patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents:
19227
diff
changeset
|
569 type_T *type; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
570 |
24112
0346a59ed5bf
patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents:
24079
diff
changeset
|
571 idx = find_exported(sid, name, &ufunc, &type, cctx, TRUE); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
572 |
19509
17f0d6dc6a73
patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents:
19227
diff
changeset
|
573 if (idx < 0 && ufunc == NULL) |
21146
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
574 goto erret; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
575 |
25186
0a3b1c66d3f2
patch 8.2.3129: Vim9: imported uninitialized list does not get type checked
Bram Moolenaar <Bram@vim.org>
parents:
25184
diff
changeset
|
576 // If already imported with the same properties and the |
23364
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
577 // IMP_FLAGS_RELOAD set then we keep that entry. Otherwise create |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
578 // a new one (and give an error for an existing import). |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
579 imported = find_imported(name, len, cctx); |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
580 if (imported != NULL |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
581 && (imported->imp_flags & IMP_FLAGS_RELOAD) |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
582 && imported->imp_sid == sid |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
583 && (idx >= 0 |
25425
effe5f2b4d01
patch 8.2.3249: Vim9: error for re-imported function with default argument
Bram Moolenaar <Bram@vim.org>
parents:
25423
diff
changeset
|
584 ? (equal_type(imported->imp_type, type, 0) |
23364
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
585 && imported->imp_var_vals_idx == idx) |
25425
effe5f2b4d01
patch 8.2.3249: Vim9: error for re-imported function with default argument
Bram Moolenaar <Bram@vim.org>
parents:
25423
diff
changeset
|
586 : (equal_type(imported->imp_type, ufunc->uf_func_type, |
effe5f2b4d01
patch 8.2.3249: Vim9: error for re-imported function with default argument
Bram Moolenaar <Bram@vim.org>
parents:
25423
diff
changeset
|
587 ETYPE_ARG_UNKNOWN) |
23364
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
588 && STRCMP(imported->imp_funcname, |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
589 ufunc->uf_name) == 0))) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
590 { |
23364
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
591 imported->imp_flags &= ~IMP_FLAGS_RELOAD; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
592 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
593 else |
21473
8bcd1ee2630b
patch 8.2.1287: Vim9: crash when using an imported function
Bram Moolenaar <Bram@vim.org>
parents:
21449
diff
changeset
|
594 { |
24469
e5db23a8ad98
patch 8.2.2774: Vim9: cannot import an existing name even when using "as"
Bram Moolenaar <Bram@vim.org>
parents:
24438
diff
changeset
|
595 if (as_name == NULL |
e5db23a8ad98
patch 8.2.2774: Vim9: cannot import an existing name even when using "as"
Bram Moolenaar <Bram@vim.org>
parents:
24438
diff
changeset
|
596 && check_defined(name, len, cctx, FALSE) == FAIL) |
23364
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
597 goto erret; |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
598 |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
599 imported = new_imported(gap != NULL ? gap |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
600 : &SCRIPT_ITEM(import_sid)->sn_imports); |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
601 if (imported == NULL) |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
602 goto erret; |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
603 |
24029
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
604 if (as_name == NULL) |
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
605 { |
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
606 imported->imp_name = name; |
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
607 ((char_u **)names.ga_data)[i] = NULL; |
24033
308d29307910
patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents:
24031
diff
changeset
|
608 } |
24029
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
609 else |
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
610 { |
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
611 // "import This as That ..." |
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
612 imported->imp_name = as_name; |
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
613 ((char_u **)as_names.ga_data)[i] = NULL; |
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
614 } |
23364
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
615 imported->imp_sid = sid; |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
616 if (idx >= 0) |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
617 { |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
618 imported->imp_type = type; |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
619 imported->imp_var_vals_idx = idx; |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
620 } |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
621 else |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
622 { |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
623 imported->imp_type = ufunc->uf_func_type; |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
624 imported->imp_funcname = ufunc->uf_name; |
17a0e32eefd4
patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
625 } |
21473
8bcd1ee2630b
patch 8.2.1287: Vim9: crash when using an imported function
Bram Moolenaar <Bram@vim.org>
parents:
21449
diff
changeset
|
626 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
627 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
628 } |
21146
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
629 erret: |
25282
9bce044c7643
patch 8.2.3178: Vim9: the file name of an :import cannot be an expression
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
630 clear_tv(&tv); |
21146
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
631 ga_clear_strings(&names); |
24029
429b4f8d2fac
patch 8.2.2556: Vim9: :import with "as" not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
632 ga_clear_strings(&as_names); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
633 return cmd_end; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
634 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
635 |
20840
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20816
diff
changeset
|
636 /* |
25567
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
637 * ":import Item from 'filename'" |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
638 * ":import Item as Alias from 'filename'" |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
639 * ":import {Item} from 'filename'". |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
640 * ":import {Item as Alias} from 'filename'" |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
641 * ":import {Item, Item} from 'filename'" |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
642 * ":import {Item, Item as Alias} from 'filename'" |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
643 * |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
644 * ":import * as Name from 'filename'" |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
645 */ |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
646 void |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
647 ex_import(exarg_T *eap) |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
648 { |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
649 char_u *cmd_end; |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
650 evalarg_T evalarg; |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
651 |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
652 if (!getline_equal(eap->getline, eap->cookie, getsourceline)) |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
653 { |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
654 emsg(_(e_import_can_only_be_used_in_script)); |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
655 return; |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
656 } |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
657 fill_evalarg_from_eap(&evalarg, eap, eap->skip); |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
658 |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
659 cmd_end = handle_import(eap->arg, NULL, current_sctx.sc_sid, |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
660 &evalarg, NULL); |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
661 if (cmd_end != NULL) |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
662 set_nextcmd(eap, cmd_end); |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
663 clear_evalarg(&evalarg, eap); |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
664 } |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
665 |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
666 /* |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
667 * Find an exported item in "sid" matching the name at "*argp". |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
668 * When it is a variable return the index. |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
669 * When it is a user function return "*ufunc". |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
670 * When not found returns -1 and "*ufunc" is NULL. |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
671 */ |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
672 int |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
673 find_exported( |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
674 int sid, |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
675 char_u *name, |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
676 ufunc_T **ufunc, |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
677 type_T **type, |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
678 cctx_T *cctx, |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
679 int verbose) |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
680 { |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
681 int idx = -1; |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
682 svar_T *sv; |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
683 scriptitem_T *script = SCRIPT_ITEM(sid); |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
684 |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
685 // Find name in "script". |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
686 idx = get_script_item_idx(sid, name, 0, cctx); |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
687 if (idx >= 0) |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
688 { |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
689 sv = ((svar_T *)script->sn_var_vals.ga_data) + idx; |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
690 if (!sv->sv_export) |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
691 { |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
692 if (verbose) |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
693 semsg(_(e_item_not_exported_in_script_str), name); |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
694 return -1; |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
695 } |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
696 *type = sv->sv_type; |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
697 *ufunc = NULL; |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
698 } |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
699 else |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
700 { |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
701 char_u buffer[200]; |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
702 char_u *funcname; |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
703 |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
704 // it could be a user function. |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
705 if (STRLEN(name) < sizeof(buffer) - 15) |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
706 funcname = buffer; |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
707 else |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
708 { |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
709 funcname = alloc(STRLEN(name) + 15); |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
710 if (funcname == NULL) |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
711 return -1; |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
712 } |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
713 funcname[0] = K_SPECIAL; |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
714 funcname[1] = KS_EXTRA; |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
715 funcname[2] = (int)KE_SNR; |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
716 sprintf((char *)funcname + 3, "%ld_%s", (long)sid, name); |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
717 *ufunc = find_func(funcname, FALSE, NULL); |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
718 if (funcname != buffer) |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
719 vim_free(funcname); |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
720 |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
721 if (*ufunc == NULL) |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
722 { |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
723 if (verbose) |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
724 semsg(_(e_item_not_found_in_script_str), name); |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
725 return -1; |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
726 } |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
727 else if (((*ufunc)->uf_flags & FC_EXPORT) == 0) |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
728 { |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
729 if (verbose) |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
730 semsg(_(e_item_not_exported_in_script_str), name); |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
731 *ufunc = NULL; |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
732 return -1; |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
733 } |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
734 } |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
735 |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
736 return idx; |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
737 } |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
738 |
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
739 /* |
20840
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20816
diff
changeset
|
740 * Declare a script-local variable without init: "let var: type". |
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20816
diff
changeset
|
741 * "const" is an error since the value is missing. |
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20816
diff
changeset
|
742 * Returns a pointer to after the type. |
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20816
diff
changeset
|
743 */ |
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20816
diff
changeset
|
744 char_u * |
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20816
diff
changeset
|
745 vim9_declare_scriptvar(exarg_T *eap, char_u *arg) |
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20816
diff
changeset
|
746 { |
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20816
diff
changeset
|
747 char_u *p; |
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20816
diff
changeset
|
748 char_u *name; |
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20816
diff
changeset
|
749 scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid); |
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20816
diff
changeset
|
750 type_T *type; |
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20816
diff
changeset
|
751 typval_T init_tv; |
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20816
diff
changeset
|
752 |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22250
diff
changeset
|
753 if (eap->cmdidx == CMD_final || eap->cmdidx == CMD_const) |
20840
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20816
diff
changeset
|
754 { |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22250
diff
changeset
|
755 if (eap->cmdidx == CMD_final) |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22250
diff
changeset
|
756 emsg(_(e_final_requires_a_value)); |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22250
diff
changeset
|
757 else |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22250
diff
changeset
|
758 emsg(_(e_const_requires_a_value)); |
20840
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20816
diff
changeset
|
759 return arg + STRLEN(arg); |
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20816
diff
changeset
|
760 } |
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20816
diff
changeset
|
761 |
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20816
diff
changeset
|
762 // Check for valid starting character. |
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20816
diff
changeset
|
763 if (!eval_isnamec1(*arg)) |
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20816
diff
changeset
|
764 { |
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20816
diff
changeset
|
765 semsg(_(e_invarg2), arg); |
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20816
diff
changeset
|
766 return arg + STRLEN(arg); |
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20816
diff
changeset
|
767 } |
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20816
diff
changeset
|
768 |
20846
709379ab5110
patch 8.2.0975: Vim9: script variable does not accept optional s: prefix
Bram Moolenaar <Bram@vim.org>
parents:
20844
diff
changeset
|
769 for (p = arg + 1; *p != NUL && eval_isnamec(*p); MB_PTR_ADV(p)) |
20921
187c3fb42c8f
patch 8.2.1012: Vim9: cannot declare single character script variables
Bram Moolenaar <Bram@vim.org>
parents:
20919
diff
changeset
|
770 if (*p == ':' && (VIM_ISWHITE(p[1]) || p != arg + 1)) |
20846
709379ab5110
patch 8.2.0975: Vim9: script variable does not accept optional s: prefix
Bram Moolenaar <Bram@vim.org>
parents:
20844
diff
changeset
|
771 break; |
20840
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20816
diff
changeset
|
772 |
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20816
diff
changeset
|
773 if (*p != ':') |
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20816
diff
changeset
|
774 { |
21789
f84625b961a8
patch 8.2.1444: error messages are spread out and names can be confusing
Bram Moolenaar <Bram@vim.org>
parents:
21584
diff
changeset
|
775 emsg(_(e_type_or_initialization_required)); |
20840
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20816
diff
changeset
|
776 return arg + STRLEN(arg); |
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20816
diff
changeset
|
777 } |
20846
709379ab5110
patch 8.2.0975: Vim9: script variable does not accept optional s: prefix
Bram Moolenaar <Bram@vim.org>
parents:
20844
diff
changeset
|
778 if (!VIM_ISWHITE(p[1])) |
709379ab5110
patch 8.2.0975: Vim9: script variable does not accept optional s: prefix
Bram Moolenaar <Bram@vim.org>
parents:
20844
diff
changeset
|
779 { |
23877
85cf06ddb2a8
patch 8.2.2480: Vim9: some errors for white space do not show context
Bram Moolenaar <Bram@vim.org>
parents:
23578
diff
changeset
|
780 semsg(_(e_white_space_required_after_str_str), ":", p); |
20846
709379ab5110
patch 8.2.0975: Vim9: script variable does not accept optional s: prefix
Bram Moolenaar <Bram@vim.org>
parents:
20844
diff
changeset
|
781 return arg + STRLEN(arg); |
709379ab5110
patch 8.2.0975: Vim9: script variable does not accept optional s: prefix
Bram Moolenaar <Bram@vim.org>
parents:
20844
diff
changeset
|
782 } |
20840
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20816
diff
changeset
|
783 name = vim_strnsave(arg, p - arg); |
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20816
diff
changeset
|
784 |
24717
bf8feac8a89a
patch 8.2.2897: Vim9: can use reserved words at the script level
Bram Moolenaar <Bram@vim.org>
parents:
24533
diff
changeset
|
785 // parse type, check for reserved name |
20840
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20816
diff
changeset
|
786 p = skipwhite(p + 1); |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23094
diff
changeset
|
787 type = parse_type(&p, &si->sn_type_list, TRUE); |
24717
bf8feac8a89a
patch 8.2.2897: Vim9: can use reserved words at the script level
Bram Moolenaar <Bram@vim.org>
parents:
24533
diff
changeset
|
788 if (type == NULL || check_reserved_name(name) == FAIL) |
20844
1360541e8c74
patch 8.2.0974: Vim9: memory leak when script var has wrong type
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
789 { |
1360541e8c74
patch 8.2.0974: Vim9: memory leak when script var has wrong type
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
790 vim_free(name); |
20840
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20816
diff
changeset
|
791 return p; |
20844
1360541e8c74
patch 8.2.0974: Vim9: memory leak when script var has wrong type
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
792 } |
20840
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20816
diff
changeset
|
793 |
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20816
diff
changeset
|
794 // Create the variable with 0/NULL value. |
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20816
diff
changeset
|
795 CLEAR_FIELD(init_tv); |
22250
dd42235ed626
patch 8.2.1674: Vim9: internal error when using variable that was not set
Bram Moolenaar <Bram@vim.org>
parents:
22202
diff
changeset
|
796 if (type->tt_type == VAR_ANY) |
dd42235ed626
patch 8.2.1674: Vim9: internal error when using variable that was not set
Bram Moolenaar <Bram@vim.org>
parents:
22202
diff
changeset
|
797 // A variable of type "any" is not possible, just use zero instead |
dd42235ed626
patch 8.2.1674: Vim9: internal error when using variable that was not set
Bram Moolenaar <Bram@vim.org>
parents:
22202
diff
changeset
|
798 init_tv.v_type = VAR_NUMBER; |
dd42235ed626
patch 8.2.1674: Vim9: internal error when using variable that was not set
Bram Moolenaar <Bram@vim.org>
parents:
22202
diff
changeset
|
799 else |
dd42235ed626
patch 8.2.1674: Vim9: internal error when using variable that was not set
Bram Moolenaar <Bram@vim.org>
parents:
22202
diff
changeset
|
800 init_tv.v_type = type->tt_type; |
23917
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23877
diff
changeset
|
801 set_var_const(name, type, &init_tv, FALSE, 0, 0); |
20840
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20816
diff
changeset
|
802 |
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20816
diff
changeset
|
803 vim_free(name); |
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20816
diff
changeset
|
804 return p; |
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20816
diff
changeset
|
805 } |
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20816
diff
changeset
|
806 |
20842
bacc2ab11810
patch 8.2.0973: Vim9: type is not checked when assigning to a script variable
Bram Moolenaar <Bram@vim.org>
parents:
20840
diff
changeset
|
807 /* |
22643
71b57779177d
patch 8.2.1870: Vim9: no need to keep all script variables
Bram Moolenaar <Bram@vim.org>
parents:
22596
diff
changeset
|
808 * Vim9 part of adding a script variable: add it to sn_all_vars (lookup by name |
71b57779177d
patch 8.2.1870: Vim9: no need to keep all script variables
Bram Moolenaar <Bram@vim.org>
parents:
22596
diff
changeset
|
809 * with a hashtable) and sn_var_vals (lookup by index). |
23362
f181fe2150ab
patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents:
23358
diff
changeset
|
810 * When "create" is TRUE this is a new variable, otherwise find and update an |
f181fe2150ab
patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents:
23358
diff
changeset
|
811 * existing variable. |
23578
85ce241ff9e3
patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents:
23458
diff
changeset
|
812 * "flags" can have ASSIGN_FINAL or ASSIGN_CONST. |
24438
5c6ccab68d1e
patch 8.2.2759: Vim9: for loop infers type of loop variable
Bram Moolenaar <Bram@vim.org>
parents:
24285
diff
changeset
|
813 * When "*type" is NULL use "tv" for the type and update "*type". If |
5c6ccab68d1e
patch 8.2.2759: Vim9: for loop infers type of loop variable
Bram Moolenaar <Bram@vim.org>
parents:
24285
diff
changeset
|
814 * "do_member" is TRUE also use the member type, otherwise use "any". |
22594
209c7aa56325
patch 8.2.1845: Vim9: function defined in a block can't use block variables
Bram Moolenaar <Bram@vim.org>
parents:
22529
diff
changeset
|
815 */ |
209c7aa56325
patch 8.2.1845: Vim9: function defined in a block can't use block variables
Bram Moolenaar <Bram@vim.org>
parents:
22529
diff
changeset
|
816 void |
23578
85ce241ff9e3
patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents:
23458
diff
changeset
|
817 update_vim9_script_var( |
85ce241ff9e3
patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents:
23458
diff
changeset
|
818 int create, |
85ce241ff9e3
patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents:
23458
diff
changeset
|
819 dictitem_T *di, |
85ce241ff9e3
patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents:
23458
diff
changeset
|
820 int flags, |
85ce241ff9e3
patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents:
23458
diff
changeset
|
821 typval_T *tv, |
24438
5c6ccab68d1e
patch 8.2.2759: Vim9: for loop infers type of loop variable
Bram Moolenaar <Bram@vim.org>
parents:
24285
diff
changeset
|
822 type_T **type, |
5c6ccab68d1e
patch 8.2.2759: Vim9: for loop infers type of loop variable
Bram Moolenaar <Bram@vim.org>
parents:
24285
diff
changeset
|
823 int do_member) |
22594
209c7aa56325
patch 8.2.1845: Vim9: function defined in a block can't use block variables
Bram Moolenaar <Bram@vim.org>
parents:
22529
diff
changeset
|
824 { |
23362
f181fe2150ab
patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents:
23358
diff
changeset
|
825 scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid); |
f181fe2150ab
patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents:
23358
diff
changeset
|
826 hashitem_T *hi; |
25358
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
827 svar_T *sv = NULL; |
22594
209c7aa56325
patch 8.2.1845: Vim9: function defined in a block can't use block variables
Bram Moolenaar <Bram@vim.org>
parents:
22529
diff
changeset
|
828 |
23362
f181fe2150ab
patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents:
23358
diff
changeset
|
829 if (create) |
22594
209c7aa56325
patch 8.2.1845: Vim9: function defined in a block can't use block variables
Bram Moolenaar <Bram@vim.org>
parents:
22529
diff
changeset
|
830 { |
25358
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
831 sallvar_T *newsav; |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
832 sallvar_T *sav = NULL; |
23362
f181fe2150ab
patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents:
23358
diff
changeset
|
833 |
f181fe2150ab
patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents:
23358
diff
changeset
|
834 // Store a pointer to the typval_T, so that it can be found by index |
f181fe2150ab
patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents:
23358
diff
changeset
|
835 // instead of using a hastab lookup. |
f181fe2150ab
patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents:
23358
diff
changeset
|
836 if (ga_grow(&si->sn_var_vals, 1) == FAIL) |
f181fe2150ab
patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents:
23358
diff
changeset
|
837 return; |
f181fe2150ab
patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents:
23358
diff
changeset
|
838 |
25358
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
839 hi = hash_find(&si->sn_all_vars.dv_hashtab, di->di_key); |
22594
209c7aa56325
patch 8.2.1845: Vim9: function defined in a block can't use block variables
Bram Moolenaar <Bram@vim.org>
parents:
22529
diff
changeset
|
840 if (!HASHITEM_EMPTY(hi)) |
209c7aa56325
patch 8.2.1845: Vim9: function defined in a block can't use block variables
Bram Moolenaar <Bram@vim.org>
parents:
22529
diff
changeset
|
841 { |
25358
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
842 // Variable with this name exists, either in this block or in |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
843 // another block. |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
844 for (sav = HI2SAV(hi); ; sav = sav->sav_next) |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
845 { |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
846 if (sav->sav_block_id == si->sn_current_block_id) |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
847 { |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
848 // variable defined in a loop, re-use the entry |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
849 sv = ((svar_T *)si->sn_var_vals.ga_data) |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
850 + sav->sav_var_vals_idx; |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
851 // unhide the variable |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
852 if (sv->sv_tv == &sav->sav_tv) |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
853 { |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
854 clear_tv(&sav->sav_tv); |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
855 sv->sv_tv = &di->di_tv; |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
856 sav->sav_di = di; |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
857 } |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
858 break; |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
859 } |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
860 if (sav->sav_next == NULL) |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
861 break; |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
862 } |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
863 } |
22594
209c7aa56325
patch 8.2.1845: Vim9: function defined in a block can't use block variables
Bram Moolenaar <Bram@vim.org>
parents:
22529
diff
changeset
|
864 |
25358
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
865 if (sv == NULL) |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
866 { |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
867 // Variable not defined or not defined in current block: Add a |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
868 // svar_T and create a new sallvar_T. |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
869 sv = ((svar_T *)si->sn_var_vals.ga_data) + si->sn_var_vals.ga_len; |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
870 newsav = (sallvar_T *)alloc_clear( |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
871 sizeof(sallvar_T) + STRLEN(di->di_key)); |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
872 if (newsav == NULL) |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
873 return; |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
874 |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
875 sv->sv_tv = &di->di_tv; |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
876 sv->sv_const = (flags & ASSIGN_FINAL) ? ASSIGN_FINAL |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
877 : (flags & ASSIGN_CONST) ? ASSIGN_CONST : 0; |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
878 sv->sv_export = is_export; |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
879 newsav->sav_var_vals_idx = si->sn_var_vals.ga_len; |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
880 ++si->sn_var_vals.ga_len; |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
881 STRCPY(&newsav->sav_key, di->di_key); |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
882 sv->sv_name = newsav->sav_key; |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
883 newsav->sav_di = di; |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
884 newsav->sav_block_id = si->sn_current_block_id; |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
885 |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
886 if (HASHITEM_EMPTY(hi)) |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
887 // new variable name |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
888 hash_add(&si->sn_all_vars.dv_hashtab, newsav->sav_key); |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
889 else if (sav != NULL) |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
890 // existing name in a new block, append to the list |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
891 sav->sav_next = newsav; |
22594
209c7aa56325
patch 8.2.1845: Vim9: function defined in a block can't use block variables
Bram Moolenaar <Bram@vim.org>
parents:
22529
diff
changeset
|
892 } |
23362
f181fe2150ab
patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents:
23358
diff
changeset
|
893 } |
f181fe2150ab
patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents:
23358
diff
changeset
|
894 else |
f181fe2150ab
patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents:
23358
diff
changeset
|
895 { |
25186
0a3b1c66d3f2
patch 8.2.3129: Vim9: imported uninitialized list does not get type checked
Bram Moolenaar <Bram@vim.org>
parents:
25184
diff
changeset
|
896 sv = find_typval_in_script(&di->di_tv); |
23362
f181fe2150ab
patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents:
23358
diff
changeset
|
897 } |
f181fe2150ab
patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents:
23358
diff
changeset
|
898 if (sv != NULL) |
f181fe2150ab
patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents:
23358
diff
changeset
|
899 { |
23458
d2b1269c2c68
patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents:
23392
diff
changeset
|
900 if (*type == NULL) |
25358
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
901 *type = typval2type(tv, get_copyID(), &si->sn_type_list, do_member); |
23458
d2b1269c2c68
patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents:
23392
diff
changeset
|
902 sv->sv_type = *type; |
23362
f181fe2150ab
patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents:
23358
diff
changeset
|
903 } |
22594
209c7aa56325
patch 8.2.1845: Vim9: function defined in a block can't use block variables
Bram Moolenaar <Bram@vim.org>
parents:
22529
diff
changeset
|
904 |
23362
f181fe2150ab
patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents:
23358
diff
changeset
|
905 // let ex_export() know the export worked. |
f181fe2150ab
patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents:
23358
diff
changeset
|
906 is_export = FALSE; |
22594
209c7aa56325
patch 8.2.1845: Vim9: function defined in a block can't use block variables
Bram Moolenaar <Bram@vim.org>
parents:
22529
diff
changeset
|
907 } |
209c7aa56325
patch 8.2.1845: Vim9: function defined in a block can't use block variables
Bram Moolenaar <Bram@vim.org>
parents:
22529
diff
changeset
|
908 |
22596
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22594
diff
changeset
|
909 /* |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22594
diff
changeset
|
910 * Hide a script variable when leaving a block. |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22594
diff
changeset
|
911 * "idx" is de index in sn_var_vals. |
22643
71b57779177d
patch 8.2.1870: Vim9: no need to keep all script variables
Bram Moolenaar <Bram@vim.org>
parents:
22596
diff
changeset
|
912 * When "func_defined" is non-zero then a function was defined in this block, |
71b57779177d
patch 8.2.1870: Vim9: no need to keep all script variables
Bram Moolenaar <Bram@vim.org>
parents:
22596
diff
changeset
|
913 * the variable may be accessed by it. Otherwise the variable can be cleared. |
22596
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22594
diff
changeset
|
914 */ |
22594
209c7aa56325
patch 8.2.1845: Vim9: function defined in a block can't use block variables
Bram Moolenaar <Bram@vim.org>
parents:
22529
diff
changeset
|
915 void |
22643
71b57779177d
patch 8.2.1870: Vim9: no need to keep all script variables
Bram Moolenaar <Bram@vim.org>
parents:
22596
diff
changeset
|
916 hide_script_var(scriptitem_T *si, int idx, int func_defined) |
22594
209c7aa56325
patch 8.2.1845: Vim9: function defined in a block can't use block variables
Bram Moolenaar <Bram@vim.org>
parents:
22529
diff
changeset
|
917 { |
22596
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22594
diff
changeset
|
918 svar_T *sv = ((svar_T *)si->sn_var_vals.ga_data) + idx; |
22594
209c7aa56325
patch 8.2.1845: Vim9: function defined in a block can't use block variables
Bram Moolenaar <Bram@vim.org>
parents:
22529
diff
changeset
|
919 hashtab_T *script_ht = get_script_local_ht(); |
209c7aa56325
patch 8.2.1845: Vim9: function defined in a block can't use block variables
Bram Moolenaar <Bram@vim.org>
parents:
22529
diff
changeset
|
920 hashtab_T *all_ht = &si->sn_all_vars.dv_hashtab; |
209c7aa56325
patch 8.2.1845: Vim9: function defined in a block can't use block variables
Bram Moolenaar <Bram@vim.org>
parents:
22529
diff
changeset
|
921 hashitem_T *script_hi; |
209c7aa56325
patch 8.2.1845: Vim9: function defined in a block can't use block variables
Bram Moolenaar <Bram@vim.org>
parents:
22529
diff
changeset
|
922 hashitem_T *all_hi; |
209c7aa56325
patch 8.2.1845: Vim9: function defined in a block can't use block variables
Bram Moolenaar <Bram@vim.org>
parents:
22529
diff
changeset
|
923 |
209c7aa56325
patch 8.2.1845: Vim9: function defined in a block can't use block variables
Bram Moolenaar <Bram@vim.org>
parents:
22529
diff
changeset
|
924 // Remove a variable declared inside the block, if it still exists. |
22643
71b57779177d
patch 8.2.1870: Vim9: no need to keep all script variables
Bram Moolenaar <Bram@vim.org>
parents:
22596
diff
changeset
|
925 // If it was added in a nested block it will already have been removed. |
22594
209c7aa56325
patch 8.2.1845: Vim9: function defined in a block can't use block variables
Bram Moolenaar <Bram@vim.org>
parents:
22529
diff
changeset
|
926 // The typval is moved into the sallvar_T. |
209c7aa56325
patch 8.2.1845: Vim9: function defined in a block can't use block variables
Bram Moolenaar <Bram@vim.org>
parents:
22529
diff
changeset
|
927 script_hi = hash_find(script_ht, sv->sv_name); |
209c7aa56325
patch 8.2.1845: Vim9: function defined in a block can't use block variables
Bram Moolenaar <Bram@vim.org>
parents:
22529
diff
changeset
|
928 all_hi = hash_find(all_ht, sv->sv_name); |
209c7aa56325
patch 8.2.1845: Vim9: function defined in a block can't use block variables
Bram Moolenaar <Bram@vim.org>
parents:
22529
diff
changeset
|
929 if (!HASHITEM_EMPTY(script_hi) && !HASHITEM_EMPTY(all_hi)) |
209c7aa56325
patch 8.2.1845: Vim9: function defined in a block can't use block variables
Bram Moolenaar <Bram@vim.org>
parents:
22529
diff
changeset
|
930 { |
209c7aa56325
patch 8.2.1845: Vim9: function defined in a block can't use block variables
Bram Moolenaar <Bram@vim.org>
parents:
22529
diff
changeset
|
931 dictitem_T *di = HI2DI(script_hi); |
209c7aa56325
patch 8.2.1845: Vim9: function defined in a block can't use block variables
Bram Moolenaar <Bram@vim.org>
parents:
22529
diff
changeset
|
932 sallvar_T *sav = HI2SAV(all_hi); |
22643
71b57779177d
patch 8.2.1870: Vim9: no need to keep all script variables
Bram Moolenaar <Bram@vim.org>
parents:
22596
diff
changeset
|
933 sallvar_T *sav_prev = NULL; |
22594
209c7aa56325
patch 8.2.1845: Vim9: function defined in a block can't use block variables
Bram Moolenaar <Bram@vim.org>
parents:
22529
diff
changeset
|
934 |
22596
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22594
diff
changeset
|
935 // There can be multiple entries with the same name in different |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22594
diff
changeset
|
936 // blocks, find the right one. |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22594
diff
changeset
|
937 while (sav != NULL && sav->sav_var_vals_idx != idx) |
22643
71b57779177d
patch 8.2.1870: Vim9: no need to keep all script variables
Bram Moolenaar <Bram@vim.org>
parents:
22596
diff
changeset
|
938 { |
71b57779177d
patch 8.2.1870: Vim9: no need to keep all script variables
Bram Moolenaar <Bram@vim.org>
parents:
22596
diff
changeset
|
939 sav_prev = sav; |
22596
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22594
diff
changeset
|
940 sav = sav->sav_next; |
22643
71b57779177d
patch 8.2.1870: Vim9: no need to keep all script variables
Bram Moolenaar <Bram@vim.org>
parents:
22596
diff
changeset
|
941 } |
22596
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22594
diff
changeset
|
942 if (sav != NULL) |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22594
diff
changeset
|
943 { |
22643
71b57779177d
patch 8.2.1870: Vim9: no need to keep all script variables
Bram Moolenaar <Bram@vim.org>
parents:
22596
diff
changeset
|
944 if (func_defined) |
71b57779177d
patch 8.2.1870: Vim9: no need to keep all script variables
Bram Moolenaar <Bram@vim.org>
parents:
22596
diff
changeset
|
945 { |
71b57779177d
patch 8.2.1870: Vim9: no need to keep all script variables
Bram Moolenaar <Bram@vim.org>
parents:
22596
diff
changeset
|
946 // move the typval from the dictitem to the sallvar |
71b57779177d
patch 8.2.1870: Vim9: no need to keep all script variables
Bram Moolenaar <Bram@vim.org>
parents:
22596
diff
changeset
|
947 sav->sav_tv = di->di_tv; |
71b57779177d
patch 8.2.1870: Vim9: no need to keep all script variables
Bram Moolenaar <Bram@vim.org>
parents:
22596
diff
changeset
|
948 di->di_tv.v_type = VAR_UNKNOWN; |
71b57779177d
patch 8.2.1870: Vim9: no need to keep all script variables
Bram Moolenaar <Bram@vim.org>
parents:
22596
diff
changeset
|
949 sav->sav_flags = di->di_flags; |
71b57779177d
patch 8.2.1870: Vim9: no need to keep all script variables
Bram Moolenaar <Bram@vim.org>
parents:
22596
diff
changeset
|
950 sav->sav_di = NULL; |
71b57779177d
patch 8.2.1870: Vim9: no need to keep all script variables
Bram Moolenaar <Bram@vim.org>
parents:
22596
diff
changeset
|
951 sv->sv_tv = &sav->sav_tv; |
71b57779177d
patch 8.2.1870: Vim9: no need to keep all script variables
Bram Moolenaar <Bram@vim.org>
parents:
22596
diff
changeset
|
952 } |
71b57779177d
patch 8.2.1870: Vim9: no need to keep all script variables
Bram Moolenaar <Bram@vim.org>
parents:
22596
diff
changeset
|
953 else |
71b57779177d
patch 8.2.1870: Vim9: no need to keep all script variables
Bram Moolenaar <Bram@vim.org>
parents:
22596
diff
changeset
|
954 { |
71b57779177d
patch 8.2.1870: Vim9: no need to keep all script variables
Bram Moolenaar <Bram@vim.org>
parents:
22596
diff
changeset
|
955 if (sav_prev == NULL) |
71b57779177d
patch 8.2.1870: Vim9: no need to keep all script variables
Bram Moolenaar <Bram@vim.org>
parents:
22596
diff
changeset
|
956 hash_remove(all_ht, all_hi); |
71b57779177d
patch 8.2.1870: Vim9: no need to keep all script variables
Bram Moolenaar <Bram@vim.org>
parents:
22596
diff
changeset
|
957 else |
71b57779177d
patch 8.2.1870: Vim9: no need to keep all script variables
Bram Moolenaar <Bram@vim.org>
parents:
22596
diff
changeset
|
958 sav_prev->sav_next = sav->sav_next; |
71b57779177d
patch 8.2.1870: Vim9: no need to keep all script variables
Bram Moolenaar <Bram@vim.org>
parents:
22596
diff
changeset
|
959 sv->sv_name = NULL; |
71b57779177d
patch 8.2.1870: Vim9: no need to keep all script variables
Bram Moolenaar <Bram@vim.org>
parents:
22596
diff
changeset
|
960 vim_free(sav); |
71b57779177d
patch 8.2.1870: Vim9: no need to keep all script variables
Bram Moolenaar <Bram@vim.org>
parents:
22596
diff
changeset
|
961 } |
22596
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22594
diff
changeset
|
962 delete_var(script_ht, script_hi); |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22594
diff
changeset
|
963 } |
22594
209c7aa56325
patch 8.2.1845: Vim9: function defined in a block can't use block variables
Bram Moolenaar <Bram@vim.org>
parents:
22529
diff
changeset
|
964 } |
209c7aa56325
patch 8.2.1845: Vim9: function defined in a block can't use block variables
Bram Moolenaar <Bram@vim.org>
parents:
22529
diff
changeset
|
965 } |
209c7aa56325
patch 8.2.1845: Vim9: function defined in a block can't use block variables
Bram Moolenaar <Bram@vim.org>
parents:
22529
diff
changeset
|
966 |
209c7aa56325
patch 8.2.1845: Vim9: function defined in a block can't use block variables
Bram Moolenaar <Bram@vim.org>
parents:
22529
diff
changeset
|
967 /* |
22529
35ef9b0a81a3
patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents:
22391
diff
changeset
|
968 * Find the script-local variable that links to "dest". |
25186
0a3b1c66d3f2
patch 8.2.3129: Vim9: imported uninitialized list does not get type checked
Bram Moolenaar <Bram@vim.org>
parents:
25184
diff
changeset
|
969 * Returns NULL if not found and give an internal error. |
20842
bacc2ab11810
patch 8.2.0973: Vim9: type is not checked when assigning to a script variable
Bram Moolenaar <Bram@vim.org>
parents:
20840
diff
changeset
|
970 */ |
22529
35ef9b0a81a3
patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents:
22391
diff
changeset
|
971 svar_T * |
25186
0a3b1c66d3f2
patch 8.2.3129: Vim9: imported uninitialized list does not get type checked
Bram Moolenaar <Bram@vim.org>
parents:
25184
diff
changeset
|
972 find_typval_in_script(typval_T *dest) |
20842
bacc2ab11810
patch 8.2.0973: Vim9: type is not checked when assigning to a script variable
Bram Moolenaar <Bram@vim.org>
parents:
20840
diff
changeset
|
973 { |
bacc2ab11810
patch 8.2.0973: Vim9: type is not checked when assigning to a script variable
Bram Moolenaar <Bram@vim.org>
parents:
20840
diff
changeset
|
974 scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid); |
bacc2ab11810
patch 8.2.0973: Vim9: type is not checked when assigning to a script variable
Bram Moolenaar <Bram@vim.org>
parents:
20840
diff
changeset
|
975 int idx; |
bacc2ab11810
patch 8.2.0973: Vim9: type is not checked when assigning to a script variable
Bram Moolenaar <Bram@vim.org>
parents:
20840
diff
changeset
|
976 |
21907
f4e21796f47d
patch 8.2.1503: Vim9: error for autocmd defined in :def in legacy script
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
977 if (si->sn_version != SCRIPT_VERSION_VIM9) |
f4e21796f47d
patch 8.2.1503: Vim9: error for autocmd defined in :def in legacy script
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
978 // legacy script doesn't store variable types |
22529
35ef9b0a81a3
patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents:
22391
diff
changeset
|
979 return NULL; |
21907
f4e21796f47d
patch 8.2.1503: Vim9: error for autocmd defined in :def in legacy script
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
980 |
25955
4003fc2340dc
patch 8.2.3511: Vim9: entry for loop variable is created every round
Bram Moolenaar <Bram@vim.org>
parents:
25755
diff
changeset
|
981 // Find the svar_T in sn_var_vals. Start at the end, in a for loop the |
4003fc2340dc
patch 8.2.3511: Vim9: entry for loop variable is created every round
Bram Moolenaar <Bram@vim.org>
parents:
25755
diff
changeset
|
982 // variable was added at the end. |
4003fc2340dc
patch 8.2.3511: Vim9: entry for loop variable is created every round
Bram Moolenaar <Bram@vim.org>
parents:
25755
diff
changeset
|
983 for (idx = si->sn_var_vals.ga_len - 1; idx >= 0; --idx) |
20842
bacc2ab11810
patch 8.2.0973: Vim9: type is not checked when assigning to a script variable
Bram Moolenaar <Bram@vim.org>
parents:
20840
diff
changeset
|
984 { |
bacc2ab11810
patch 8.2.0973: Vim9: type is not checked when assigning to a script variable
Bram Moolenaar <Bram@vim.org>
parents:
20840
diff
changeset
|
985 svar_T *sv = ((svar_T *)si->sn_var_vals.ga_data) + idx; |
bacc2ab11810
patch 8.2.0973: Vim9: type is not checked when assigning to a script variable
Bram Moolenaar <Bram@vim.org>
parents:
20840
diff
changeset
|
986 |
23094
8b93aea8d9d7
patch 8.2.2093: Vim9: script test sometimes fails
Bram Moolenaar <Bram@vim.org>
parents:
22740
diff
changeset
|
987 // If "sv_name" is NULL the variable was hidden when leaving a block, |
8b93aea8d9d7
patch 8.2.2093: Vim9: script test sometimes fails
Bram Moolenaar <Bram@vim.org>
parents:
22740
diff
changeset
|
988 // don't check "sv_tv" then, it might be used for another variable now. |
8b93aea8d9d7
patch 8.2.2093: Vim9: script test sometimes fails
Bram Moolenaar <Bram@vim.org>
parents:
22740
diff
changeset
|
989 if (sv->sv_name != NULL && sv->sv_tv == dest) |
22529
35ef9b0a81a3
patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents:
22391
diff
changeset
|
990 return sv; |
20842
bacc2ab11810
patch 8.2.0973: Vim9: type is not checked when assigning to a script variable
Bram Moolenaar <Bram@vim.org>
parents:
20840
diff
changeset
|
991 } |
25186
0a3b1c66d3f2
patch 8.2.3129: Vim9: imported uninitialized list does not get type checked
Bram Moolenaar <Bram@vim.org>
parents:
25184
diff
changeset
|
992 iemsg("find_typval_in_script(): not found"); |
22529
35ef9b0a81a3
patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents:
22391
diff
changeset
|
993 return NULL; |
35ef9b0a81a3
patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents:
22391
diff
changeset
|
994 } |
35ef9b0a81a3
patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents:
22391
diff
changeset
|
995 |
35ef9b0a81a3
patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents:
22391
diff
changeset
|
996 /* |
35ef9b0a81a3
patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents:
22391
diff
changeset
|
997 * Check if the type of script variable "dest" allows assigning "value". |
35ef9b0a81a3
patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents:
22391
diff
changeset
|
998 * If needed convert "value" to a bool. |
35ef9b0a81a3
patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents:
22391
diff
changeset
|
999 */ |
35ef9b0a81a3
patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents:
22391
diff
changeset
|
1000 int |
23917
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23877
diff
changeset
|
1001 check_script_var_type( |
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23877
diff
changeset
|
1002 typval_T *dest, |
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23877
diff
changeset
|
1003 typval_T *value, |
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23877
diff
changeset
|
1004 char_u *name, |
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23877
diff
changeset
|
1005 where_T where) |
22529
35ef9b0a81a3
patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents:
22391
diff
changeset
|
1006 { |
25186
0a3b1c66d3f2
patch 8.2.3129: Vim9: imported uninitialized list does not get type checked
Bram Moolenaar <Bram@vim.org>
parents:
25184
diff
changeset
|
1007 svar_T *sv = find_typval_in_script(dest); |
22529
35ef9b0a81a3
patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents:
22391
diff
changeset
|
1008 int ret; |
35ef9b0a81a3
patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents:
22391
diff
changeset
|
1009 |
35ef9b0a81a3
patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents:
22391
diff
changeset
|
1010 if (sv != NULL) |
35ef9b0a81a3
patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents:
22391
diff
changeset
|
1011 { |
23578
85ce241ff9e3
patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents:
23458
diff
changeset
|
1012 if (sv->sv_const != 0) |
22529
35ef9b0a81a3
patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents:
22391
diff
changeset
|
1013 { |
25320
1e6da8364a02
patch 8.2.3197: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
25282
diff
changeset
|
1014 semsg(_(e_cannot_change_readonly_variable_str), name); |
22529
35ef9b0a81a3
patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents:
22391
diff
changeset
|
1015 return FAIL; |
35ef9b0a81a3
patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents:
22391
diff
changeset
|
1016 } |
23917
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23877
diff
changeset
|
1017 ret = check_typval_type(sv->sv_type, value, where); |
22529
35ef9b0a81a3
patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents:
22391
diff
changeset
|
1018 if (ret == OK && need_convert_to_bool(sv->sv_type, value)) |
35ef9b0a81a3
patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents:
22391
diff
changeset
|
1019 { |
35ef9b0a81a3
patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents:
22391
diff
changeset
|
1020 int val = tv2bool(value); |
35ef9b0a81a3
patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents:
22391
diff
changeset
|
1021 |
35ef9b0a81a3
patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents:
22391
diff
changeset
|
1022 clear_tv(value); |
35ef9b0a81a3
patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents:
22391
diff
changeset
|
1023 value->v_type = VAR_BOOL; |
35ef9b0a81a3
patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents:
22391
diff
changeset
|
1024 value->v_lock = 0; |
35ef9b0a81a3
patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents:
22391
diff
changeset
|
1025 value->vval.v_number = val ? VVAL_TRUE : VVAL_FALSE; |
35ef9b0a81a3
patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents:
22391
diff
changeset
|
1026 } |
35ef9b0a81a3
patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents:
22391
diff
changeset
|
1027 return ret; |
35ef9b0a81a3
patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents:
22391
diff
changeset
|
1028 } |
35ef9b0a81a3
patch 8.2.1813: Vim9: can assign wrong type to script dict
Bram Moolenaar <Bram@vim.org>
parents:
22391
diff
changeset
|
1029 |
20919
96bf2b304932
patch 8.2.1011: Vim9: some code not tested
Bram Moolenaar <Bram@vim.org>
parents:
20881
diff
changeset
|
1030 return OK; // not really |
20842
bacc2ab11810
patch 8.2.0973: Vim9: type is not checked when assigning to a script variable
Bram Moolenaar <Bram@vim.org>
parents:
20840
diff
changeset
|
1031 } |
20840
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20816
diff
changeset
|
1032 |
24717
bf8feac8a89a
patch 8.2.2897: Vim9: can use reserved words at the script level
Bram Moolenaar <Bram@vim.org>
parents:
24533
diff
changeset
|
1033 // words that cannot be used as a variable |
bf8feac8a89a
patch 8.2.2897: Vim9: can use reserved words at the script level
Bram Moolenaar <Bram@vim.org>
parents:
24533
diff
changeset
|
1034 static char *reserved[] = { |
bf8feac8a89a
patch 8.2.2897: Vim9: can use reserved words at the script level
Bram Moolenaar <Bram@vim.org>
parents:
24533
diff
changeset
|
1035 "true", |
bf8feac8a89a
patch 8.2.2897: Vim9: can use reserved words at the script level
Bram Moolenaar <Bram@vim.org>
parents:
24533
diff
changeset
|
1036 "false", |
bf8feac8a89a
patch 8.2.2897: Vim9: can use reserved words at the script level
Bram Moolenaar <Bram@vim.org>
parents:
24533
diff
changeset
|
1037 "null", |
24888
b6ac4ed5e2d2
patch 8.2.2982: Vim9: future commands are not reserved yet
Bram Moolenaar <Bram@vim.org>
parents:
24717
diff
changeset
|
1038 "this", |
24717
bf8feac8a89a
patch 8.2.2897: Vim9: can use reserved words at the script level
Bram Moolenaar <Bram@vim.org>
parents:
24533
diff
changeset
|
1039 NULL |
bf8feac8a89a
patch 8.2.2897: Vim9: can use reserved words at the script level
Bram Moolenaar <Bram@vim.org>
parents:
24533
diff
changeset
|
1040 }; |
bf8feac8a89a
patch 8.2.2897: Vim9: can use reserved words at the script level
Bram Moolenaar <Bram@vim.org>
parents:
24533
diff
changeset
|
1041 |
bf8feac8a89a
patch 8.2.2897: Vim9: can use reserved words at the script level
Bram Moolenaar <Bram@vim.org>
parents:
24533
diff
changeset
|
1042 int |
bf8feac8a89a
patch 8.2.2897: Vim9: can use reserved words at the script level
Bram Moolenaar <Bram@vim.org>
parents:
24533
diff
changeset
|
1043 check_reserved_name(char_u *name) |
bf8feac8a89a
patch 8.2.2897: Vim9: can use reserved words at the script level
Bram Moolenaar <Bram@vim.org>
parents:
24533
diff
changeset
|
1044 { |
bf8feac8a89a
patch 8.2.2897: Vim9: can use reserved words at the script level
Bram Moolenaar <Bram@vim.org>
parents:
24533
diff
changeset
|
1045 int idx; |
bf8feac8a89a
patch 8.2.2897: Vim9: can use reserved words at the script level
Bram Moolenaar <Bram@vim.org>
parents:
24533
diff
changeset
|
1046 |
bf8feac8a89a
patch 8.2.2897: Vim9: can use reserved words at the script level
Bram Moolenaar <Bram@vim.org>
parents:
24533
diff
changeset
|
1047 for (idx = 0; reserved[idx] != NULL; ++idx) |
bf8feac8a89a
patch 8.2.2897: Vim9: can use reserved words at the script level
Bram Moolenaar <Bram@vim.org>
parents:
24533
diff
changeset
|
1048 if (STRCMP(reserved[idx], name) == 0) |
bf8feac8a89a
patch 8.2.2897: Vim9: can use reserved words at the script level
Bram Moolenaar <Bram@vim.org>
parents:
24533
diff
changeset
|
1049 { |
bf8feac8a89a
patch 8.2.2897: Vim9: can use reserved words at the script level
Bram Moolenaar <Bram@vim.org>
parents:
24533
diff
changeset
|
1050 semsg(_(e_cannot_use_reserved_name), name); |
bf8feac8a89a
patch 8.2.2897: Vim9: can use reserved words at the script level
Bram Moolenaar <Bram@vim.org>
parents:
24533
diff
changeset
|
1051 return FAIL; |
bf8feac8a89a
patch 8.2.2897: Vim9: can use reserved words at the script level
Bram Moolenaar <Bram@vim.org>
parents:
24533
diff
changeset
|
1052 } |
bf8feac8a89a
patch 8.2.2897: Vim9: can use reserved words at the script level
Bram Moolenaar <Bram@vim.org>
parents:
24533
diff
changeset
|
1053 return OK; |
bf8feac8a89a
patch 8.2.2897: Vim9: can use reserved words at the script level
Bram Moolenaar <Bram@vim.org>
parents:
24533
diff
changeset
|
1054 } |
bf8feac8a89a
patch 8.2.2897: Vim9: can use reserved words at the script level
Bram Moolenaar <Bram@vim.org>
parents:
24533
diff
changeset
|
1055 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1056 #endif // FEAT_EVAL |