Mercurial > vim
annotate src/userfunc.c @ 30481:ac6b2ee967f1 v9.0.0576
patch 9.0.0576: unused loop variables
Commit: https://github.com/vim/vim/commit/b2209f213e2931cf3313b24868a9165bbb717cc4
Author: dundargoc <gocdundar@gmail.com>
Date: Sat Sep 24 15:55:27 2022 +0100
patch 9.0.0576: unused loop variables
Problem: Unused loop variables.
Solution: Use a while loop instead. (closes https://github.com/vim/vim/issues/11214)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 24 Sep 2022 17:00:03 +0200 |
parents | b3367a7a3914 |
children | d900f0561eee |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9951
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2 * |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3 * VIM - Vi IMproved by Bram Moolenaar |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4 * |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5 * Do ":help uganda" in Vim to read copying and usage conditions. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6 * Do ":help credits" in Vim to see a list of people who contributed. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
7 * See README.txt for an overview of the Vim source code. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
8 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
9 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
10 /* |
18265
fe5afdc03bd2
patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
18104
diff
changeset
|
11 * userfunc.c: User defined function support |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
12 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
13 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
14 #include "vim.h" |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
15 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
16 #if defined(FEAT_EVAL) || defined(PROTO) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
17 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
18 * All user-defined functions are found in this hashtable. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
19 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
20 static hashtab_T func_hashtab; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
21 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
22 // Used by get_func_tv() |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
23 static garray_T funcargs = GA_EMPTY; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
24 |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
25 // pointer to funccal for currently active function |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
26 static funccall_T *current_funccal = NULL; |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
27 |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
28 // Pointer to list of previously used funccal, still around because some |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
29 // item in it is still being used. |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
30 static funccall_T *previous_funccal = NULL; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
31 |
9735
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
32 static void funccal_unref(funccall_T *fc, ufunc_T *fp, int force); |
24244
827fcf174f15
patch 8.2.2663: Vim9: leaking memory when inline function has an error
Bram Moolenaar <Bram@vim.org>
parents:
24208
diff
changeset
|
33 static void func_clear(ufunc_T *fp, int force); |
827fcf174f15
patch 8.2.2663: Vim9: leaking memory when inline function has an error
Bram Moolenaar <Bram@vim.org>
parents:
24208
diff
changeset
|
34 static int func_free(ufunc_T *fp, int force); |
29320
a74398c432a4
patch 9.0.0003: functions are global while they could be local
Bram Moolenaar <Bram@vim.org>
parents:
29196
diff
changeset
|
35 static char_u *untrans_function_name(char_u *name); |
30122
458162398682
patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents:
30108
diff
changeset
|
36 static void handle_defer_one(funccall_T *funccal); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
37 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
38 void |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
39 func_init() |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
40 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
41 hash_init(&func_hashtab); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
42 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
43 |
9597
3ca0fd9709b1
commit https://github.com/vim/vim/commit/4f0383bc3fe5af0229fb66b53fe94329af783eff
Christian Brabandt <cb@256bit.org>
parents:
9593
diff
changeset
|
44 /* |
17381
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
45 * Return the function hash table |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
46 */ |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
47 hashtab_T * |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
48 func_tbl_get(void) |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
49 { |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
50 return &func_hashtab; |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
51 } |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
52 |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
53 /* |
20029
8fb1cf4c44d5
patch 8.2.0570: Vim9: no error when omitting type from argument
Bram Moolenaar <Bram@vim.org>
parents:
20023
diff
changeset
|
54 * Get one function argument. |
24410
25db91a3281b
patch 8.2.2745: Vim9: missing part of the argument change
Bram Moolenaar <Bram@vim.org>
parents:
24400
diff
changeset
|
55 * If "argtypes" is not NULL also get the type: "arg: type" (:def function). |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
56 * If "types_optional" is TRUE a missing type is OK, use "any". |
24033
308d29307910
patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents:
24004
diff
changeset
|
57 * If "evalarg" is not NULL use it to check for an already declared name. |
27611
e311a80f8cbe
patch 8.2.4332: Vim9: incomplete test for existing script variable in block
Bram Moolenaar <Bram@vim.org>
parents:
27595
diff
changeset
|
58 * If "eap" is not NULL use it to check for an already declared name. |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
59 * Return a pointer to after the type. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
60 * When something is wrong return "arg". |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
61 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
62 static char_u * |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
63 one_function_arg( |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
64 char_u *arg, |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
65 garray_T *newargs, |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
66 garray_T *argtypes, |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
67 int types_optional, |
24033
308d29307910
patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents:
24004
diff
changeset
|
68 evalarg_T *evalarg, |
27611
e311a80f8cbe
patch 8.2.4332: Vim9: incomplete test for existing script variable in block
Bram Moolenaar <Bram@vim.org>
parents:
27595
diff
changeset
|
69 exarg_T *eap, |
24400
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
70 int is_vararg, |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
71 int skip) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
72 { |
20029
8fb1cf4c44d5
patch 8.2.0570: Vim9: no error when omitting type from argument
Bram Moolenaar <Bram@vim.org>
parents:
20023
diff
changeset
|
73 char_u *p = arg; |
8fb1cf4c44d5
patch 8.2.0570: Vim9: no error when omitting type from argument
Bram Moolenaar <Bram@vim.org>
parents:
20023
diff
changeset
|
74 char_u *arg_copy = NULL; |
24410
25db91a3281b
patch 8.2.2745: Vim9: missing part of the argument change
Bram Moolenaar <Bram@vim.org>
parents:
24400
diff
changeset
|
75 int is_underscore = FALSE; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
76 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
77 while (ASCII_ISALNUM(*p) || *p == '_') |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
78 ++p; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
79 if (arg == p || isdigit(*arg) |
22339
56f674e7518c
patch 8.2.1718: Vim9: :def function disallows "firstline" for no good reason
Bram Moolenaar <Bram@vim.org>
parents:
22326
diff
changeset
|
80 || (argtypes == NULL |
56f674e7518c
patch 8.2.1718: Vim9: :def function disallows "firstline" for no good reason
Bram Moolenaar <Bram@vim.org>
parents:
22326
diff
changeset
|
81 && ((p - arg == 9 && STRNCMP(arg, "firstline", 9) == 0) |
56f674e7518c
patch 8.2.1718: Vim9: :def function disallows "firstline" for no good reason
Bram Moolenaar <Bram@vim.org>
parents:
22326
diff
changeset
|
82 || (p - arg == 8 && STRNCMP(arg, "lastline", 8) == 0)))) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
83 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
84 if (!skip) |
26757
3a2b222107a6
patch 8.2.3907: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26747
diff
changeset
|
85 semsg(_(e_illegal_argument_str), arg); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
86 return arg; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
87 } |
23996
c192411b27e8
patch 8.2.2540: Vim9: no error for using script var name for argument
Bram Moolenaar <Bram@vim.org>
parents:
23988
diff
changeset
|
88 |
24033
308d29307910
patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents:
24004
diff
changeset
|
89 // Vim9 script: cannot use script var name for argument. In function: also |
308d29307910
patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents:
24004
diff
changeset
|
90 // check local vars and arguments. |
308d29307910
patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents:
24004
diff
changeset
|
91 if (!skip && argtypes != NULL && check_defined(arg, p - arg, |
27611
e311a80f8cbe
patch 8.2.4332: Vim9: incomplete test for existing script variable in block
Bram Moolenaar <Bram@vim.org>
parents:
27595
diff
changeset
|
92 evalarg == NULL ? NULL : evalarg->eval_cctx, |
e311a80f8cbe
patch 8.2.4332: Vim9: incomplete test for existing script variable in block
Bram Moolenaar <Bram@vim.org>
parents:
27595
diff
changeset
|
93 eap == NULL ? NULL : eap->cstack, TRUE) == FAIL) |
23996
c192411b27e8
patch 8.2.2540: Vim9: no error for using script var name for argument
Bram Moolenaar <Bram@vim.org>
parents:
23988
diff
changeset
|
94 return arg; |
c192411b27e8
patch 8.2.2540: Vim9: no error for using script var name for argument
Bram Moolenaar <Bram@vim.org>
parents:
23988
diff
changeset
|
95 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
96 if (newargs != NULL && ga_grow(newargs, 1) == FAIL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
97 return arg; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
98 if (newargs != NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
99 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
100 int c; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
101 int i; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
102 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
103 c = *p; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
104 *p = NUL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
105 arg_copy = vim_strsave(arg); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
106 if (arg_copy == NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
107 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
108 *p = c; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
109 return arg; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
110 } |
24410
25db91a3281b
patch 8.2.2745: Vim9: missing part of the argument change
Bram Moolenaar <Bram@vim.org>
parents:
24400
diff
changeset
|
111 is_underscore = arg_copy[0] == '_' && arg_copy[1] == NUL; |
24412
0e0943dfdbf9
patch 8.2.2746: check for duplicate arguments does not work
Bram Moolenaar <Bram@vim.org>
parents:
24410
diff
changeset
|
112 if (argtypes == NULL || !is_underscore) |
24410
25db91a3281b
patch 8.2.2745: Vim9: missing part of the argument change
Bram Moolenaar <Bram@vim.org>
parents:
24400
diff
changeset
|
113 // Check for duplicate argument name. |
25db91a3281b
patch 8.2.2745: Vim9: missing part of the argument change
Bram Moolenaar <Bram@vim.org>
parents:
24400
diff
changeset
|
114 for (i = 0; i < newargs->ga_len; ++i) |
25db91a3281b
patch 8.2.2745: Vim9: missing part of the argument change
Bram Moolenaar <Bram@vim.org>
parents:
24400
diff
changeset
|
115 if (STRCMP(((char_u **)(newargs->ga_data))[i], arg_copy) == 0) |
25db91a3281b
patch 8.2.2745: Vim9: missing part of the argument change
Bram Moolenaar <Bram@vim.org>
parents:
24400
diff
changeset
|
116 { |
26962
85866e069c24
patch 8.2.4010: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26958
diff
changeset
|
117 semsg(_(e_duplicate_argument_name_str), arg_copy); |
24410
25db91a3281b
patch 8.2.2745: Vim9: missing part of the argument change
Bram Moolenaar <Bram@vim.org>
parents:
24400
diff
changeset
|
118 vim_free(arg_copy); |
25db91a3281b
patch 8.2.2745: Vim9: missing part of the argument change
Bram Moolenaar <Bram@vim.org>
parents:
24400
diff
changeset
|
119 return arg; |
25db91a3281b
patch 8.2.2745: Vim9: missing part of the argument change
Bram Moolenaar <Bram@vim.org>
parents:
24400
diff
changeset
|
120 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
121 ((char_u **)(newargs->ga_data))[newargs->ga_len] = arg_copy; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
122 newargs->ga_len++; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
123 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
124 *p = c; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
125 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
126 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
127 // get any type from "arg: type" |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
128 if (argtypes != NULL && (skip || ga_grow(argtypes, 1) == OK)) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
129 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
130 char_u *type = NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
131 |
20029
8fb1cf4c44d5
patch 8.2.0570: Vim9: no error when omitting type from argument
Bram Moolenaar <Bram@vim.org>
parents:
20023
diff
changeset
|
132 if (VIM_ISWHITE(*p) && *skipwhite(p) == ':') |
8fb1cf4c44d5
patch 8.2.0570: Vim9: no error when omitting type from argument
Bram Moolenaar <Bram@vim.org>
parents:
20023
diff
changeset
|
133 { |
21821
0deb6f96a5a3
patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
21791
diff
changeset
|
134 semsg(_(e_no_white_space_allowed_before_colon_str), |
20029
8fb1cf4c44d5
patch 8.2.0570: Vim9: no error when omitting type from argument
Bram Moolenaar <Bram@vim.org>
parents:
20023
diff
changeset
|
135 arg_copy == NULL ? arg : arg_copy); |
8fb1cf4c44d5
patch 8.2.0570: Vim9: no error when omitting type from argument
Bram Moolenaar <Bram@vim.org>
parents:
20023
diff
changeset
|
136 p = skipwhite(p); |
8fb1cf4c44d5
patch 8.2.0570: Vim9: no error when omitting type from argument
Bram Moolenaar <Bram@vim.org>
parents:
20023
diff
changeset
|
137 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
138 if (*p == ':') |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
139 { |
20142
fe8d0a4344df
patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20138
diff
changeset
|
140 ++p; |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
141 if (!skip && !VIM_ISWHITE(*p)) |
20142
fe8d0a4344df
patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20138
diff
changeset
|
142 { |
23877
85cf06ddb2a8
patch 8.2.2480: Vim9: some errors for white space do not show context
Bram Moolenaar <Bram@vim.org>
parents:
23829
diff
changeset
|
143 semsg(_(e_white_space_required_after_str_str), ":", p - 1); |
20142
fe8d0a4344df
patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20138
diff
changeset
|
144 return arg; |
fe8d0a4344df
patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20138
diff
changeset
|
145 } |
fe8d0a4344df
patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20138
diff
changeset
|
146 type = skipwhite(p); |
21500
574517d682cf
patch 8.2.1300: Vim9: optional argument type not parsed properly
Bram Moolenaar <Bram@vim.org>
parents:
21479
diff
changeset
|
147 p = skip_type(type, TRUE); |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
148 if (!skip) |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
149 type = vim_strnsave(type, p - type); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
150 } |
24410
25db91a3281b
patch 8.2.2745: Vim9: missing part of the argument change
Bram Moolenaar <Bram@vim.org>
parents:
24400
diff
changeset
|
151 else if (*skipwhite(p) != '=' && !types_optional && !is_underscore) |
20029
8fb1cf4c44d5
patch 8.2.0570: Vim9: no error when omitting type from argument
Bram Moolenaar <Bram@vim.org>
parents:
20023
diff
changeset
|
152 { |
21821
0deb6f96a5a3
patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
21791
diff
changeset
|
153 semsg(_(e_missing_argument_type_for_str), |
20029
8fb1cf4c44d5
patch 8.2.0570: Vim9: no error when omitting type from argument
Bram Moolenaar <Bram@vim.org>
parents:
20023
diff
changeset
|
154 arg_copy == NULL ? arg : arg_copy); |
8fb1cf4c44d5
patch 8.2.0570: Vim9: no error when omitting type from argument
Bram Moolenaar <Bram@vim.org>
parents:
20023
diff
changeset
|
155 return arg; |
8fb1cf4c44d5
patch 8.2.0570: Vim9: no error when omitting type from argument
Bram Moolenaar <Bram@vim.org>
parents:
20023
diff
changeset
|
156 } |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
157 if (!skip) |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
158 { |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
159 if (type == NULL && types_optional) |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
160 // lambda arguments default to "any" type |
24400
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
161 type = vim_strsave((char_u *) |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
162 (is_vararg ? "list<any>" : "any")); |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
163 ((char_u **)argtypes->ga_data)[argtypes->ga_len++] = type; |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
164 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
165 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
166 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
167 return p; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
168 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
169 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
170 /* |
26792
30d8377ea1b1
patch 8.2.3924: Vim9: no error if something follows :enddef
Bram Moolenaar <Bram@vim.org>
parents:
26790
diff
changeset
|
171 * Handle line continuation in function arguments or body. |
27022
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
172 * Get a next line, store it in "eap" if appropriate and put the line in |
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
173 * "lines_to_free" to free the line later. |
26792
30d8377ea1b1
patch 8.2.3924: Vim9: no error if something follows :enddef
Bram Moolenaar <Bram@vim.org>
parents:
26790
diff
changeset
|
174 */ |
30d8377ea1b1
patch 8.2.3924: Vim9: no error if something follows :enddef
Bram Moolenaar <Bram@vim.org>
parents:
26790
diff
changeset
|
175 static char_u * |
30d8377ea1b1
patch 8.2.3924: Vim9: no error if something follows :enddef
Bram Moolenaar <Bram@vim.org>
parents:
26790
diff
changeset
|
176 get_function_line( |
30d8377ea1b1
patch 8.2.3924: Vim9: no error if something follows :enddef
Bram Moolenaar <Bram@vim.org>
parents:
26790
diff
changeset
|
177 exarg_T *eap, |
27022
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
178 garray_T *lines_to_free, |
26800
e0ec45216f05
patch 8.2.3928: heredoc test fails
Bram Moolenaar <Bram@vim.org>
parents:
26798
diff
changeset
|
179 int indent, |
e0ec45216f05
patch 8.2.3928: heredoc test fails
Bram Moolenaar <Bram@vim.org>
parents:
26798
diff
changeset
|
180 getline_opt_T getline_options) |
26792
30d8377ea1b1
patch 8.2.3924: Vim9: no error if something follows :enddef
Bram Moolenaar <Bram@vim.org>
parents:
26790
diff
changeset
|
181 { |
30d8377ea1b1
patch 8.2.3924: Vim9: no error if something follows :enddef
Bram Moolenaar <Bram@vim.org>
parents:
26790
diff
changeset
|
182 char_u *theline; |
30d8377ea1b1
patch 8.2.3924: Vim9: no error if something follows :enddef
Bram Moolenaar <Bram@vim.org>
parents:
26790
diff
changeset
|
183 |
30d8377ea1b1
patch 8.2.3924: Vim9: no error if something follows :enddef
Bram Moolenaar <Bram@vim.org>
parents:
26790
diff
changeset
|
184 if (eap->getline == NULL) |
26804
34f1b7d6974a
patch 8.2.3930: getcmdline() argument has a misleading type
Bram Moolenaar <Bram@vim.org>
parents:
26800
diff
changeset
|
185 theline = getcmdline(':', 0L, indent, 0); |
26792
30d8377ea1b1
patch 8.2.3924: Vim9: no error if something follows :enddef
Bram Moolenaar <Bram@vim.org>
parents:
26790
diff
changeset
|
186 else |
30d8377ea1b1
patch 8.2.3924: Vim9: no error if something follows :enddef
Bram Moolenaar <Bram@vim.org>
parents:
26790
diff
changeset
|
187 theline = eap->getline(':', eap->cookie, indent, getline_options); |
30d8377ea1b1
patch 8.2.3924: Vim9: no error if something follows :enddef
Bram Moolenaar <Bram@vim.org>
parents:
26790
diff
changeset
|
188 if (theline != NULL) |
30d8377ea1b1
patch 8.2.3924: Vim9: no error if something follows :enddef
Bram Moolenaar <Bram@vim.org>
parents:
26790
diff
changeset
|
189 { |
27022
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
190 if (lines_to_free->ga_len > 0 |
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
191 && *eap->cmdlinep == ((char_u **)lines_to_free->ga_data) |
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
192 [lines_to_free->ga_len - 1]) |
26792
30d8377ea1b1
patch 8.2.3924: Vim9: no error if something follows :enddef
Bram Moolenaar <Bram@vim.org>
parents:
26790
diff
changeset
|
193 *eap->cmdlinep = theline; |
27022
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
194 ga_add_string(lines_to_free, theline); |
26792
30d8377ea1b1
patch 8.2.3924: Vim9: no error if something follows :enddef
Bram Moolenaar <Bram@vim.org>
parents:
26790
diff
changeset
|
195 } |
30d8377ea1b1
patch 8.2.3924: Vim9: no error if something follows :enddef
Bram Moolenaar <Bram@vim.org>
parents:
26790
diff
changeset
|
196 |
30d8377ea1b1
patch 8.2.3924: Vim9: no error if something follows :enddef
Bram Moolenaar <Bram@vim.org>
parents:
26790
diff
changeset
|
197 return theline; |
30d8377ea1b1
patch 8.2.3924: Vim9: no error if something follows :enddef
Bram Moolenaar <Bram@vim.org>
parents:
26790
diff
changeset
|
198 } |
30d8377ea1b1
patch 8.2.3924: Vim9: no error if something follows :enddef
Bram Moolenaar <Bram@vim.org>
parents:
26790
diff
changeset
|
199 |
30d8377ea1b1
patch 8.2.3924: Vim9: no error if something follows :enddef
Bram Moolenaar <Bram@vim.org>
parents:
26790
diff
changeset
|
200 /* |
9597
3ca0fd9709b1
commit https://github.com/vim/vim/commit/4f0383bc3fe5af0229fb66b53fe94329af783eff
Christian Brabandt <cb@256bit.org>
parents:
9593
diff
changeset
|
201 * Get function arguments. |
23511
7e8703464f01
patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23446
diff
changeset
|
202 * "argp" should point to just after the "(", possibly to white space. |
23318
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
203 * "argp" is advanced just after "endchar". |
9597
3ca0fd9709b1
commit https://github.com/vim/vim/commit/4f0383bc3fe5af0229fb66b53fe94329af783eff
Christian Brabandt <cb@256bit.org>
parents:
9593
diff
changeset
|
204 */ |
23511
7e8703464f01
patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23446
diff
changeset
|
205 static int |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
206 get_function_args( |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
207 char_u **argp, |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
208 char_u endchar, |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
209 garray_T *newargs, |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
210 garray_T *argtypes, // NULL unless using :def |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
211 int types_optional, // types optional if "argtypes" is not NULL |
24033
308d29307910
patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents:
24004
diff
changeset
|
212 evalarg_T *evalarg, // context or NULL |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
213 int *varargs, |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
214 garray_T *default_args, |
20015
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
215 int skip, |
27611
e311a80f8cbe
patch 8.2.4332: Vim9: incomplete test for existing script variable in block
Bram Moolenaar <Bram@vim.org>
parents:
27595
diff
changeset
|
216 exarg_T *eap, // can be NULL |
27022
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
217 garray_T *lines_to_free) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
218 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
219 int mustend = FALSE; |
23511
7e8703464f01
patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23446
diff
changeset
|
220 char_u *arg; |
7e8703464f01
patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23446
diff
changeset
|
221 char_u *p; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
222 int c; |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
223 int any_default = FALSE; |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
224 char_u *expr; |
23511
7e8703464f01
patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23446
diff
changeset
|
225 char_u *whitep = *argp; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
226 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
227 if (newargs != NULL) |
27028
c9474ae175f4
patch 8.2.4043: using int for second argument of ga_init2()
Bram Moolenaar <Bram@vim.org>
parents:
27022
diff
changeset
|
228 ga_init2(newargs, sizeof(char_u *), 3); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
229 if (argtypes != NULL) |
27028
c9474ae175f4
patch 8.2.4043: using int for second argument of ga_init2()
Bram Moolenaar <Bram@vim.org>
parents:
27022
diff
changeset
|
230 ga_init2(argtypes, sizeof(char_u *), 3); |
25044
a9a21631c090
patch 8.2.3059: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
25042
diff
changeset
|
231 if (!skip && default_args != NULL) |
27028
c9474ae175f4
patch 8.2.4043: using int for second argument of ga_init2()
Bram Moolenaar <Bram@vim.org>
parents:
27022
diff
changeset
|
232 ga_init2(default_args, sizeof(char_u *), 3); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
233 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
234 if (varargs != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
235 *varargs = FALSE; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
236 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
237 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
238 * Isolate the arguments: "arg1, arg2, ...)" |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
239 */ |
23511
7e8703464f01
patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23446
diff
changeset
|
240 arg = skipwhite(*argp); |
7e8703464f01
patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23446
diff
changeset
|
241 p = arg; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
242 while (*p != endchar) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
243 { |
20023
c85d4e173cc9
patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents:
20015
diff
changeset
|
244 while (eap != NULL && eap->getline != NULL |
c85d4e173cc9
patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents:
20015
diff
changeset
|
245 && (*p == NUL || (VIM_ISWHITE(*whitep) && *p == '#'))) |
20015
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
246 { |
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
247 // End of the line, get the next one. |
27022
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
248 char_u *theline = get_function_line(eap, lines_to_free, 0, |
26800
e0ec45216f05
patch 8.2.3928: heredoc test fails
Bram Moolenaar <Bram@vim.org>
parents:
26798
diff
changeset
|
249 GETLINE_CONCAT_CONT); |
26792
30d8377ea1b1
patch 8.2.3924: Vim9: no error if something follows :enddef
Bram Moolenaar <Bram@vim.org>
parents:
26790
diff
changeset
|
250 |
20015
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
251 if (theline == NULL) |
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
252 break; |
20023
c85d4e173cc9
patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents:
20015
diff
changeset
|
253 whitep = (char_u *)" "; |
20015
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
254 p = skipwhite(theline); |
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
255 } |
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
256 |
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
257 if (mustend && *p != endchar) |
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
258 { |
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
259 if (!skip) |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26857
diff
changeset
|
260 semsg(_(e_invalid_argument_str), *argp); |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
261 goto err_ret; |
20015
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
262 } |
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
263 if (*p == endchar) |
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
264 break; |
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
265 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
266 if (p[0] == '.' && p[1] == '.' && p[2] == '.') |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
267 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
268 if (varargs != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
269 *varargs = TRUE; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
270 p += 3; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
271 mustend = TRUE; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
272 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
273 if (argtypes != NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
274 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
275 // ...name: list<type> |
22349
b66a2e046c2e
patch 8.2.1723: Vim9: Variable argument name cannot start with underscore
Bram Moolenaar <Bram@vim.org>
parents:
22339
diff
changeset
|
276 if (!eval_isnamec1(*p)) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
277 { |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
278 if (!skip) |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
279 emsg(_(e_missing_name_after_dots)); |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
280 goto err_ret; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
281 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
282 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
283 arg = p; |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
284 p = one_function_arg(p, newargs, argtypes, types_optional, |
27611
e311a80f8cbe
patch 8.2.4332: Vim9: incomplete test for existing script variable in block
Bram Moolenaar <Bram@vim.org>
parents:
27595
diff
changeset
|
285 evalarg, eap, TRUE, skip); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
286 if (p == arg) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
287 break; |
23879
9ddf1a537fc2
patch 8.2.2481: Vim9: confusing error when variable arguments have default
Bram Moolenaar <Bram@vim.org>
parents:
23877
diff
changeset
|
288 if (*skipwhite(p) == '=') |
9ddf1a537fc2
patch 8.2.2481: Vim9: confusing error when variable arguments have default
Bram Moolenaar <Bram@vim.org>
parents:
23877
diff
changeset
|
289 { |
9ddf1a537fc2
patch 8.2.2481: Vim9: confusing error when variable arguments have default
Bram Moolenaar <Bram@vim.org>
parents:
23877
diff
changeset
|
290 emsg(_(e_cannot_use_default_for_variable_arguments)); |
9ddf1a537fc2
patch 8.2.2481: Vim9: confusing error when variable arguments have default
Bram Moolenaar <Bram@vim.org>
parents:
23877
diff
changeset
|
291 break; |
9ddf1a537fc2
patch 8.2.2481: Vim9: confusing error when variable arguments have default
Bram Moolenaar <Bram@vim.org>
parents:
23877
diff
changeset
|
292 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
293 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
294 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
295 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
296 { |
25042
3f39b6b73019
patch 8.2.3058: Vim9: cannot use ternary operator in parenthesis
Bram Moolenaar <Bram@vim.org>
parents:
25038
diff
changeset
|
297 char_u *np; |
3f39b6b73019
patch 8.2.3058: Vim9: cannot use ternary operator in parenthesis
Bram Moolenaar <Bram@vim.org>
parents:
25038
diff
changeset
|
298 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
299 arg = p; |
24033
308d29307910
patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents:
24004
diff
changeset
|
300 p = one_function_arg(p, newargs, argtypes, types_optional, |
27611
e311a80f8cbe
patch 8.2.4332: Vim9: incomplete test for existing script variable in block
Bram Moolenaar <Bram@vim.org>
parents:
27595
diff
changeset
|
301 evalarg, eap, FALSE, skip); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
302 if (p == arg) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
303 break; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
304 |
25042
3f39b6b73019
patch 8.2.3058: Vim9: cannot use ternary operator in parenthesis
Bram Moolenaar <Bram@vim.org>
parents:
25038
diff
changeset
|
305 // Recognize " = expr" but not " == expr". A lambda can have |
25046
2f702d19013a
patch 8.2.3060: Vim9: cannot use ternary operator in parenthesis
Bram Moolenaar <Bram@vim.org>
parents:
25044
diff
changeset
|
306 // "(a = expr" but "(a == expr" and "(a =~ expr" are not a lambda. |
25042
3f39b6b73019
patch 8.2.3058: Vim9: cannot use ternary operator in parenthesis
Bram Moolenaar <Bram@vim.org>
parents:
25038
diff
changeset
|
307 np = skipwhite(p); |
25046
2f702d19013a
patch 8.2.3060: Vim9: cannot use ternary operator in parenthesis
Bram Moolenaar <Bram@vim.org>
parents:
25044
diff
changeset
|
308 if (*np == '=' && np[1] != '=' && np[1] != '~' |
2f702d19013a
patch 8.2.3060: Vim9: cannot use ternary operator in parenthesis
Bram Moolenaar <Bram@vim.org>
parents:
25044
diff
changeset
|
309 && default_args != NULL) |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
310 { |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
311 typval_T rettv; |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
312 |
19328
e99e6d794597
patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents:
19297
diff
changeset
|
313 // find the end of the expression (doesn't evaluate it) |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
314 any_default = TRUE; |
30079
105f946422d1
patch 9.0.0377: argument assignment does not work
Bram Moolenaar <Bram@vim.org>
parents:
30077
diff
changeset
|
315 p = skipwhite(np + 1); |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
316 expr = p; |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20945
diff
changeset
|
317 if (eval1(&p, &rettv, NULL) != FAIL) |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
318 { |
25044
a9a21631c090
patch 8.2.3059: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
25042
diff
changeset
|
319 if (!skip) |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
320 { |
25044
a9a21631c090
patch 8.2.3059: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
25042
diff
changeset
|
321 if (ga_grow(default_args, 1) == FAIL) |
a9a21631c090
patch 8.2.3059: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
25042
diff
changeset
|
322 goto err_ret; |
a9a21631c090
patch 8.2.3059: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
25042
diff
changeset
|
323 |
a9a21631c090
patch 8.2.3059: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
25042
diff
changeset
|
324 // trim trailing whitespace |
a9a21631c090
patch 8.2.3059: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
25042
diff
changeset
|
325 while (p > expr && VIM_ISWHITE(p[-1])) |
a9a21631c090
patch 8.2.3059: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
25042
diff
changeset
|
326 p--; |
a9a21631c090
patch 8.2.3059: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
25042
diff
changeset
|
327 c = *p; |
a9a21631c090
patch 8.2.3059: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
25042
diff
changeset
|
328 *p = NUL; |
a9a21631c090
patch 8.2.3059: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
25042
diff
changeset
|
329 expr = vim_strsave(expr); |
a9a21631c090
patch 8.2.3059: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
25042
diff
changeset
|
330 if (expr == NULL) |
a9a21631c090
patch 8.2.3059: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
25042
diff
changeset
|
331 { |
a9a21631c090
patch 8.2.3059: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
25042
diff
changeset
|
332 *p = c; |
a9a21631c090
patch 8.2.3059: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
25042
diff
changeset
|
333 goto err_ret; |
a9a21631c090
patch 8.2.3059: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
25042
diff
changeset
|
334 } |
a9a21631c090
patch 8.2.3059: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
25042
diff
changeset
|
335 ((char_u **)(default_args->ga_data)) |
a9a21631c090
patch 8.2.3059: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
25042
diff
changeset
|
336 [default_args->ga_len] = expr; |
a9a21631c090
patch 8.2.3059: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
25042
diff
changeset
|
337 default_args->ga_len++; |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
338 *p = c; |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
339 } |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
340 } |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
341 else |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
342 mustend = TRUE; |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
343 } |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
344 else if (any_default) |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
345 { |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
346 emsg(_(e_non_default_argument_follows_default_argument)); |
21263
71bd2f9adb61
patch 8.2.1182: Vim9: no check for whitespace after comma in lambda
Bram Moolenaar <Bram@vim.org>
parents:
21222
diff
changeset
|
347 goto err_ret; |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
348 } |
24371
2b4883926a24
patch 8.2.2726: confusing error message with white space before comma
Bram Moolenaar <Bram@vim.org>
parents:
24272
diff
changeset
|
349 |
2b4883926a24
patch 8.2.2726: confusing error message with white space before comma
Bram Moolenaar <Bram@vim.org>
parents:
24272
diff
changeset
|
350 if (VIM_ISWHITE(*p) && *skipwhite(p) == ',') |
2b4883926a24
patch 8.2.2726: confusing error message with white space before comma
Bram Moolenaar <Bram@vim.org>
parents:
24272
diff
changeset
|
351 { |
2b4883926a24
patch 8.2.2726: confusing error message with white space before comma
Bram Moolenaar <Bram@vim.org>
parents:
24272
diff
changeset
|
352 // Be tolerant when skipping |
2b4883926a24
patch 8.2.2726: confusing error message with white space before comma
Bram Moolenaar <Bram@vim.org>
parents:
24272
diff
changeset
|
353 if (!skip) |
2b4883926a24
patch 8.2.2726: confusing error message with white space before comma
Bram Moolenaar <Bram@vim.org>
parents:
24272
diff
changeset
|
354 { |
2b4883926a24
patch 8.2.2726: confusing error message with white space before comma
Bram Moolenaar <Bram@vim.org>
parents:
24272
diff
changeset
|
355 semsg(_(e_no_white_space_allowed_before_str_str), ",", p); |
2b4883926a24
patch 8.2.2726: confusing error message with white space before comma
Bram Moolenaar <Bram@vim.org>
parents:
24272
diff
changeset
|
356 goto err_ret; |
2b4883926a24
patch 8.2.2726: confusing error message with white space before comma
Bram Moolenaar <Bram@vim.org>
parents:
24272
diff
changeset
|
357 } |
2b4883926a24
patch 8.2.2726: confusing error message with white space before comma
Bram Moolenaar <Bram@vim.org>
parents:
24272
diff
changeset
|
358 p = skipwhite(p); |
2b4883926a24
patch 8.2.2726: confusing error message with white space before comma
Bram Moolenaar <Bram@vim.org>
parents:
24272
diff
changeset
|
359 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
360 if (*p == ',') |
21263
71bd2f9adb61
patch 8.2.1182: Vim9: no check for whitespace after comma in lambda
Bram Moolenaar <Bram@vim.org>
parents:
21222
diff
changeset
|
361 { |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
362 ++p; |
21263
71bd2f9adb61
patch 8.2.1182: Vim9: no check for whitespace after comma in lambda
Bram Moolenaar <Bram@vim.org>
parents:
21222
diff
changeset
|
363 // Don't give this error when skipping, it makes the "->" not |
71bd2f9adb61
patch 8.2.1182: Vim9: no check for whitespace after comma in lambda
Bram Moolenaar <Bram@vim.org>
parents:
21222
diff
changeset
|
364 // found in "{k,v -> x}" and give a confusing error. |
24069
324408c61b20
patch 8.2.2576: Vim9: defining a :func function checks for white space
Bram Moolenaar <Bram@vim.org>
parents:
24033
diff
changeset
|
365 // Allow missing space after comma in legacy functions. |
324408c61b20
patch 8.2.2576: Vim9: defining a :func function checks for white space
Bram Moolenaar <Bram@vim.org>
parents:
24033
diff
changeset
|
366 if (!skip && argtypes != NULL |
21263
71bd2f9adb61
patch 8.2.1182: Vim9: no check for whitespace after comma in lambda
Bram Moolenaar <Bram@vim.org>
parents:
21222
diff
changeset
|
367 && !IS_WHITE_OR_NUL(*p) && *p != endchar) |
71bd2f9adb61
patch 8.2.1182: Vim9: no check for whitespace after comma in lambda
Bram Moolenaar <Bram@vim.org>
parents:
21222
diff
changeset
|
368 { |
23877
85cf06ddb2a8
patch 8.2.2480: Vim9: some errors for white space do not show context
Bram Moolenaar <Bram@vim.org>
parents:
23829
diff
changeset
|
369 semsg(_(e_white_space_required_after_str_str), ",", p - 1); |
21263
71bd2f9adb61
patch 8.2.1182: Vim9: no check for whitespace after comma in lambda
Bram Moolenaar <Bram@vim.org>
parents:
21222
diff
changeset
|
370 goto err_ret; |
71bd2f9adb61
patch 8.2.1182: Vim9: no check for whitespace after comma in lambda
Bram Moolenaar <Bram@vim.org>
parents:
21222
diff
changeset
|
371 } |
71bd2f9adb61
patch 8.2.1182: Vim9: no check for whitespace after comma in lambda
Bram Moolenaar <Bram@vim.org>
parents:
21222
diff
changeset
|
372 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
373 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
374 mustend = TRUE; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
375 } |
20023
c85d4e173cc9
patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents:
20015
diff
changeset
|
376 whitep = p; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
377 p = skipwhite(p); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
378 } |
20015
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
379 |
9597
3ca0fd9709b1
commit https://github.com/vim/vim/commit/4f0383bc3fe5af0229fb66b53fe94329af783eff
Christian Brabandt <cb@256bit.org>
parents:
9593
diff
changeset
|
380 if (*p != endchar) |
3ca0fd9709b1
commit https://github.com/vim/vim/commit/4f0383bc3fe5af0229fb66b53fe94329af783eff
Christian Brabandt <cb@256bit.org>
parents:
9593
diff
changeset
|
381 goto err_ret; |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
382 ++p; // skip "endchar" |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
383 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
384 *argp = p; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
385 return OK; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
386 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
387 err_ret: |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
388 if (newargs != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
389 ga_clear_strings(newargs); |
25044
a9a21631c090
patch 8.2.3059: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
25042
diff
changeset
|
390 if (!skip && default_args != NULL) |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
391 ga_clear_strings(default_args); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
392 return FAIL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
393 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
394 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
395 /* |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
396 * Parse the argument types, filling "fp->uf_arg_types". |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
397 * Return OK or FAIL. |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
398 */ |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
399 static int |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
400 parse_argument_types(ufunc_T *fp, garray_T *argtypes, int varargs) |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
401 { |
24400
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
402 int len = 0; |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
403 |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
404 ga_init2(&fp->uf_type_list, sizeof(type_T *), 10); |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
405 if (argtypes->ga_len > 0) |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
406 { |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
407 // When "varargs" is set the last name/type goes into uf_va_name |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
408 // and uf_va_type. |
24400
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
409 len = argtypes->ga_len - (varargs ? 1 : 0); |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
410 |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
411 if (len > 0) |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
412 fp->uf_arg_types = ALLOC_CLEAR_MULT(type_T *, len); |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
413 if (fp->uf_arg_types != NULL) |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
414 { |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
415 int i; |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
416 type_T *type; |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
417 |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
418 for (i = 0; i < len; ++ i) |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
419 { |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
420 char_u *p = ((char_u **)argtypes->ga_data)[i]; |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
421 |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
422 if (p == NULL) |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
423 // will get the type from the default value |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
424 type = &t_unknown; |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
425 else |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
426 type = parse_type(&p, &fp->uf_type_list, TRUE); |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
427 if (type == NULL) |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
428 return FAIL; |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
429 fp->uf_arg_types[i] = type; |
28123
e5fcd1256ee3
patch 8.2.4586: Vim9: no error for using lower case name for "func" argument
Bram Moolenaar <Bram@vim.org>
parents:
28047
diff
changeset
|
430 if (i < fp->uf_args.ga_len |
e5fcd1256ee3
patch 8.2.4586: Vim9: no error for using lower case name for "func" argument
Bram Moolenaar <Bram@vim.org>
parents:
28047
diff
changeset
|
431 && (type->tt_type == VAR_FUNC |
e5fcd1256ee3
patch 8.2.4586: Vim9: no error for using lower case name for "func" argument
Bram Moolenaar <Bram@vim.org>
parents:
28047
diff
changeset
|
432 || type->tt_type == VAR_PARTIAL) |
e5fcd1256ee3
patch 8.2.4586: Vim9: no error for using lower case name for "func" argument
Bram Moolenaar <Bram@vim.org>
parents:
28047
diff
changeset
|
433 && var_wrong_func_name( |
e5fcd1256ee3
patch 8.2.4586: Vim9: no error for using lower case name for "func" argument
Bram Moolenaar <Bram@vim.org>
parents:
28047
diff
changeset
|
434 ((char_u **)fp->uf_args.ga_data)[i], TRUE)) |
e5fcd1256ee3
patch 8.2.4586: Vim9: no error for using lower case name for "func" argument
Bram Moolenaar <Bram@vim.org>
parents:
28047
diff
changeset
|
435 return FAIL; |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
436 } |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
437 } |
24400
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
438 } |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
439 |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
440 if (varargs) |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
441 { |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
442 char_u *p; |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
443 |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
444 // Move the last argument "...name: type" to uf_va_name and |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
445 // uf_va_type. |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
446 fp->uf_va_name = ((char_u **)fp->uf_args.ga_data) |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
447 [fp->uf_args.ga_len - 1]; |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
448 --fp->uf_args.ga_len; |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
449 p = ((char_u **)argtypes->ga_data)[len]; |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
450 if (p == NULL) |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
451 // TODO: get type from default value |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
452 fp->uf_va_type = &t_list_any; |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
453 else |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
454 { |
24400
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
455 fp->uf_va_type = parse_type(&p, &fp->uf_type_list, TRUE); |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
456 if (fp->uf_va_type != NULL && fp->uf_va_type->tt_type != VAR_LIST) |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
457 { |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
458 semsg(_(e_variable_arguments_type_must_be_list_str), |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
459 ((char_u **)argtypes->ga_data)[len]); |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
460 return FAIL; |
24400
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
461 } |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
462 } |
24400
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
463 if (fp->uf_va_type == NULL) |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
464 return FAIL; |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
465 } |
24400
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
466 |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
467 return OK; |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
468 } |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
469 |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
470 static int |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
471 parse_return_type(ufunc_T *fp, char_u *ret_type) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
472 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
473 if (ret_type == NULL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
474 fp->uf_ret_type = &t_void; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
475 else |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
476 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
477 char_u *p = ret_type; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
478 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
479 fp->uf_ret_type = parse_type(&p, &fp->uf_type_list, TRUE); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
480 if (fp->uf_ret_type == NULL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
481 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
482 fp->uf_ret_type = &t_void; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
483 return FAIL; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
484 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
485 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
486 return OK; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
487 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
488 |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
489 /* |
9721
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
490 * Register function "fp" as using "current_funccal" as its scope. |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
491 */ |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
492 static int |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
493 register_closure(ufunc_T *fp) |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
494 { |
9733
59565cdd7261
commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents:
9731
diff
changeset
|
495 if (fp->uf_scoped == current_funccal) |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
496 // no change |
9733
59565cdd7261
commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents:
9731
diff
changeset
|
497 return OK; |
9735
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
498 funccal_unref(fp->uf_scoped, fp, FALSE); |
9721
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
499 fp->uf_scoped = current_funccal; |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
500 current_funccal->fc_refcount++; |
9733
59565cdd7261
commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents:
9731
diff
changeset
|
501 |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
502 if (ga_grow(¤t_funccal->fc_ufuncs, 1) == FAIL) |
9721
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
503 return FAIL; |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
504 ((ufunc_T **)current_funccal->fc_ufuncs.ga_data) |
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
505 [current_funccal->fc_ufuncs.ga_len++] = fp; |
9721
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
506 return OK; |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
507 } |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
508 |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
509 static void |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
510 set_ufunc_name(ufunc_T *fp, char_u *name) |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
511 { |
23829
950875545045
patch 8.2.2456: Coverity warning for strcpy() into fixed size array
Bram Moolenaar <Bram@vim.org>
parents:
23808
diff
changeset
|
512 // Add a type cast to avoid a warning for an overflow, the uf_name[] array |
950875545045
patch 8.2.2456: Coverity warning for strcpy() into fixed size array
Bram Moolenaar <Bram@vim.org>
parents:
23808
diff
changeset
|
513 // actually extends beyond the struct. |
950875545045
patch 8.2.2456: Coverity warning for strcpy() into fixed size array
Bram Moolenaar <Bram@vim.org>
parents:
23808
diff
changeset
|
514 STRCPY((void *)fp->uf_name, name); |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
515 |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
516 if (name[0] == K_SPECIAL) |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
517 { |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
518 fp->uf_name_exp = alloc(STRLEN(name) + 3); |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
519 if (fp->uf_name_exp != NULL) |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
520 { |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
521 STRCPY(fp->uf_name_exp, "<SNR>"); |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
522 STRCAT(fp->uf_name_exp, fp->uf_name + 3); |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
523 } |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
524 } |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
525 } |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
526 |
9721
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
527 /* |
28263
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28249
diff
changeset
|
528 * If "name" starts with K_SPECIAL and "buf[bufsize]" is big enough |
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28249
diff
changeset
|
529 * return "buf" filled with a readable function name. |
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28249
diff
changeset
|
530 * Otherwise just return "name", thus the return value can always be used. |
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28249
diff
changeset
|
531 * "name" and "buf" may be equal. |
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28249
diff
changeset
|
532 */ |
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28249
diff
changeset
|
533 char_u * |
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28249
diff
changeset
|
534 make_ufunc_name_readable(char_u *name, char_u *buf, size_t bufsize) |
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28249
diff
changeset
|
535 { |
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28249
diff
changeset
|
536 size_t len; |
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28249
diff
changeset
|
537 |
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28249
diff
changeset
|
538 if (name[0] != K_SPECIAL) |
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28249
diff
changeset
|
539 return name; |
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28249
diff
changeset
|
540 len = STRLEN(name); |
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28249
diff
changeset
|
541 if (len + 3 > bufsize) |
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28249
diff
changeset
|
542 return name; |
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28249
diff
changeset
|
543 |
28267
39a833e69bf3
patch 8.2.4659: invalid memory access when using printable function name
Bram Moolenaar <Bram@vim.org>
parents:
28263
diff
changeset
|
544 mch_memmove(buf + 5, name + 3, len - 2); // Include trailing NUL |
28263
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28249
diff
changeset
|
545 mch_memmove(buf, "<SNR>", 5); |
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28249
diff
changeset
|
546 return buf; |
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28249
diff
changeset
|
547 } |
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28249
diff
changeset
|
548 |
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28249
diff
changeset
|
549 /* |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
550 * Get a name for a lambda. Returned in static memory. |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
551 */ |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
552 char_u * |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
553 get_lambda_name(void) |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
554 { |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
555 static char_u name[30]; |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
556 static int lambda_no = 0; |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
557 |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
558 sprintf((char*)name, "<lambda>%d", ++lambda_no); |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
559 return name; |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
560 } |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
561 |
21006
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
562 #if defined(FEAT_LUA) || defined(PROTO) |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
563 /* |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
564 * Registers a native C callback which can be called from Vim script. |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
565 * Returns the name of the Vim script function. |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
566 */ |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
567 char_u * |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
568 register_cfunc(cfunc_T cb, cfunc_free_T cb_free, void *state) |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
569 { |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
570 char_u *name = get_lambda_name(); |
21066
48cfc37fe4fc
patch 8.2.1084: Lua: registering function has useless code
Bram Moolenaar <Bram@vim.org>
parents:
21058
diff
changeset
|
571 ufunc_T *fp; |
21006
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
572 |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
573 fp = alloc_clear(offsetof(ufunc_T, uf_name) + STRLEN(name) + 1); |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
574 if (fp == NULL) |
21066
48cfc37fe4fc
patch 8.2.1084: Lua: registering function has useless code
Bram Moolenaar <Bram@vim.org>
parents:
21058
diff
changeset
|
575 return NULL; |
21006
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
576 |
21558
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21552
diff
changeset
|
577 fp->uf_def_status = UF_NOT_COMPILED; |
21006
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
578 fp->uf_refcount = 1; |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
579 fp->uf_varargs = TRUE; |
26323
3841da4eac23
patch 8.2.3692: Vim9: cannot use :func inside a :def function
Bram Moolenaar <Bram@vim.org>
parents:
26205
diff
changeset
|
580 fp->uf_flags = FC_CFUNC | FC_LAMBDA; |
21006
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
581 fp->uf_calls = 0; |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
582 fp->uf_script_ctx = current_sctx; |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
583 fp->uf_cb = cb; |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
584 fp->uf_cb_free = cb_free; |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
585 fp->uf_cb_state = state; |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
586 |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
587 set_ufunc_name(fp, name); |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
588 hash_add(&func_hashtab, UF2HIKEY(fp)); |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
589 |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
590 return name; |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
591 } |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
592 #endif |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
593 |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
594 /* |
23318
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
595 * Skip over "->" or "=>" after the arguments of a lambda. |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
596 * If ": type" is found make "ret_type" point to "type". |
23338
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
597 * If "white_error" is not NULL check for correct use of white space and set |
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
598 * "white_error" to TRUE if there is an error. |
23318
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
599 * Return NULL if no valid arrow found. |
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
600 */ |
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
601 static char_u * |
23338
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
602 skip_arrow( |
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
603 char_u *start, |
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
604 int equal_arrow, |
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
605 char_u **ret_type, |
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
606 int *white_error) |
23318
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
607 { |
23338
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
608 char_u *s = start; |
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
609 char_u *bef = start - 2; // "start" points to > of -> |
23318
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
610 |
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
611 if (equal_arrow) |
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
612 { |
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
613 if (*s == ':') |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
614 { |
23338
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
615 if (white_error != NULL && !VIM_ISWHITE(s[1])) |
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
616 { |
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
617 *white_error = TRUE; |
23877
85cf06ddb2a8
patch 8.2.2480: Vim9: some errors for white space do not show context
Bram Moolenaar <Bram@vim.org>
parents:
23829
diff
changeset
|
618 semsg(_(e_white_space_required_after_str_str), ":", s); |
23338
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
619 return NULL; |
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
620 } |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
621 s = skipwhite(s + 1); |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
622 *ret_type = s; |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
623 s = skip_type(s, TRUE); |
23808
baf9069f64ca
patch 8.2.2445: Vim9: no proper error for lambda missing return type
Bram Moolenaar <Bram@vim.org>
parents:
23727
diff
changeset
|
624 if (s == *ret_type) |
baf9069f64ca
patch 8.2.2445: Vim9: no proper error for lambda missing return type
Bram Moolenaar <Bram@vim.org>
parents:
23727
diff
changeset
|
625 { |
baf9069f64ca
patch 8.2.2445: Vim9: no proper error for lambda missing return type
Bram Moolenaar <Bram@vim.org>
parents:
23727
diff
changeset
|
626 emsg(_(e_missing_return_type)); |
baf9069f64ca
patch 8.2.2445: Vim9: no proper error for lambda missing return type
Bram Moolenaar <Bram@vim.org>
parents:
23727
diff
changeset
|
627 return NULL; |
baf9069f64ca
patch 8.2.2445: Vim9: no proper error for lambda missing return type
Bram Moolenaar <Bram@vim.org>
parents:
23727
diff
changeset
|
628 } |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
629 } |
23338
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
630 bef = s; |
23318
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
631 s = skipwhite(s); |
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
632 if (*s != '=') |
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
633 return NULL; |
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
634 ++s; |
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
635 } |
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
636 if (*s != '>') |
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
637 return NULL; |
23338
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
638 if (white_error != NULL && ((!VIM_ISWHITE(*bef) && *bef != '{') |
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
639 || !IS_WHITE_OR_NUL(s[1]))) |
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
640 { |
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
641 *white_error = TRUE; |
23446
b1dbbc81a011
patch 8.2.2266: Vim9: it can be hard to see where white space is missing
Bram Moolenaar <Bram@vim.org>
parents:
23444
diff
changeset
|
642 semsg(_(e_white_space_required_before_and_after_str_at_str), |
b1dbbc81a011
patch 8.2.2266: Vim9: it can be hard to see where white space is missing
Bram Moolenaar <Bram@vim.org>
parents:
23444
diff
changeset
|
643 equal_arrow ? "=>" : "->", bef); |
23338
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
644 return NULL; |
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
645 } |
23318
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
646 return skipwhite(s + 1); |
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
647 } |
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
648 |
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
649 /* |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
650 * Check if "*cmd" points to a function command and if so advance "*cmd" and |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
651 * return TRUE. |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
652 * Otherwise return FALSE; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
653 * Do not consider "function(" to be a command. |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
654 */ |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
655 static int |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
656 is_function_cmd(char_u **cmd) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
657 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
658 char_u *p = *cmd; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
659 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
660 if (checkforcmd(&p, "function", 2)) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
661 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
662 if (*p == '(') |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
663 return FALSE; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
664 *cmd = p; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
665 return TRUE; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
666 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
667 return FALSE; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
668 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
669 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
670 /* |
25358
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
671 * Called when defining a function: The context may be needed for script |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
672 * variables declared in a block that is visible now but not when the function |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
673 * is compiled or called later. |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
674 */ |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
675 static void |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
676 function_using_block_scopes(ufunc_T *fp, cstack_T *cstack) |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
677 { |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
678 if (cstack != NULL && cstack->cs_idx >= 0) |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
679 { |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
680 int count = cstack->cs_idx + 1; |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
681 int i; |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
682 |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
683 fp->uf_block_ids = ALLOC_MULT(int, count); |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
684 if (fp->uf_block_ids != NULL) |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
685 { |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
686 mch_memmove(fp->uf_block_ids, cstack->cs_block_id, |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
687 sizeof(int) * count); |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
688 fp->uf_block_depth = count; |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
689 } |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
690 |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
691 // Set flag in each block to indicate a function was defined. This |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
692 // is used to keep the variable when leaving the block, see |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
693 // hide_script_var(). |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
694 for (i = 0; i <= cstack->cs_idx; ++i) |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
695 cstack->cs_flags[i] |= CSF_FUNC_DEF; |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
696 } |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
697 } |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
698 |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
699 /* |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
700 * Read the body of a function, put every line in "newlines". |
24651
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
701 * This stops at "}", "endfunction" or "enddef". |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
702 * "newlines" must already have been initialized. |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
703 * "eap->cmdidx" is CMD_function, CMD_def or CMD_block; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
704 */ |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
705 static int |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
706 get_function_body( |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
707 exarg_T *eap, |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
708 garray_T *newlines, |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
709 char_u *line_arg_in, |
27022
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
710 garray_T *lines_to_free) |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
711 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
712 linenr_T sourcing_lnum_top = SOURCING_LNUM; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
713 linenr_T sourcing_lnum_off; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
714 int saved_wait_return = need_wait_return; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
715 char_u *line_arg = line_arg_in; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
716 int vim9_function = eap->cmdidx == CMD_def |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
717 || eap->cmdidx == CMD_block; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
718 #define MAX_FUNC_NESTING 50 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
719 char nesting_def[MAX_FUNC_NESTING]; |
25265
1d6ff96306fc
patch 8.2.3169: Vim9: cannot handle nested inline function
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
720 char nesting_inline[MAX_FUNC_NESTING]; |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
721 int nesting = 0; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
722 getline_opt_T getline_options; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
723 int indent = 2; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
724 char_u *skip_until = NULL; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
725 int ret = FAIL; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
726 int is_heredoc = FALSE; |
24826
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
727 int heredoc_concat_len = 0; |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
728 garray_T heredoc_ga; |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
729 char_u *heredoc_trimmed = NULL; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
730 |
24826
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
731 ga_init2(&heredoc_ga, 1, 500); |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
732 |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
733 // Detect having skipped over comment lines to find the return |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
734 // type. Add NULL lines to keep the line count correct. |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
735 sourcing_lnum_off = get_sourced_lnum(eap->getline, eap->cookie); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
736 if (SOURCING_LNUM < sourcing_lnum_off) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
737 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
738 sourcing_lnum_off -= SOURCING_LNUM; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
739 if (ga_grow(newlines, sourcing_lnum_off) == FAIL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
740 goto theend; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
741 while (sourcing_lnum_off-- > 0) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
742 ((char_u **)(newlines->ga_data))[newlines->ga_len++] = NULL; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
743 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
744 |
25265
1d6ff96306fc
patch 8.2.3169: Vim9: cannot handle nested inline function
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
745 nesting_def[0] = vim9_function; |
1d6ff96306fc
patch 8.2.3169: Vim9: cannot handle nested inline function
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
746 nesting_inline[0] = eap->cmdidx == CMD_block; |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
747 getline_options = vim9_function |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
748 ? GETLINE_CONCAT_CONTBAR : GETLINE_CONCAT_CONT; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
749 for (;;) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
750 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
751 char_u *theline; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
752 char_u *p; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
753 char_u *arg; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
754 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
755 if (KeyTyped) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
756 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
757 msg_scroll = TRUE; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
758 saved_wait_return = FALSE; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
759 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
760 need_wait_return = FALSE; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
761 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
762 if (line_arg != NULL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
763 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
764 // Use eap->arg, split up in parts by line breaks. |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
765 theline = line_arg; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
766 p = vim_strchr(theline, '\n'); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
767 if (p == NULL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
768 line_arg += STRLEN(line_arg); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
769 else |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
770 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
771 *p = NUL; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
772 line_arg = p + 1; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
773 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
774 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
775 else |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
776 { |
27022
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
777 theline = get_function_line(eap, lines_to_free, indent, |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
778 getline_options); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
779 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
780 if (KeyTyped) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
781 lines_left = Rows - 1; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
782 if (theline == NULL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
783 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
784 // Use the start of the function for the line number. |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
785 SOURCING_LNUM = sourcing_lnum_top; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
786 if (skip_until != NULL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
787 semsg(_(e_missing_heredoc_end_marker_str), skip_until); |
25265
1d6ff96306fc
patch 8.2.3169: Vim9: cannot handle nested inline function
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
788 else if (nesting_inline[nesting]) |
1d6ff96306fc
patch 8.2.3169: Vim9: cannot handle nested inline function
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
789 emsg(_(e_missing_end_block)); |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
790 else if (eap->cmdidx == CMD_def) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
791 emsg(_(e_missing_enddef)); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
792 else |
26757
3a2b222107a6
patch 8.2.3907: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26747
diff
changeset
|
793 emsg(_(e_missing_endfunction)); |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
794 goto theend; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
795 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
796 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
797 // Detect line continuation: SOURCING_LNUM increased more than one. |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
798 sourcing_lnum_off = get_sourced_lnum(eap->getline, eap->cookie); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
799 if (SOURCING_LNUM < sourcing_lnum_off) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
800 sourcing_lnum_off -= SOURCING_LNUM; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
801 else |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
802 sourcing_lnum_off = 0; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
803 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
804 if (skip_until != NULL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
805 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
806 // Don't check for ":endfunc"/":enddef" between |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
807 // * ":append" and "." |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
808 // * ":python <<EOF" and "EOF" |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
809 // * ":let {var-name} =<< [trim] {marker}" and "{marker}" |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
810 if (heredoc_trimmed == NULL |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
811 || (is_heredoc && skipwhite(theline) == theline) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
812 || STRNCMP(theline, heredoc_trimmed, |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
813 STRLEN(heredoc_trimmed)) == 0) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
814 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
815 if (heredoc_trimmed == NULL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
816 p = theline; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
817 else if (is_heredoc) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
818 p = skipwhite(theline) == theline |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
819 ? theline : theline + STRLEN(heredoc_trimmed); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
820 else |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
821 p = theline + STRLEN(heredoc_trimmed); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
822 if (STRCMP(p, skip_until) == 0) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
823 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
824 VIM_CLEAR(skip_until); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
825 VIM_CLEAR(heredoc_trimmed); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
826 getline_options = vim9_function |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
827 ? GETLINE_CONCAT_CONTBAR : GETLINE_CONCAT_CONT; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
828 is_heredoc = FALSE; |
24826
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
829 |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
830 if (heredoc_concat_len > 0) |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
831 { |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
832 // Replace the starting line with all the concatenated |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
833 // lines. |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
834 ga_concat(&heredoc_ga, theline); |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
835 vim_free(((char_u **)(newlines->ga_data))[ |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
836 heredoc_concat_len - 1]); |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
837 ((char_u **)(newlines->ga_data))[ |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
838 heredoc_concat_len - 1] = heredoc_ga.ga_data; |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
839 ga_init(&heredoc_ga); |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
840 heredoc_concat_len = 0; |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
841 theline += STRLEN(theline); // skip the "EOF" |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
842 } |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
843 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
844 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
845 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
846 else |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
847 { |
25265
1d6ff96306fc
patch 8.2.3169: Vim9: cannot handle nested inline function
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
848 int c; |
1d6ff96306fc
patch 8.2.3169: Vim9: cannot handle nested inline function
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
849 char_u *end; |
27978
442ca2007bec
patch 8.2.4514: Vim9: some flow commands can be shortened
Bram Moolenaar <Bram@vim.org>
parents:
27893
diff
changeset
|
850 char_u *cmd; |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
851 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
852 // skip ':' and blanks |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
853 for (p = theline; VIM_ISWHITE(*p) || *p == ':'; ++p) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
854 ; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
855 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
856 // Check for "endfunction", "enddef" or "}". |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
857 // When a ":" follows it must be a dict key; "enddef: value," |
27978
442ca2007bec
patch 8.2.4514: Vim9: some flow commands can be shortened
Bram Moolenaar <Bram@vim.org>
parents:
27893
diff
changeset
|
858 cmd = p; |
25265
1d6ff96306fc
patch 8.2.3169: Vim9: cannot handle nested inline function
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
859 if (nesting_inline[nesting] |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
860 ? *p == '}' |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
861 : (checkforcmd(&p, nesting_def[nesting] |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
862 ? "enddef" : "endfunction", 4) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
863 && *p != ':')) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
864 { |
27978
442ca2007bec
patch 8.2.4514: Vim9: some flow commands can be shortened
Bram Moolenaar <Bram@vim.org>
parents:
27893
diff
changeset
|
865 if (!nesting_inline[nesting] && nesting_def[nesting] |
442ca2007bec
patch 8.2.4514: Vim9: some flow commands can be shortened
Bram Moolenaar <Bram@vim.org>
parents:
27893
diff
changeset
|
866 && p < cmd + 6) |
442ca2007bec
patch 8.2.4514: Vim9: some flow commands can be shortened
Bram Moolenaar <Bram@vim.org>
parents:
27893
diff
changeset
|
867 semsg(_(e_command_cannot_be_shortened_str), "enddef"); |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
868 if (nesting-- == 0) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
869 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
870 char_u *nextcmd = NULL; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
871 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
872 if (*p == '|' || *p == '}') |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
873 nextcmd = p + 1; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
874 else if (line_arg != NULL && *skipwhite(line_arg) != NUL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
875 nextcmd = line_arg; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
876 else if (*p != NUL && *p != (vim9_function ? '#' : '"') |
24208
7a21b2581dce
patch 8.2.2645: using inline function is not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
24202
diff
changeset
|
877 && (vim9_function || p_verbose > 0)) |
7a21b2581dce
patch 8.2.2645: using inline function is not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
24202
diff
changeset
|
878 { |
25632
c204815f3058
patch 8.2.3352: Vim9: error for nested :enddef has wrong line number
Bram Moolenaar <Bram@vim.org>
parents:
25561
diff
changeset
|
879 SOURCING_LNUM = sourcing_lnum_top |
c204815f3058
patch 8.2.3352: Vim9: error for nested :enddef has wrong line number
Bram Moolenaar <Bram@vim.org>
parents:
25561
diff
changeset
|
880 + newlines->ga_len + 1; |
24208
7a21b2581dce
patch 8.2.2645: using inline function is not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
24202
diff
changeset
|
881 if (eap->cmdidx == CMD_def) |
26792
30d8377ea1b1
patch 8.2.3924: Vim9: no error if something follows :enddef
Bram Moolenaar <Bram@vim.org>
parents:
26790
diff
changeset
|
882 semsg(_(e_text_found_after_str_str), "enddef", p); |
24208
7a21b2581dce
patch 8.2.2645: using inline function is not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
24202
diff
changeset
|
883 else |
7a21b2581dce
patch 8.2.2645: using inline function is not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
24202
diff
changeset
|
884 give_warning2((char_u *) |
7a21b2581dce
patch 8.2.2645: using inline function is not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
24202
diff
changeset
|
885 _("W22: Text found after :endfunction: %s"), |
7a21b2581dce
patch 8.2.2645: using inline function is not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
24202
diff
changeset
|
886 p, TRUE); |
7a21b2581dce
patch 8.2.2645: using inline function is not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
24202
diff
changeset
|
887 } |
7a21b2581dce
patch 8.2.2645: using inline function is not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
24202
diff
changeset
|
888 if (nextcmd != NULL && *skipwhite(nextcmd) != NUL) |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
889 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
890 // Another command follows. If the line came from "eap" |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
891 // we can simply point into it, otherwise we need to |
27022
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
892 // change "eap->cmdlinep" to point to the last fetched |
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
893 // line. |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
894 eap->nextcmd = nextcmd; |
27022
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
895 if (lines_to_free->ga_len > 0 |
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
896 && *eap->cmdlinep != |
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
897 ((char_u **)lines_to_free->ga_data) |
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
898 [lines_to_free->ga_len - 1]) |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
899 { |
27022
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
900 // *cmdlinep will be freed later, thus remove the |
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
901 // line from lines_to_free. |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
902 vim_free(*eap->cmdlinep); |
27022
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
903 *eap->cmdlinep = ((char_u **)lines_to_free->ga_data) |
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
904 [lines_to_free->ga_len - 1]; |
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
905 --lines_to_free->ga_len; |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
906 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
907 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
908 break; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
909 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
910 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
911 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
912 // Check for mismatched "endfunc" or "enddef". |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
913 // We don't check for "def" inside "func" thus we also can't check |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
914 // for "enddef". |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
915 // We continue to find the end of the function, although we might |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
916 // not find it. |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
917 else if (nesting_def[nesting]) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
918 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
919 if (checkforcmd(&p, "endfunction", 4) && *p != ':') |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
920 emsg(_(e_mismatched_endfunction)); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
921 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
922 else if (eap->cmdidx == CMD_def && checkforcmd(&p, "enddef", 4)) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
923 emsg(_(e_mismatched_enddef)); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
924 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
925 // Increase indent inside "if", "while", "for" and "try", decrease |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
926 // at "end". |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
927 if (indent > 2 && (*p == '}' || STRNCMP(p, "end", 3) == 0)) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
928 indent -= 2; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
929 else if (STRNCMP(p, "if", 2) == 0 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
930 || STRNCMP(p, "wh", 2) == 0 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
931 || STRNCMP(p, "for", 3) == 0 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
932 || STRNCMP(p, "try", 3) == 0) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
933 indent += 2; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
934 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
935 // Check for defining a function inside this function. |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
936 // Only recognize "def" inside "def", not inside "function", |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
937 // For backwards compatibility, see Test_function_python(). |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
938 c = *p; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
939 if (is_function_cmd(&p) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
940 || (eap->cmdidx == CMD_def && checkforcmd(&p, "def", 3))) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
941 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
942 if (*p == '!') |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
943 p = skipwhite(p + 1); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
944 p += eval_fname_script(p); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
945 vim_free(trans_function_name(&p, NULL, TRUE, 0, NULL, |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
946 NULL, NULL)); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
947 if (*skipwhite(p) == '(') |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
948 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
949 if (nesting == MAX_FUNC_NESTING - 1) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
950 emsg(_(e_function_nesting_too_deep)); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
951 else |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
952 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
953 ++nesting; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
954 nesting_def[nesting] = (c == 'd'); |
25265
1d6ff96306fc
patch 8.2.3169: Vim9: cannot handle nested inline function
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
955 nesting_inline[nesting] = FALSE; |
1d6ff96306fc
patch 8.2.3169: Vim9: cannot handle nested inline function
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
956 indent += 2; |
1d6ff96306fc
patch 8.2.3169: Vim9: cannot handle nested inline function
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
957 } |
1d6ff96306fc
patch 8.2.3169: Vim9: cannot handle nested inline function
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
958 } |
1d6ff96306fc
patch 8.2.3169: Vim9: cannot handle nested inline function
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
959 } |
1d6ff96306fc
patch 8.2.3169: Vim9: cannot handle nested inline function
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
960 |
25296
ec0421c25be9
patch 8.2.3185: Vim9: start of inline function found in comment line
Bram Moolenaar <Bram@vim.org>
parents:
25269
diff
changeset
|
961 if (nesting_def[nesting] ? *p != '#' : *p != '"') |
25265
1d6ff96306fc
patch 8.2.3169: Vim9: cannot handle nested inline function
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
962 { |
25296
ec0421c25be9
patch 8.2.3185: Vim9: start of inline function found in comment line
Bram Moolenaar <Bram@vim.org>
parents:
25269
diff
changeset
|
963 // Not a comment line: check for nested inline function. |
ec0421c25be9
patch 8.2.3185: Vim9: start of inline function found in comment line
Bram Moolenaar <Bram@vim.org>
parents:
25269
diff
changeset
|
964 end = p + STRLEN(p) - 1; |
25265
1d6ff96306fc
patch 8.2.3169: Vim9: cannot handle nested inline function
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
965 while (end > p && VIM_ISWHITE(*end)) |
1d6ff96306fc
patch 8.2.3169: Vim9: cannot handle nested inline function
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
966 --end; |
25473
9a4cb96c9550
patch 8.2.3273: autocmd test fails
Bram Moolenaar <Bram@vim.org>
parents:
25469
diff
changeset
|
967 if (end > p + 1 && *end == '{' && VIM_ISWHITE(end[-1])) |
25265
1d6ff96306fc
patch 8.2.3169: Vim9: cannot handle nested inline function
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
968 { |
25469
dcd45fe7fe2e
patch 8.2.3271: Vim9: cannot use :command or :au with block in :def function
Bram Moolenaar <Bram@vim.org>
parents:
25409
diff
changeset
|
969 int is_block; |
dcd45fe7fe2e
patch 8.2.3271: Vim9: cannot use :command or :au with block in :def function
Bram Moolenaar <Bram@vim.org>
parents:
25409
diff
changeset
|
970 |
dcd45fe7fe2e
patch 8.2.3271: Vim9: cannot use :command or :au with block in :def function
Bram Moolenaar <Bram@vim.org>
parents:
25409
diff
changeset
|
971 // check for trailing "=> {": start of an inline function |
25296
ec0421c25be9
patch 8.2.3185: Vim9: start of inline function found in comment line
Bram Moolenaar <Bram@vim.org>
parents:
25269
diff
changeset
|
972 --end; |
ec0421c25be9
patch 8.2.3185: Vim9: start of inline function found in comment line
Bram Moolenaar <Bram@vim.org>
parents:
25269
diff
changeset
|
973 while (end > p && VIM_ISWHITE(*end)) |
ec0421c25be9
patch 8.2.3185: Vim9: start of inline function found in comment line
Bram Moolenaar <Bram@vim.org>
parents:
25269
diff
changeset
|
974 --end; |
25469
dcd45fe7fe2e
patch 8.2.3271: Vim9: cannot use :command or :au with block in :def function
Bram Moolenaar <Bram@vim.org>
parents:
25409
diff
changeset
|
975 is_block = end > p + 2 && end[-1] == '=' && end[0] == '>'; |
dcd45fe7fe2e
patch 8.2.3271: Vim9: cannot use :command or :au with block in :def function
Bram Moolenaar <Bram@vim.org>
parents:
25409
diff
changeset
|
976 if (!is_block) |
25265
1d6ff96306fc
patch 8.2.3169: Vim9: cannot handle nested inline function
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
977 { |
25469
dcd45fe7fe2e
patch 8.2.3271: Vim9: cannot use :command or :au with block in :def function
Bram Moolenaar <Bram@vim.org>
parents:
25409
diff
changeset
|
978 char_u *s = p; |
dcd45fe7fe2e
patch 8.2.3271: Vim9: cannot use :command or :au with block in :def function
Bram Moolenaar <Bram@vim.org>
parents:
25409
diff
changeset
|
979 |
dcd45fe7fe2e
patch 8.2.3271: Vim9: cannot use :command or :au with block in :def function
Bram Moolenaar <Bram@vim.org>
parents:
25409
diff
changeset
|
980 // check for line starting with "au" for :autocmd or |
dcd45fe7fe2e
patch 8.2.3271: Vim9: cannot use :command or :au with block in :def function
Bram Moolenaar <Bram@vim.org>
parents:
25409
diff
changeset
|
981 // "com" for :command, these can use a {} block |
dcd45fe7fe2e
patch 8.2.3271: Vim9: cannot use :command or :au with block in :def function
Bram Moolenaar <Bram@vim.org>
parents:
25409
diff
changeset
|
982 is_block = checkforcmd_noparen(&s, "autocmd", 2) |
dcd45fe7fe2e
patch 8.2.3271: Vim9: cannot use :command or :au with block in :def function
Bram Moolenaar <Bram@vim.org>
parents:
25409
diff
changeset
|
983 || checkforcmd_noparen(&s, "command", 3); |
dcd45fe7fe2e
patch 8.2.3271: Vim9: cannot use :command or :au with block in :def function
Bram Moolenaar <Bram@vim.org>
parents:
25409
diff
changeset
|
984 } |
dcd45fe7fe2e
patch 8.2.3271: Vim9: cannot use :command or :au with block in :def function
Bram Moolenaar <Bram@vim.org>
parents:
25409
diff
changeset
|
985 |
dcd45fe7fe2e
patch 8.2.3271: Vim9: cannot use :command or :au with block in :def function
Bram Moolenaar <Bram@vim.org>
parents:
25409
diff
changeset
|
986 if (is_block) |
dcd45fe7fe2e
patch 8.2.3271: Vim9: cannot use :command or :au with block in :def function
Bram Moolenaar <Bram@vim.org>
parents:
25409
diff
changeset
|
987 { |
25296
ec0421c25be9
patch 8.2.3185: Vim9: start of inline function found in comment line
Bram Moolenaar <Bram@vim.org>
parents:
25269
diff
changeset
|
988 if (nesting == MAX_FUNC_NESTING - 1) |
ec0421c25be9
patch 8.2.3185: Vim9: start of inline function found in comment line
Bram Moolenaar <Bram@vim.org>
parents:
25269
diff
changeset
|
989 emsg(_(e_function_nesting_too_deep)); |
ec0421c25be9
patch 8.2.3185: Vim9: start of inline function found in comment line
Bram Moolenaar <Bram@vim.org>
parents:
25269
diff
changeset
|
990 else |
ec0421c25be9
patch 8.2.3185: Vim9: start of inline function found in comment line
Bram Moolenaar <Bram@vim.org>
parents:
25269
diff
changeset
|
991 { |
ec0421c25be9
patch 8.2.3185: Vim9: start of inline function found in comment line
Bram Moolenaar <Bram@vim.org>
parents:
25269
diff
changeset
|
992 ++nesting; |
ec0421c25be9
patch 8.2.3185: Vim9: start of inline function found in comment line
Bram Moolenaar <Bram@vim.org>
parents:
25269
diff
changeset
|
993 nesting_def[nesting] = TRUE; |
ec0421c25be9
patch 8.2.3185: Vim9: start of inline function found in comment line
Bram Moolenaar <Bram@vim.org>
parents:
25269
diff
changeset
|
994 nesting_inline[nesting] = TRUE; |
ec0421c25be9
patch 8.2.3185: Vim9: start of inline function found in comment line
Bram Moolenaar <Bram@vim.org>
parents:
25269
diff
changeset
|
995 indent += 2; |
ec0421c25be9
patch 8.2.3185: Vim9: start of inline function found in comment line
Bram Moolenaar <Bram@vim.org>
parents:
25269
diff
changeset
|
996 } |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
997 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
998 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
999 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1000 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1001 // Check for ":append", ":change", ":insert". Not for :def. |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1002 p = skip_range(p, FALSE, NULL); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1003 if (!vim9_function |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1004 && ((p[0] == 'a' && (!ASCII_ISALPHA(p[1]) || p[1] == 'p')) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1005 || (p[0] == 'c' |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1006 && (!ASCII_ISALPHA(p[1]) || (p[1] == 'h' |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1007 && (!ASCII_ISALPHA(p[2]) || (p[2] == 'a' |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1008 && (STRNCMP(&p[3], "nge", 3) != 0 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1009 || !ASCII_ISALPHA(p[6]))))))) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1010 || (p[0] == 'i' |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1011 && (!ASCII_ISALPHA(p[1]) || (p[1] == 'n' |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1012 && (!ASCII_ISALPHA(p[2]) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1013 || (p[2] == 's' |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1014 && (!ASCII_ISALPHA(p[3]) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1015 || p[3] == 'e')))))))) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1016 skip_until = vim_strsave((char_u *)"."); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1017 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1018 // Check for ":python <<EOF", ":tcl <<EOF", etc. |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1019 arg = skipwhite(skiptowhite(p)); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1020 if (arg[0] == '<' && arg[1] =='<' |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1021 && ((p[0] == 'p' && p[1] == 'y' |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1022 && (!ASCII_ISALNUM(p[2]) || p[2] == 't' |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1023 || ((p[2] == '3' || p[2] == 'x') |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1024 && !ASCII_ISALPHA(p[3])))) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1025 || (p[0] == 'p' && p[1] == 'e' |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1026 && (!ASCII_ISALPHA(p[2]) || p[2] == 'r')) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1027 || (p[0] == 't' && p[1] == 'c' |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1028 && (!ASCII_ISALPHA(p[2]) || p[2] == 'l')) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1029 || (p[0] == 'l' && p[1] == 'u' && p[2] == 'a' |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1030 && !ASCII_ISALPHA(p[3])) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1031 || (p[0] == 'r' && p[1] == 'u' && p[2] == 'b' |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1032 && (!ASCII_ISALPHA(p[3]) || p[3] == 'y')) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1033 || (p[0] == 'm' && p[1] == 'z' |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1034 && (!ASCII_ISALPHA(p[2]) || p[2] == 's')) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1035 )) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1036 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1037 // ":python <<" continues until a dot, like ":append" |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1038 p = skipwhite(arg + 2); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1039 if (STRNCMP(p, "trim", 4) == 0) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1040 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1041 // Ignore leading white space. |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1042 p = skipwhite(p + 4); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1043 heredoc_trimmed = vim_strnsave(theline, |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1044 skipwhite(theline) - theline); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1045 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1046 if (*p == NUL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1047 skip_until = vim_strsave((char_u *)"."); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1048 else |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1049 skip_until = vim_strnsave(p, skiptowhite(p) - p); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1050 getline_options = GETLINE_NONE; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1051 is_heredoc = TRUE; |
28850
338212bba072
patch 8.2.4948: cannot use Perl heredoc in nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1052 if (eap->cmdidx == CMD_def && nesting == 0) |
24826
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
1053 heredoc_concat_len = newlines->ga_len + 1; |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1054 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1055 |
28850
338212bba072
patch 8.2.4948: cannot use Perl heredoc in nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1056 if (!is_heredoc) |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1057 { |
28850
338212bba072
patch 8.2.4948: cannot use Perl heredoc in nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1058 // Check for ":cmd v =<< [trim] EOF" |
338212bba072
patch 8.2.4948: cannot use Perl heredoc in nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1059 // and ":cmd [a, b] =<< [trim] EOF" |
338212bba072
patch 8.2.4948: cannot use Perl heredoc in nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1060 // and "lines =<< [trim] EOF" for Vim9 |
338212bba072
patch 8.2.4948: cannot use Perl heredoc in nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1061 // Where "cmd" can be "let", "var", "final" or "const". |
338212bba072
patch 8.2.4948: cannot use Perl heredoc in nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1062 arg = skipwhite(skiptowhite(p)); |
338212bba072
patch 8.2.4948: cannot use Perl heredoc in nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1063 if (*arg == '[') |
338212bba072
patch 8.2.4948: cannot use Perl heredoc in nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1064 arg = vim_strchr(arg, ']'); |
338212bba072
patch 8.2.4948: cannot use Perl heredoc in nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1065 if (arg != NULL) |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1066 { |
28850
338212bba072
patch 8.2.4948: cannot use Perl heredoc in nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1067 int found = (eap->cmdidx == CMD_def && arg[0] == '=' |
338212bba072
patch 8.2.4948: cannot use Perl heredoc in nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1068 && arg[1] == '<' && arg[2] =='<'); |
338212bba072
patch 8.2.4948: cannot use Perl heredoc in nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1069 |
338212bba072
patch 8.2.4948: cannot use Perl heredoc in nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1070 if (!found) |
338212bba072
patch 8.2.4948: cannot use Perl heredoc in nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1071 // skip over the argument after "cmd" |
338212bba072
patch 8.2.4948: cannot use Perl heredoc in nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1072 arg = skipwhite(skiptowhite(arg)); |
338212bba072
patch 8.2.4948: cannot use Perl heredoc in nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1073 if (found || (arg[0] == '=' && arg[1] == '<' |
338212bba072
patch 8.2.4948: cannot use Perl heredoc in nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1074 && arg[2] =='<' |
338212bba072
patch 8.2.4948: cannot use Perl heredoc in nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1075 && (checkforcmd(&p, "let", 2) |
338212bba072
patch 8.2.4948: cannot use Perl heredoc in nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1076 || checkforcmd(&p, "var", 3) |
338212bba072
patch 8.2.4948: cannot use Perl heredoc in nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1077 || checkforcmd(&p, "final", 5) |
338212bba072
patch 8.2.4948: cannot use Perl heredoc in nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1078 || checkforcmd(&p, "const", 5)))) |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1079 { |
28850
338212bba072
patch 8.2.4948: cannot use Perl heredoc in nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1080 p = skipwhite(arg + 3); |
338212bba072
patch 8.2.4948: cannot use Perl heredoc in nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1081 while (TRUE) |
28491
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28382
diff
changeset
|
1082 { |
28850
338212bba072
patch 8.2.4948: cannot use Perl heredoc in nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1083 if (STRNCMP(p, "trim", 4) == 0) |
338212bba072
patch 8.2.4948: cannot use Perl heredoc in nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1084 { |
338212bba072
patch 8.2.4948: cannot use Perl heredoc in nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1085 // Ignore leading white space. |
338212bba072
patch 8.2.4948: cannot use Perl heredoc in nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1086 p = skipwhite(p + 4); |
338212bba072
patch 8.2.4948: cannot use Perl heredoc in nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1087 heredoc_trimmed = vim_strnsave(theline, |
338212bba072
patch 8.2.4948: cannot use Perl heredoc in nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1088 skipwhite(theline) - theline); |
338212bba072
patch 8.2.4948: cannot use Perl heredoc in nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1089 continue; |
338212bba072
patch 8.2.4948: cannot use Perl heredoc in nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1090 } |
338212bba072
patch 8.2.4948: cannot use Perl heredoc in nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1091 if (STRNCMP(p, "eval", 4) == 0) |
338212bba072
patch 8.2.4948: cannot use Perl heredoc in nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1092 { |
338212bba072
patch 8.2.4948: cannot use Perl heredoc in nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1093 // Ignore leading white space. |
338212bba072
patch 8.2.4948: cannot use Perl heredoc in nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1094 p = skipwhite(p + 4); |
338212bba072
patch 8.2.4948: cannot use Perl heredoc in nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1095 continue; |
338212bba072
patch 8.2.4948: cannot use Perl heredoc in nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1096 } |
338212bba072
patch 8.2.4948: cannot use Perl heredoc in nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1097 break; |
28491
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28382
diff
changeset
|
1098 } |
28850
338212bba072
patch 8.2.4948: cannot use Perl heredoc in nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1099 skip_until = vim_strnsave(p, skiptowhite(p) - p); |
338212bba072
patch 8.2.4948: cannot use Perl heredoc in nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1100 getline_options = GETLINE_NONE; |
338212bba072
patch 8.2.4948: cannot use Perl heredoc in nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1101 is_heredoc = TRUE; |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1102 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1103 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1104 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1105 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1106 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1107 // Add the line to the function. |
28382
f24d4826e6bf
patch 8.2.4716: memory allocation failure not tested when defining a function
Bram Moolenaar <Bram@vim.org>
parents:
28313
diff
changeset
|
1108 if (ga_grow_id(newlines, 1 + sourcing_lnum_off, aid_get_func) == FAIL) |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1109 goto theend; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1110 |
24826
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
1111 if (heredoc_concat_len > 0) |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
1112 { |
26771
fc859aea8cec
patch 8.2.3914: various spelling mistakes in comments
Bram Moolenaar <Bram@vim.org>
parents:
26757
diff
changeset
|
1113 // For a :def function "python << EOF" concatenates all the lines, |
24826
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
1114 // to be used for the instruction later. |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
1115 ga_concat(&heredoc_ga, theline); |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
1116 ga_concat(&heredoc_ga, (char_u *)"\n"); |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
1117 p = vim_strsave((char_u *)""); |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
1118 } |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
1119 else |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
1120 { |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
1121 // Copy the line to newly allocated memory. get_one_sourceline() |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
1122 // allocates 250 bytes per line, this saves 80% on average. The |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
1123 // cost is an extra alloc/free. |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
1124 p = vim_strsave(theline); |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
1125 } |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1126 if (p == NULL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1127 goto theend; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1128 ((char_u **)(newlines->ga_data))[newlines->ga_len++] = p; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1129 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1130 // Add NULL lines for continuation lines, so that the line count is |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1131 // equal to the index in the growarray. |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1132 while (sourcing_lnum_off-- > 0) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1133 ((char_u **)(newlines->ga_data))[newlines->ga_len++] = NULL; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1134 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1135 // Check for end of eap->arg. |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1136 if (line_arg != NULL && *line_arg == NUL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1137 line_arg = NULL; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1138 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1139 |
24651
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1140 // Return OK when no error was detected. |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1141 if (!did_emsg) |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1142 ret = OK; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1143 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1144 theend: |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1145 vim_free(skip_until); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1146 vim_free(heredoc_trimmed); |
24826
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
1147 vim_free(heredoc_ga.ga_data); |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1148 need_wait_return |= saved_wait_return; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1149 return ret; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1150 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1151 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1152 /* |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1153 * Handle the body of a lambda. *arg points to the "{", process statements |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1154 * until the matching "}". |
24651
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1155 * When not evaluating "newargs" is NULL. |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1156 * When successful "rettv" is set to a funcref. |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1157 */ |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1158 static int |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1159 lambda_function_body( |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1160 char_u **arg, |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1161 typval_T *rettv, |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1162 evalarg_T *evalarg, |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1163 garray_T *newargs, |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1164 garray_T *argtypes, |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1165 int varargs, |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1166 garray_T *default_args, |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1167 char_u *ret_type) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1168 { |
30435
c2ef8f0f8ba1
patch 9.0.0553: no error for "|" after "{" in lamda
Bram Moolenaar <Bram@vim.org>
parents:
30333
diff
changeset
|
1169 char_u *start = *arg; |
24422
41cf1155ab90
patch 8.2.2751: Coverity warns for using NULL pointer
Bram Moolenaar <Bram@vim.org>
parents:
24412
diff
changeset
|
1170 int evaluate = (evalarg->eval_flags & EVAL_EVALUATE); |
24651
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1171 garray_T *gap = &evalarg->eval_ga; |
24655
3876d9629ebd
patch 8.2.2866: Vim9: memory leak when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24653
diff
changeset
|
1172 garray_T *freegap = &evalarg->eval_freega; |
24244
827fcf174f15
patch 8.2.2663: Vim9: leaking memory when inline function has an error
Bram Moolenaar <Bram@vim.org>
parents:
24208
diff
changeset
|
1173 ufunc_T *ufunc = NULL; |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1174 exarg_T eap; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1175 garray_T newlines; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1176 char_u *cmdline = NULL; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1177 int ret = FAIL; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1178 partial_T *pt; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1179 char_u *name; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1180 int lnum_save = -1; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1181 linenr_T sourcing_lnum_top = SOURCING_LNUM; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1182 |
30435
c2ef8f0f8ba1
patch 9.0.0553: no error for "|" after "{" in lamda
Bram Moolenaar <Bram@vim.org>
parents:
30333
diff
changeset
|
1183 *arg = skipwhite(*arg + 1); |
c2ef8f0f8ba1
patch 9.0.0553: no error for "|" after "{" in lamda
Bram Moolenaar <Bram@vim.org>
parents:
30333
diff
changeset
|
1184 if (**arg == '|' || !ends_excmd2(start, *arg)) |
c2ef8f0f8ba1
patch 9.0.0553: no error for "|" after "{" in lamda
Bram Moolenaar <Bram@vim.org>
parents:
30333
diff
changeset
|
1185 { |
c2ef8f0f8ba1
patch 9.0.0553: no error for "|" after "{" in lamda
Bram Moolenaar <Bram@vim.org>
parents:
30333
diff
changeset
|
1186 semsg(_(e_trailing_characters_str), *arg); |
24202
c50c5464e6dc
patch 8.2.2642: Vim9: no clear error for wrong inline function
Bram Moolenaar <Bram@vim.org>
parents:
24190
diff
changeset
|
1187 return FAIL; |
c50c5464e6dc
patch 8.2.2642: Vim9: no clear error for wrong inline function
Bram Moolenaar <Bram@vim.org>
parents:
24190
diff
changeset
|
1188 } |
c50c5464e6dc
patch 8.2.2642: Vim9: no clear error for wrong inline function
Bram Moolenaar <Bram@vim.org>
parents:
24190
diff
changeset
|
1189 |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1190 CLEAR_FIELD(eap); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1191 eap.cmdidx = CMD_block; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1192 eap.forceit = FALSE; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1193 eap.cmdlinep = &cmdline; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1194 eap.skip = !evaluate; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1195 if (evalarg->eval_cctx != NULL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1196 fill_exarg_from_cctx(&eap, evalarg->eval_cctx); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1197 else |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1198 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1199 eap.getline = evalarg->eval_getline; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1200 eap.cookie = evalarg->eval_cookie; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1201 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1202 |
27028
c9474ae175f4
patch 8.2.4043: using int for second argument of ga_init2()
Bram Moolenaar <Bram@vim.org>
parents:
27022
diff
changeset
|
1203 ga_init2(&newlines, sizeof(char_u *), 10); |
27022
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
1204 if (get_function_body(&eap, &newlines, NULL, |
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
1205 &evalarg->eval_tofree_ga) == FAIL) |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1206 goto erret; |
24651
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1207 |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1208 // When inside a lambda must add the function lines to evalarg.eval_ga. |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1209 evalarg->eval_break_count += newlines.ga_len; |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1210 if (gap->ga_itemsize > 0) |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1211 { |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1212 int idx; |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1213 char_u *last; |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1214 size_t plen; |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1215 char_u *pnl; |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1216 |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1217 for (idx = 0; idx < newlines.ga_len; ++idx) |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1218 { |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1219 char_u *p = skipwhite(((char_u **)newlines.ga_data)[idx]); |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1220 |
24655
3876d9629ebd
patch 8.2.2866: Vim9: memory leak when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24653
diff
changeset
|
1221 if (ga_grow(gap, 1) == FAIL || ga_grow(freegap, 1) == FAIL) |
24651
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1222 goto erret; |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1223 |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1224 // Going to concatenate the lines after parsing. For an empty or |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1225 // comment line use an empty string. |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1226 // Insert NL characters at the start of each line, the string will |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1227 // be split again later in .get_lambda_tv(). |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1228 if (*p == NUL || vim9_comment_start(p)) |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1229 p = (char_u *)""; |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1230 plen = STRLEN(p); |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1231 pnl = vim_strnsave((char_u *)"\n", plen + 1); |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1232 if (pnl != NULL) |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1233 mch_memmove(pnl + 1, p, plen + 1); |
24655
3876d9629ebd
patch 8.2.2866: Vim9: memory leak when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24653
diff
changeset
|
1234 ((char_u **)gap->ga_data)[gap->ga_len++] = pnl; |
3876d9629ebd
patch 8.2.2866: Vim9: memory leak when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24653
diff
changeset
|
1235 ((char_u **)freegap->ga_data)[freegap->ga_len++] = pnl; |
24651
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1236 } |
24655
3876d9629ebd
patch 8.2.2866: Vim9: memory leak when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24653
diff
changeset
|
1237 if (ga_grow(gap, 1) == FAIL || ga_grow(freegap, 1) == FAIL) |
24651
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1238 goto erret; |
26747
a8a4e1e7b111
patch 8.2.3902: Vim9: double free with nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
1239 if (eap.nextcmd != NULL) |
24651
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1240 // more is following after the "}", which was skipped |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1241 last = cmdline; |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1242 else |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1243 // nothing is following the "}" |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1244 last = (char_u *)"}"; |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1245 plen = STRLEN(last); |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1246 pnl = vim_strnsave((char_u *)"\n", plen + 1); |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1247 if (pnl != NULL) |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1248 mch_memmove(pnl + 1, last, plen + 1); |
24655
3876d9629ebd
patch 8.2.2866: Vim9: memory leak when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24653
diff
changeset
|
1249 ((char_u **)gap->ga_data)[gap->ga_len++] = pnl; |
3876d9629ebd
patch 8.2.2866: Vim9: memory leak when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24653
diff
changeset
|
1250 ((char_u **)freegap->ga_data)[freegap->ga_len++] = pnl; |
24651
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1251 } |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1252 |
26747
a8a4e1e7b111
patch 8.2.3902: Vim9: double free with nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
1253 if (eap.nextcmd != NULL) |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1254 { |
26053
e861c5aaedd8
patch 8.2.3560: using freed memory with lambda
Bram Moolenaar <Bram@vim.org>
parents:
26046
diff
changeset
|
1255 garray_T *tfgap = &evalarg->eval_tofree_ga; |
e861c5aaedd8
patch 8.2.3560: using freed memory with lambda
Bram Moolenaar <Bram@vim.org>
parents:
26046
diff
changeset
|
1256 |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1257 // Something comes after the "}". |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1258 *arg = eap.nextcmd; |
24190
5f3a2d31c48d
patch 8.2.2636: memory leak when compiling inline function
Bram Moolenaar <Bram@vim.org>
parents:
24188
diff
changeset
|
1259 |
5f3a2d31c48d
patch 8.2.2636: memory leak when compiling inline function
Bram Moolenaar <Bram@vim.org>
parents:
24188
diff
changeset
|
1260 // "arg" points into cmdline, need to keep the line and free it later. |
26053
e861c5aaedd8
patch 8.2.3560: using freed memory with lambda
Bram Moolenaar <Bram@vim.org>
parents:
26046
diff
changeset
|
1261 if (ga_grow(tfgap, 1) == OK) |
e861c5aaedd8
patch 8.2.3560: using freed memory with lambda
Bram Moolenaar <Bram@vim.org>
parents:
26046
diff
changeset
|
1262 { |
e861c5aaedd8
patch 8.2.3560: using freed memory with lambda
Bram Moolenaar <Bram@vim.org>
parents:
26046
diff
changeset
|
1263 ((char_u **)(tfgap->ga_data))[tfgap->ga_len++] = cmdline; |
e861c5aaedd8
patch 8.2.3560: using freed memory with lambda
Bram Moolenaar <Bram@vim.org>
parents:
26046
diff
changeset
|
1264 evalarg->eval_using_cmdline = TRUE; |
e861c5aaedd8
patch 8.2.3560: using freed memory with lambda
Bram Moolenaar <Bram@vim.org>
parents:
26046
diff
changeset
|
1265 } |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1266 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1267 else |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1268 *arg = (char_u *)""; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1269 |
24651
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1270 if (!evaluate) |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1271 { |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1272 ret = OK; |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1273 goto erret; |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1274 } |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1275 |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1276 name = get_lambda_name(); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1277 ufunc = alloc_clear(offsetof(ufunc_T, uf_name) + STRLEN(name) + 1); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1278 if (ufunc == NULL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1279 goto erret; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1280 set_ufunc_name(ufunc, name); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1281 if (hash_add(&func_hashtab, UF2HIKEY(ufunc)) == FAIL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1282 goto erret; |
26323
3841da4eac23
patch 8.2.3692: Vim9: cannot use :func inside a :def function
Bram Moolenaar <Bram@vim.org>
parents:
26205
diff
changeset
|
1283 ufunc->uf_flags = FC_LAMBDA; |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1284 ufunc->uf_refcount = 1; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1285 ufunc->uf_args = *newargs; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1286 newargs->ga_data = NULL; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1287 ufunc->uf_def_args = *default_args; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1288 default_args->ga_data = NULL; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1289 ufunc->uf_func_type = &t_func_any; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1290 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1291 // error messages are for the first function line |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1292 lnum_save = SOURCING_LNUM; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1293 SOURCING_LNUM = sourcing_lnum_top; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1294 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1295 // parse argument types |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1296 if (parse_argument_types(ufunc, argtypes, varargs) == FAIL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1297 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1298 SOURCING_LNUM = lnum_save; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1299 goto erret; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1300 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1301 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1302 // parse the return type, if any |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1303 if (parse_return_type(ufunc, ret_type) == FAIL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1304 goto erret; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1305 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1306 pt = ALLOC_CLEAR_ONE(partial_T); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1307 if (pt == NULL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1308 goto erret; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1309 pt->pt_func = ufunc; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1310 pt->pt_refcount = 1; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1311 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1312 ufunc->uf_lines = newlines; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1313 newlines.ga_data = NULL; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1314 if (sandbox) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1315 ufunc->uf_flags |= FC_SANDBOX; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1316 if (!ASCII_ISUPPER(*ufunc->uf_name)) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1317 ufunc->uf_flags |= FC_VIM9; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1318 ufunc->uf_script_ctx = current_sctx; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1319 ufunc->uf_script_ctx_version = current_sctx.sc_version; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1320 ufunc->uf_script_ctx.sc_lnum += sourcing_lnum_top; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1321 set_function_type(ufunc); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1322 |
25358
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
1323 function_using_block_scopes(ufunc, evalarg->eval_cstack); |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
1324 |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1325 rettv->vval.v_partial = pt; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1326 rettv->v_type = VAR_PARTIAL; |
24244
827fcf174f15
patch 8.2.2663: Vim9: leaking memory when inline function has an error
Bram Moolenaar <Bram@vim.org>
parents:
24208
diff
changeset
|
1327 ufunc = NULL; |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1328 ret = OK; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1329 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1330 erret: |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1331 if (lnum_save >= 0) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1332 SOURCING_LNUM = lnum_save; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1333 ga_clear_strings(&newlines); |
24651
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1334 if (newargs != NULL) |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1335 ga_clear_strings(newargs); |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1336 ga_clear_strings(default_args); |
24244
827fcf174f15
patch 8.2.2663: Vim9: leaking memory when inline function has an error
Bram Moolenaar <Bram@vim.org>
parents:
24208
diff
changeset
|
1337 if (ufunc != NULL) |
827fcf174f15
patch 8.2.2663: Vim9: leaking memory when inline function has an error
Bram Moolenaar <Bram@vim.org>
parents:
24208
diff
changeset
|
1338 { |
827fcf174f15
patch 8.2.2663: Vim9: leaking memory when inline function has an error
Bram Moolenaar <Bram@vim.org>
parents:
24208
diff
changeset
|
1339 func_clear(ufunc, TRUE); |
827fcf174f15
patch 8.2.2663: Vim9: leaking memory when inline function has an error
Bram Moolenaar <Bram@vim.org>
parents:
24208
diff
changeset
|
1340 func_free(ufunc, TRUE); |
827fcf174f15
patch 8.2.2663: Vim9: leaking memory when inline function has an error
Bram Moolenaar <Bram@vim.org>
parents:
24208
diff
changeset
|
1341 } |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1342 return ret; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1343 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1344 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1345 /* |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1346 * Parse a lambda expression and get a Funcref from "*arg" into "rettv". |
23318
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
1347 * "arg" points to the { in "{arg -> expr}" or the ( in "(arg) => expr" |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
1348 * When "types_optional" is TRUE optionally take argument types. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1349 * Return OK or FAIL. Returns NOTDONE for dict or {expr}. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1350 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1351 int |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
1352 get_lambda_tv( |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
1353 char_u **arg, |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
1354 typval_T *rettv, |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
1355 int types_optional, |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
1356 evalarg_T *evalarg) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1357 { |
21040
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21032
diff
changeset
|
1358 int evaluate = evalarg != NULL |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21032
diff
changeset
|
1359 && (evalarg->eval_flags & EVAL_EVALUATE); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1360 garray_T newargs; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1361 garray_T newlines; |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
1362 garray_T *pnewargs; |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
1363 garray_T argtypes; |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1364 garray_T default_args; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1365 ufunc_T *fp = NULL; |
15820
bd75c9df2a14
patch 8.1.0917: double free when running out of memory
Bram Moolenaar <Bram@vim.org>
parents:
15780
diff
changeset
|
1366 partial_T *pt = NULL; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1367 int varargs; |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
1368 char_u *ret_type = NULL; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1369 int ret; |
21220
ad13736a1783
patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents:
21218
diff
changeset
|
1370 char_u *s; |
ad13736a1783
patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents:
21218
diff
changeset
|
1371 char_u *start, *end; |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
1372 int *old_eval_lavars = eval_lavars_used; |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
1373 int eval_lavars = FALSE; |
23644
03acf9c49f07
patch 8.2.2364: Vim9: line break in lambda accesses freed memory
Bram Moolenaar <Bram@vim.org>
parents:
23630
diff
changeset
|
1374 char_u *tofree2 = NULL; |
23318
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
1375 int equal_arrow = **arg == '('; |
23338
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
1376 int white_error = FALSE; |
23808
baf9069f64ca
patch 8.2.2445: Vim9: no proper error for lambda missing return type
Bram Moolenaar <Bram@vim.org>
parents:
23727
diff
changeset
|
1377 int called_emsg_start = called_emsg; |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
1378 int vim9script = in_vim9script(); |
28727
30862b2f7431
patch 8.2.4888: line number of lambda ignores line continuation
Bram Moolenaar <Bram@vim.org>
parents:
28515
diff
changeset
|
1379 long start_lnum = SOURCING_LNUM; |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
1380 |
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
1381 if (equal_arrow && !vim9script) |
23318
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
1382 return NOTDONE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1383 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1384 ga_init(&newargs); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1385 ga_init(&newlines); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1386 |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
1387 // First, check if this is really a lambda expression. "->" or "=>" must |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
1388 // be found after the arguments. |
23511
7e8703464f01
patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23446
diff
changeset
|
1389 s = *arg + 1; |
23318
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
1390 ret = get_function_args(&s, equal_arrow ? ')' : '-', NULL, |
24033
308d29307910
patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents:
24004
diff
changeset
|
1391 types_optional ? &argtypes : NULL, types_optional, evalarg, |
25038
efdb9608cc11
patch 8.2.3056: Vim9: using default value in lambda gives confusing error
Bram Moolenaar <Bram@vim.org>
parents:
24988
diff
changeset
|
1392 NULL, &default_args, TRUE, NULL, NULL); |
23338
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
1393 if (ret == FAIL || skip_arrow(s, equal_arrow, &ret_type, NULL) == NULL) |
23320
1d11e3adbe52
patch 8.2.2205: Vim9: memory leak when parsing lambda fails
Bram Moolenaar <Bram@vim.org>
parents:
23318
diff
changeset
|
1394 { |
1d11e3adbe52
patch 8.2.2205: Vim9: memory leak when parsing lambda fails
Bram Moolenaar <Bram@vim.org>
parents:
23318
diff
changeset
|
1395 if (types_optional) |
1d11e3adbe52
patch 8.2.2205: Vim9: memory leak when parsing lambda fails
Bram Moolenaar <Bram@vim.org>
parents:
23318
diff
changeset
|
1396 ga_clear_strings(&argtypes); |
23808
baf9069f64ca
patch 8.2.2445: Vim9: no proper error for lambda missing return type
Bram Moolenaar <Bram@vim.org>
parents:
23727
diff
changeset
|
1397 return called_emsg == called_emsg_start ? NOTDONE : FAIL; |
23320
1d11e3adbe52
patch 8.2.2205: Vim9: memory leak when parsing lambda fails
Bram Moolenaar <Bram@vim.org>
parents:
23318
diff
changeset
|
1398 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1399 |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
1400 // Parse the arguments for real. |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
1401 if (evaluate) |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
1402 pnewargs = &newargs; |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
1403 else |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
1404 pnewargs = NULL; |
23511
7e8703464f01
patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23446
diff
changeset
|
1405 *arg += 1; |
23318
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
1406 ret = get_function_args(arg, equal_arrow ? ')' : '-', pnewargs, |
24033
308d29307910
patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents:
24004
diff
changeset
|
1407 types_optional ? &argtypes : NULL, types_optional, evalarg, |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1408 &varargs, &default_args, |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1409 FALSE, NULL, NULL); |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
1410 if (ret == FAIL |
23338
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
1411 || (s = skip_arrow(*arg, equal_arrow, &ret_type, |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
1412 equal_arrow || vim9script ? &white_error : NULL)) == NULL) |
23320
1d11e3adbe52
patch 8.2.2205: Vim9: memory leak when parsing lambda fails
Bram Moolenaar <Bram@vim.org>
parents:
23318
diff
changeset
|
1413 { |
1d11e3adbe52
patch 8.2.2205: Vim9: memory leak when parsing lambda fails
Bram Moolenaar <Bram@vim.org>
parents:
23318
diff
changeset
|
1414 if (types_optional) |
1d11e3adbe52
patch 8.2.2205: Vim9: memory leak when parsing lambda fails
Bram Moolenaar <Bram@vim.org>
parents:
23318
diff
changeset
|
1415 ga_clear_strings(&argtypes); |
23354
611e19cd237d
patch 8.2.2220: Vim9: memory leak when parsing nested parenthesis
Bram Moolenaar <Bram@vim.org>
parents:
23340
diff
changeset
|
1416 ga_clear_strings(&newargs); |
23338
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
1417 return white_error ? FAIL : NOTDONE; |
23320
1d11e3adbe52
patch 8.2.2205: Vim9: memory leak when parsing lambda fails
Bram Moolenaar <Bram@vim.org>
parents:
23318
diff
changeset
|
1418 } |
23338
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
1419 *arg = s; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1420 |
23644
03acf9c49f07
patch 8.2.2364: Vim9: line break in lambda accesses freed memory
Bram Moolenaar <Bram@vim.org>
parents:
23630
diff
changeset
|
1421 // Skipping over linebreaks may make "ret_type" invalid, make a copy. |
03acf9c49f07
patch 8.2.2364: Vim9: line break in lambda accesses freed memory
Bram Moolenaar <Bram@vim.org>
parents:
23630
diff
changeset
|
1422 if (ret_type != NULL) |
03acf9c49f07
patch 8.2.2364: Vim9: line break in lambda accesses freed memory
Bram Moolenaar <Bram@vim.org>
parents:
23630
diff
changeset
|
1423 { |
03acf9c49f07
patch 8.2.2364: Vim9: line break in lambda accesses freed memory
Bram Moolenaar <Bram@vim.org>
parents:
23630
diff
changeset
|
1424 ret_type = vim_strsave(ret_type); |
03acf9c49f07
patch 8.2.2364: Vim9: line break in lambda accesses freed memory
Bram Moolenaar <Bram@vim.org>
parents:
23630
diff
changeset
|
1425 tofree2 = ret_type; |
03acf9c49f07
patch 8.2.2364: Vim9: line break in lambda accesses freed memory
Bram Moolenaar <Bram@vim.org>
parents:
23630
diff
changeset
|
1426 } |
03acf9c49f07
patch 8.2.2364: Vim9: line break in lambda accesses freed memory
Bram Moolenaar <Bram@vim.org>
parents:
23630
diff
changeset
|
1427 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1428 // Set up a flag for checking local variables and arguments. |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
1429 if (evaluate) |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
1430 eval_lavars_used = &eval_lavars; |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
1431 |
23318
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
1432 *arg = skipwhite_and_linebreak(*arg, evalarg); |
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
1433 |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
1434 // Recognize "{" as the start of a function body. |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
1435 if (equal_arrow && **arg == '{') |
23318
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
1436 { |
24422
41cf1155ab90
patch 8.2.2751: Coverity warns for using NULL pointer
Bram Moolenaar <Bram@vim.org>
parents:
24412
diff
changeset
|
1437 if (evalarg == NULL) |
41cf1155ab90
patch 8.2.2751: Coverity warns for using NULL pointer
Bram Moolenaar <Bram@vim.org>
parents:
24412
diff
changeset
|
1438 // cannot happen? |
41cf1155ab90
patch 8.2.2751: Coverity warns for using NULL pointer
Bram Moolenaar <Bram@vim.org>
parents:
24412
diff
changeset
|
1439 goto theend; |
28727
30862b2f7431
patch 8.2.4888: line number of lambda ignores line continuation
Bram Moolenaar <Bram@vim.org>
parents:
28515
diff
changeset
|
1440 SOURCING_LNUM = start_lnum; // used for where lambda is defined |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1441 if (lambda_function_body(arg, rettv, evalarg, pnewargs, |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1442 types_optional ? &argtypes : NULL, varargs, |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1443 &default_args, ret_type) == FAIL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1444 goto errret; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1445 goto theend; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1446 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1447 if (default_args.ga_len > 0) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1448 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1449 emsg(_(e_cannot_use_default_values_in_lambda)); |
23318
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
1450 goto errret; |
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
1451 } |
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
1452 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1453 // Get the start and the end of the expression. |
21220
ad13736a1783
patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents:
21218
diff
changeset
|
1454 start = *arg; |
ad13736a1783
patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents:
21218
diff
changeset
|
1455 ret = skip_expr_concatenate(arg, &start, &end, evalarg); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1456 if (ret == FAIL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1457 goto errret; |
21040
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21032
diff
changeset
|
1458 |
23318
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
1459 if (!equal_arrow) |
19826
293a22b677a8
patch 8.2.0469: Vim9: no error for missing ] after list
Bram Moolenaar <Bram@vim.org>
parents:
19685
diff
changeset
|
1460 { |
23318
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
1461 *arg = skipwhite_and_linebreak(*arg, evalarg); |
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
1462 if (**arg != '}') |
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
1463 { |
26915
3631d2deb36c
patch 8.2.3986: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26897
diff
changeset
|
1464 semsg(_(e_expected_right_curly_str), *arg); |
23318
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
1465 goto errret; |
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
1466 } |
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
1467 ++*arg; |
19826
293a22b677a8
patch 8.2.0469: Vim9: no error for missing ] after list
Bram Moolenaar <Bram@vim.org>
parents:
19685
diff
changeset
|
1468 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1469 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1470 if (evaluate) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1471 { |
21040
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21032
diff
changeset
|
1472 int len; |
26323
3841da4eac23
patch 8.2.3692: Vim9: cannot use :func inside a :def function
Bram Moolenaar <Bram@vim.org>
parents:
26205
diff
changeset
|
1473 int flags = FC_LAMBDA; |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
1474 char_u *p; |
24651
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1475 char_u *line_end; |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
1476 char_u *name = get_lambda_name(); |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
1477 |
17659
121bdff812b4
patch 8.1.1827: allocating more memory than needed for extended structs
Bram Moolenaar <Bram@vim.org>
parents:
17646
diff
changeset
|
1478 fp = alloc_clear(offsetof(ufunc_T, uf_name) + STRLEN(name) + 1); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1479 if (fp == NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1480 goto errret; |
20943
1693ca876049
patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
1481 fp->uf_def_status = UF_NOT_COMPILED; |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
1482 pt = ALLOC_CLEAR_ONE(partial_T); |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
1483 if (pt == NULL) |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
1484 goto errret; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1485 |
27028
c9474ae175f4
patch 8.2.4043: using int for second argument of ga_init2()
Bram Moolenaar <Bram@vim.org>
parents:
27022
diff
changeset
|
1486 ga_init2(&newlines, sizeof(char_u *), 1); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1487 if (ga_grow(&newlines, 1) == FAIL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1488 goto errret; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1489 |
24651
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1490 // If there are line breaks, we need to split up the string. |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1491 line_end = vim_strchr(start, '\n'); |
25396
8ecd3575bc8c
patch 8.2.3235: cannot use lambda in {} block in user command
Bram Moolenaar <Bram@vim.org>
parents:
25358
diff
changeset
|
1492 if (line_end == NULL || line_end > end) |
24651
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1493 line_end = end; |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1494 |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1495 // Add "return " before the expression (or the first line). |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1496 len = 7 + (int)(line_end - start) + 1; |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
1497 p = alloc(len); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1498 if (p == NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1499 goto errret; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1500 ((char_u **)(newlines.ga_data))[newlines.ga_len++] = p; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1501 STRCPY(p, "return "); |
24651
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1502 vim_strncpy(p + 7, start, line_end - start); |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1503 |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1504 if (line_end != end) |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1505 { |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1506 // Add more lines, split by line breaks. Thus is used when a |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1507 // lambda with { cmds } is encountered. |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1508 while (*line_end == '\n') |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1509 { |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1510 if (ga_grow(&newlines, 1) == FAIL) |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1511 goto errret; |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1512 start = line_end + 1; |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1513 line_end = vim_strchr(start, '\n'); |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1514 if (line_end == NULL) |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1515 line_end = end; |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1516 ((char_u **)(newlines.ga_data))[newlines.ga_len++] = |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1517 vim_strnsave(start, line_end - start); |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1518 } |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1519 } |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1520 |
19886
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
1521 if (strstr((char *)p + 7, "a:") == NULL) |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
1522 // No a: variables are used for sure. |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
1523 flags |= FC_NOARGS; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1524 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1525 fp->uf_refcount = 1; |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
1526 set_ufunc_name(fp, name); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1527 fp->uf_args = newargs; |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
1528 ga_init(&fp->uf_def_args); |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
1529 if (types_optional) |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
1530 { |
24400
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
1531 if (parse_argument_types(fp, &argtypes, |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
1532 vim9script && varargs) == FAIL) |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
1533 goto errret; |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
1534 if (ret_type != NULL) |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
1535 { |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
1536 fp->uf_ret_type = parse_type(&ret_type, |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
1537 &fp->uf_type_list, TRUE); |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
1538 if (fp->uf_ret_type == NULL) |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
1539 goto errret; |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
1540 } |
23420
42294d4d4f6e
patch 8.2.2253: Vim9: expr test fails
Bram Moolenaar <Bram@vim.org>
parents:
23398
diff
changeset
|
1541 else |
24890
0cba2be8cbd7
patch 8.2.2983: Vim9: an inline function requires specifying the return type
Bram Moolenaar <Bram@vim.org>
parents:
24826
diff
changeset
|
1542 fp->uf_ret_type = &t_unknown; |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
1543 } |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
1544 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1545 fp->uf_lines = newlines; |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
1546 if (current_funccal != NULL && eval_lavars) |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
1547 { |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
1548 flags |= FC_CLOSURE; |
9721
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
1549 if (register_closure(fp) == FAIL) |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
1550 goto errret; |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
1551 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1552 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1553 #ifdef FEAT_PROFILE |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1554 if (prof_def_func()) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1555 func_do_profile(fp); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1556 #endif |
14323
9df95cf9ea7e
patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1557 if (sandbox) |
9df95cf9ea7e
patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1558 flags |= FC_SANDBOX; |
24398
bed5ec739304
patch 8.2.2739: Vim9: a lambda accepts too many arguments at the script level
Bram Moolenaar <Bram@vim.org>
parents:
24371
diff
changeset
|
1559 // In legacy script a lambda can be called with more args than |
24400
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
1560 // uf_args.ga_len. In Vim9 script "...name" has to be used. |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
1561 fp->uf_varargs = !vim9script || varargs; |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
1562 fp->uf_flags = flags; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1563 fp->uf_calls = 0; |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14430
diff
changeset
|
1564 fp->uf_script_ctx = current_sctx; |
28727
30862b2f7431
patch 8.2.4888: line number of lambda ignores line continuation
Bram Moolenaar <Bram@vim.org>
parents:
28515
diff
changeset
|
1565 // Use the line number of the arguments. |
30862b2f7431
patch 8.2.4888: line number of lambda ignores line continuation
Bram Moolenaar <Bram@vim.org>
parents:
28515
diff
changeset
|
1566 fp->uf_script_ctx.sc_lnum += start_lnum; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1567 |
25358
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
1568 function_using_block_scopes(fp, evalarg->eval_cstack); |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
1569 |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
1570 pt->pt_func = fp; |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
1571 pt->pt_refcount = 1; |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
1572 rettv->vval.v_partial = pt; |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
1573 rettv->v_type = VAR_PARTIAL; |
24033
308d29307910
patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents:
24004
diff
changeset
|
1574 |
308d29307910
patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents:
24004
diff
changeset
|
1575 hash_add(&func_hashtab, UF2HIKEY(fp)); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1576 } |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
1577 |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1578 theend: |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
1579 eval_lavars_used = old_eval_lavars; |
23644
03acf9c49f07
patch 8.2.2364: Vim9: line break in lambda accesses freed memory
Bram Moolenaar <Bram@vim.org>
parents:
23630
diff
changeset
|
1580 vim_free(tofree2); |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
1581 if (types_optional) |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
1582 ga_clear_strings(&argtypes); |
25358
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
1583 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1584 return OK; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1585 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1586 errret: |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1587 ga_clear_strings(&newargs); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1588 ga_clear_strings(&newlines); |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1589 ga_clear_strings(&default_args); |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
1590 if (types_optional) |
24687
0668fe755d2b
patch 8.2.2882: Vim9: memory leak when lambda has an error
Bram Moolenaar <Bram@vim.org>
parents:
24655
diff
changeset
|
1591 { |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
1592 ga_clear_strings(&argtypes); |
24687
0668fe755d2b
patch 8.2.2882: Vim9: memory leak when lambda has an error
Bram Moolenaar <Bram@vim.org>
parents:
24655
diff
changeset
|
1593 if (fp != NULL) |
0668fe755d2b
patch 8.2.2882: Vim9: memory leak when lambda has an error
Bram Moolenaar <Bram@vim.org>
parents:
24655
diff
changeset
|
1594 vim_free(fp->uf_arg_types); |
0668fe755d2b
patch 8.2.2882: Vim9: memory leak when lambda has an error
Bram Moolenaar <Bram@vim.org>
parents:
24655
diff
changeset
|
1595 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1596 vim_free(fp); |
15820
bd75c9df2a14
patch 8.1.0917: double free when running out of memory
Bram Moolenaar <Bram@vim.org>
parents:
15780
diff
changeset
|
1597 vim_free(pt); |
23644
03acf9c49f07
patch 8.2.2364: Vim9: line break in lambda accesses freed memory
Bram Moolenaar <Bram@vim.org>
parents:
23630
diff
changeset
|
1598 vim_free(tofree2); |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
1599 eval_lavars_used = old_eval_lavars; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1600 return FAIL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1601 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1602 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1603 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1604 * Check if "name" is a variable of type VAR_FUNC. If so, return the function |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1605 * name it contains, otherwise return "name". |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1606 * If "partialp" is not NULL, and "name" is of type VAR_PARTIAL also set |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1607 * "partialp". |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1608 * If "type" is not NULL and a Vim9 script-local variable is found look up the |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1609 * type of the variable. |
27233
73232ed49cf2
patch 8.2.4145: confusing error when using name of import for a function
Bram Moolenaar <Bram@vim.org>
parents:
27189
diff
changeset
|
1610 * If "new_function" is TRUE the name is for a new function. |
26506
4a1d2abc2016
patch 8.2.3783: confusing error for using a variable as a function
Bram Moolenaar <Bram@vim.org>
parents:
26504
diff
changeset
|
1611 * If "found_var" is not NULL and a variable was found set it to TRUE. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1612 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1613 char_u * |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1614 deref_func_name( |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1615 char_u *name, |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1616 int *lenp, |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1617 partial_T **partialp, |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1618 type_T **type, |
26506
4a1d2abc2016
patch 8.2.3783: confusing error for using a variable as a function
Bram Moolenaar <Bram@vim.org>
parents:
26504
diff
changeset
|
1619 int no_autoload, |
27233
73232ed49cf2
patch 8.2.4145: confusing error when using name of import for a function
Bram Moolenaar <Bram@vim.org>
parents:
27189
diff
changeset
|
1620 int new_function, |
26506
4a1d2abc2016
patch 8.2.3783: confusing error for using a variable as a function
Bram Moolenaar <Bram@vim.org>
parents:
26504
diff
changeset
|
1621 int *found_var) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1622 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1623 dictitem_T *v; |
26046
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1624 typval_T *tv = NULL; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1625 int cc; |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1626 char_u *s = NULL; |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1627 hashtab_T *ht; |
26046
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1628 int did_type = FALSE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1629 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1630 if (partialp != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1631 *partialp = NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1632 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1633 cc = name[*lenp]; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1634 name[*lenp] = NUL; |
24826
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
1635 |
27002
cf5b5e95f62b
patch 8.2.4030: a script local funcref is not found from a mapping
Bram Moolenaar <Bram@vim.org>
parents:
26990
diff
changeset
|
1636 v = find_var_also_in_script(name, &ht, no_autoload); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1637 name[*lenp] = cc; |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1638 if (v != NULL) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1639 { |
26046
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1640 tv = &v->di_tv; |
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1641 } |
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1642 else if (in_vim9script() || STRNCMP(name, "s:", 2) == 0) |
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1643 { |
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1644 imported_T *import; |
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1645 char_u *p = name; |
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1646 int len = *lenp; |
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1647 |
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1648 if (STRNCMP(name, "s:", 2) == 0) |
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1649 { |
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1650 p = name + 2; |
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1651 len -= 2; |
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1652 } |
27698
3813036f19cb
patch 8.2.4375: ctx_imports is not used
Bram Moolenaar <Bram@vim.org>
parents:
27682
diff
changeset
|
1653 import = find_imported(p, len, FALSE); |
26046
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1654 |
26980
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
1655 // imported function from another script |
26046
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1656 if (import != NULL) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1657 { |
26980
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
1658 name[len] = NUL; |
27233
73232ed49cf2
patch 8.2.4145: confusing error when using name of import for a function
Bram Moolenaar <Bram@vim.org>
parents:
27189
diff
changeset
|
1659 if (new_function) |
73232ed49cf2
patch 8.2.4145: confusing error when using name of import for a function
Bram Moolenaar <Bram@vim.org>
parents:
27189
diff
changeset
|
1660 semsg(_(e_redefining_imported_item_str), name); |
73232ed49cf2
patch 8.2.4145: confusing error when using name of import for a function
Bram Moolenaar <Bram@vim.org>
parents:
27189
diff
changeset
|
1661 else |
73232ed49cf2
patch 8.2.4145: confusing error when using name of import for a function
Bram Moolenaar <Bram@vim.org>
parents:
27189
diff
changeset
|
1662 semsg(_(e_cannot_use_str_itself_it_is_imported), name); |
26980
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
1663 name[len] = cc; |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
1664 *lenp = 0; |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
1665 return (char_u *)""; // just in case |
26046
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1666 } |
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1667 } |
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1668 |
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1669 if (tv != NULL) |
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1670 { |
26506
4a1d2abc2016
patch 8.2.3783: confusing error for using a variable as a function
Bram Moolenaar <Bram@vim.org>
parents:
26504
diff
changeset
|
1671 if (found_var != NULL) |
4a1d2abc2016
patch 8.2.3783: confusing error for using a variable as a function
Bram Moolenaar <Bram@vim.org>
parents:
26504
diff
changeset
|
1672 *found_var = TRUE; |
26046
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1673 if (tv->v_type == VAR_FUNC) |
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1674 { |
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1675 if (tv->vval.v_string == NULL) |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1676 { |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1677 *lenp = 0; |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1678 return (char_u *)""; // just in case |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1679 } |
26046
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1680 s = tv->vval.v_string; |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1681 *lenp = (int)STRLEN(s); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1682 } |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1683 |
26046
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1684 if (tv->v_type == VAR_PARTIAL) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1685 { |
26046
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1686 partial_T *pt = tv->vval.v_partial; |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1687 |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1688 if (pt == NULL) |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1689 { |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1690 *lenp = 0; |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1691 return (char_u *)""; // just in case |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1692 } |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1693 if (partialp != NULL) |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1694 *partialp = pt; |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1695 s = partial_name(pt); |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1696 *lenp = (int)STRLEN(s); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1697 } |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1698 |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1699 if (s != NULL) |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1700 { |
26046
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1701 if (!did_type && type != NULL && ht == get_script_local_ht()) |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1702 { |
28313
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28267
diff
changeset
|
1703 svar_T *sv = find_typval_in_script(tv, 0, TRUE); |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1704 |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1705 if (sv != NULL) |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1706 *type = sv->sv_type; |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1707 } |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1708 return s; |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1709 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1710 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1711 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1712 return name; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1713 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1714 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1715 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1716 * Give an error message with a function name. Handle <SNR> things. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1717 * "ermsg" is to be passed without translation, use N_() instead of _(). |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1718 */ |
18576
e9675870c480
patch 8.1.2282: crash when passing many arguments through a partial
Bram Moolenaar <Bram@vim.org>
parents:
18572
diff
changeset
|
1719 void |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1720 emsg_funcname(char *ermsg, char_u *name) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1721 { |
27088
3956e3bb47ec
patch 8.2.4073: Coverity warns for using NULL pointer
Bram Moolenaar <Bram@vim.org>
parents:
27076
diff
changeset
|
1722 char_u *p = name; |
3956e3bb47ec
patch 8.2.4073: Coverity warns for using NULL pointer
Bram Moolenaar <Bram@vim.org>
parents:
27076
diff
changeset
|
1723 |
3956e3bb47ec
patch 8.2.4073: Coverity warns for using NULL pointer
Bram Moolenaar <Bram@vim.org>
parents:
27076
diff
changeset
|
1724 if (name[0] == K_SPECIAL && name[1] != NUL && name[2] != NUL) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1725 p = concat_str((char_u *)"<SNR>", name + 3); |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15138
diff
changeset
|
1726 semsg(_(ermsg), p); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1727 if (p != name) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1728 vim_free(p); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1729 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1730 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1731 /* |
30065
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
1732 * Get function arguments at "*arg" and advance it. |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
1733 * Return them in "*argvars[MAX_FUNC_ARGS + 1]" and the count in "argcount". |
30083
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30079
diff
changeset
|
1734 * On failure FAIL is returned but the "argvars[argcount]" are still set. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1735 */ |
30065
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
1736 static int |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
1737 get_func_arguments( |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
1738 char_u **arg, |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
1739 evalarg_T *evalarg, |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
1740 int partial_argc, |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
1741 typval_T *argvars, |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
1742 int *argcount) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1743 { |
30065
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
1744 char_u *argp = *arg; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1745 int ret = OK; |
21909
a211bca98bc3
patch 8.2.1504: Vim9: white space checks are only done for a :def function
Bram Moolenaar <Bram@vim.org>
parents:
21883
diff
changeset
|
1746 int vim9script = in_vim9script(); |
27053
58cfcd3ed15b
patch 8.2.4055: Vim9: line break in expression causes v:errmsg to be fillec
Bram Moolenaar <Bram@vim.org>
parents:
27049
diff
changeset
|
1747 int evaluate = evalarg == NULL |
58cfcd3ed15b
patch 8.2.4055: Vim9: line break in expression causes v:errmsg to be fillec
Bram Moolenaar <Bram@vim.org>
parents:
27049
diff
changeset
|
1748 ? FALSE : (evalarg->eval_flags & EVAL_EVALUATE); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1749 |
30065
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
1750 while (*argcount < MAX_FUNC_ARGS - partial_argc) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1751 { |
21118
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21066
diff
changeset
|
1752 // skip the '(' or ',' and possibly line breaks |
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21066
diff
changeset
|
1753 argp = skipwhite_and_linebreak(argp + 1, evalarg); |
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21066
diff
changeset
|
1754 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1755 if (*argp == ')' || *argp == ',' || *argp == NUL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1756 break; |
30065
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
1757 if (eval1(&argp, &argvars[*argcount], evalarg) == FAIL) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1758 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1759 ret = FAIL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1760 break; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1761 } |
30065
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
1762 ++*argcount; |
21552
cbc570e66d11
patch 8.2.1326: Vim9: skipping over white space after list
Bram Moolenaar <Bram@vim.org>
parents:
21528
diff
changeset
|
1763 // The comma should come right after the argument, but this wasn't |
cbc570e66d11
patch 8.2.1326: Vim9: skipping over white space after list
Bram Moolenaar <Bram@vim.org>
parents:
21528
diff
changeset
|
1764 // checked previously, thus only enforce it in Vim9 script. |
21909
a211bca98bc3
patch 8.2.1504: Vim9: white space checks are only done for a :def function
Bram Moolenaar <Bram@vim.org>
parents:
21883
diff
changeset
|
1765 if (vim9script) |
a211bca98bc3
patch 8.2.1504: Vim9: white space checks are only done for a :def function
Bram Moolenaar <Bram@vim.org>
parents:
21883
diff
changeset
|
1766 { |
a211bca98bc3
patch 8.2.1504: Vim9: white space checks are only done for a :def function
Bram Moolenaar <Bram@vim.org>
parents:
21883
diff
changeset
|
1767 if (*argp != ',' && *skipwhite(argp) == ',') |
a211bca98bc3
patch 8.2.1504: Vim9: white space checks are only done for a :def function
Bram Moolenaar <Bram@vim.org>
parents:
21883
diff
changeset
|
1768 { |
27053
58cfcd3ed15b
patch 8.2.4055: Vim9: line break in expression causes v:errmsg to be fillec
Bram Moolenaar <Bram@vim.org>
parents:
27049
diff
changeset
|
1769 if (evaluate) |
58cfcd3ed15b
patch 8.2.4055: Vim9: line break in expression causes v:errmsg to be fillec
Bram Moolenaar <Bram@vim.org>
parents:
27049
diff
changeset
|
1770 semsg(_(e_no_white_space_allowed_before_str_str), |
58cfcd3ed15b
patch 8.2.4055: Vim9: line break in expression causes v:errmsg to be fillec
Bram Moolenaar <Bram@vim.org>
parents:
27049
diff
changeset
|
1771 ",", argp); |
21909
a211bca98bc3
patch 8.2.1504: Vim9: white space checks are only done for a :def function
Bram Moolenaar <Bram@vim.org>
parents:
21883
diff
changeset
|
1772 ret = FAIL; |
a211bca98bc3
patch 8.2.1504: Vim9: white space checks are only done for a :def function
Bram Moolenaar <Bram@vim.org>
parents:
21883
diff
changeset
|
1773 break; |
a211bca98bc3
patch 8.2.1504: Vim9: white space checks are only done for a :def function
Bram Moolenaar <Bram@vim.org>
parents:
21883
diff
changeset
|
1774 } |
a211bca98bc3
patch 8.2.1504: Vim9: white space checks are only done for a :def function
Bram Moolenaar <Bram@vim.org>
parents:
21883
diff
changeset
|
1775 } |
a211bca98bc3
patch 8.2.1504: Vim9: white space checks are only done for a :def function
Bram Moolenaar <Bram@vim.org>
parents:
21883
diff
changeset
|
1776 else |
21552
cbc570e66d11
patch 8.2.1326: Vim9: skipping over white space after list
Bram Moolenaar <Bram@vim.org>
parents:
21528
diff
changeset
|
1777 argp = skipwhite(argp); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1778 if (*argp != ',') |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1779 break; |
21909
a211bca98bc3
patch 8.2.1504: Vim9: white space checks are only done for a :def function
Bram Moolenaar <Bram@vim.org>
parents:
21883
diff
changeset
|
1780 if (vim9script && !IS_WHITE_OR_NUL(argp[1])) |
a211bca98bc3
patch 8.2.1504: Vim9: white space checks are only done for a :def function
Bram Moolenaar <Bram@vim.org>
parents:
21883
diff
changeset
|
1781 { |
27053
58cfcd3ed15b
patch 8.2.4055: Vim9: line break in expression causes v:errmsg to be fillec
Bram Moolenaar <Bram@vim.org>
parents:
27049
diff
changeset
|
1782 if (evaluate) |
58cfcd3ed15b
patch 8.2.4055: Vim9: line break in expression causes v:errmsg to be fillec
Bram Moolenaar <Bram@vim.org>
parents:
27049
diff
changeset
|
1783 semsg(_(e_white_space_required_after_str_str), ",", argp); |
21909
a211bca98bc3
patch 8.2.1504: Vim9: white space checks are only done for a :def function
Bram Moolenaar <Bram@vim.org>
parents:
21883
diff
changeset
|
1784 ret = FAIL; |
a211bca98bc3
patch 8.2.1504: Vim9: white space checks are only done for a :def function
Bram Moolenaar <Bram@vim.org>
parents:
21883
diff
changeset
|
1785 break; |
a211bca98bc3
patch 8.2.1504: Vim9: white space checks are only done for a :def function
Bram Moolenaar <Bram@vim.org>
parents:
21883
diff
changeset
|
1786 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1787 } |
30065
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
1788 |
21118
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21066
diff
changeset
|
1789 argp = skipwhite_and_linebreak(argp, evalarg); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1790 if (*argp == ')') |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1791 ++argp; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1792 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1793 ret = FAIL; |
30065
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
1794 *arg = argp; |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
1795 return ret; |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
1796 } |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
1797 |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
1798 /* |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
1799 * Call a function and put the result in "rettv". |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
1800 * Return OK or FAIL. |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
1801 */ |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
1802 int |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
1803 get_func_tv( |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
1804 char_u *name, // name of the function |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
1805 int len, // length of "name" or -1 to use strlen() |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
1806 typval_T *rettv, |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
1807 char_u **arg, // argument, pointing to the '(' |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
1808 evalarg_T *evalarg, // for line continuation |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
1809 funcexe_T *funcexe) // various values |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
1810 { |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
1811 char_u *argp; |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
1812 int ret = OK; |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
1813 typval_T argvars[MAX_FUNC_ARGS + 1]; // vars for arguments |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
1814 int argcount = 0; // number of arguments found |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
1815 int vim9script = in_vim9script(); |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
1816 int evaluate = evalarg == NULL |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
1817 ? FALSE : (evalarg->eval_flags & EVAL_EVALUATE); |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
1818 |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
1819 argp = *arg; |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
1820 ret = get_func_arguments(&argp, evalarg, |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
1821 (funcexe->fe_partial == NULL ? 0 : funcexe->fe_partial->pt_argc), |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
1822 argvars, &argcount); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1823 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1824 if (ret == OK) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1825 { |
25400
5c7192180b89
patch 8.2.3237: when a builtin function gives an error processing continues
Bram Moolenaar <Bram@vim.org>
parents:
25396
diff
changeset
|
1826 int i = 0; |
5c7192180b89
patch 8.2.3237: when a builtin function gives an error processing continues
Bram Moolenaar <Bram@vim.org>
parents:
25396
diff
changeset
|
1827 int did_emsg_before = did_emsg; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1828 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1829 if (get_vim_var_nr(VV_TESTING)) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1830 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1831 // Prepare for calling test_garbagecollect_now(), need to know |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1832 // what variables are used on the call stack. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1833 if (funcargs.ga_itemsize == 0) |
27028
c9474ae175f4
patch 8.2.4043: using int for second argument of ga_init2()
Bram Moolenaar <Bram@vim.org>
parents:
27022
diff
changeset
|
1834 ga_init2(&funcargs, sizeof(typval_T *), 50); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1835 for (i = 0; i < argcount; ++i) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1836 if (ga_grow(&funcargs, 1) == OK) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1837 ((typval_T **)funcargs.ga_data)[funcargs.ga_len++] = |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1838 &argvars[i]; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1839 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1840 |
17606
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17462
diff
changeset
|
1841 ret = call_func(name, len, rettv, argcount, argvars, funcexe); |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
1842 if (vim9script && did_emsg > did_emsg_before) |
25409
e3f1086429d8
patch 8.2.3241: Vim9: memory leak when function reports an error
Bram Moolenaar <Bram@vim.org>
parents:
25400
diff
changeset
|
1843 { |
25400
5c7192180b89
patch 8.2.3237: when a builtin function gives an error processing continues
Bram Moolenaar <Bram@vim.org>
parents:
25396
diff
changeset
|
1844 // An error in a builtin function does not return FAIL, but we do |
5c7192180b89
patch 8.2.3237: when a builtin function gives an error processing continues
Bram Moolenaar <Bram@vim.org>
parents:
25396
diff
changeset
|
1845 // want to abort further processing if an error was given. |
5c7192180b89
patch 8.2.3237: when a builtin function gives an error processing continues
Bram Moolenaar <Bram@vim.org>
parents:
25396
diff
changeset
|
1846 ret = FAIL; |
25409
e3f1086429d8
patch 8.2.3241: Vim9: memory leak when function reports an error
Bram Moolenaar <Bram@vim.org>
parents:
25400
diff
changeset
|
1847 clear_tv(rettv); |
e3f1086429d8
patch 8.2.3241: Vim9: memory leak when function reports an error
Bram Moolenaar <Bram@vim.org>
parents:
25400
diff
changeset
|
1848 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1849 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1850 funcargs.ga_len -= i; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1851 } |
27053
58cfcd3ed15b
patch 8.2.4055: Vim9: line break in expression causes v:errmsg to be fillec
Bram Moolenaar <Bram@vim.org>
parents:
27049
diff
changeset
|
1852 else if (!aborting() && evaluate) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1853 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1854 if (argcount == MAX_FUNC_ARGS) |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
1855 emsg_funcname(e_too_many_arguments_for_function_str_2, name); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1856 else |
26757
3a2b222107a6
patch 8.2.3907: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26747
diff
changeset
|
1857 emsg_funcname(e_invalid_arguments_for_function_str, name); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1858 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1859 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1860 while (--argcount >= 0) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1861 clear_tv(&argvars[argcount]); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1862 |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
1863 if (vim9script) |
21737
a849c984b485
patch 8.2.1418: Vim9: invalid error for missing white space
Bram Moolenaar <Bram@vim.org>
parents:
21699
diff
changeset
|
1864 *arg = argp; |
a849c984b485
patch 8.2.1418: Vim9: invalid error for missing white space
Bram Moolenaar <Bram@vim.org>
parents:
21699
diff
changeset
|
1865 else |
a849c984b485
patch 8.2.1418: Vim9: invalid error for missing white space
Bram Moolenaar <Bram@vim.org>
parents:
21699
diff
changeset
|
1866 *arg = skipwhite(argp); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1867 return ret; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1868 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1869 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1870 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1871 * Return TRUE if "p" starts with "<SID>" or "s:". |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1872 * Only works if eval_fname_script() returned non-zero for "p"! |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1873 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1874 static int |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1875 eval_fname_sid(char_u *p) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1876 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1877 return (*p == 's' || TOUPPER_ASC(p[2]) == 'I'); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1878 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1879 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1880 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1881 * In a script change <SID>name() and s:name() to K_SNR 123_name(). |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1882 * Change <SNR>123_name() to K_SNR 123_name(). |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1883 * Use "fname_buf[FLEN_FIXED + 1]" when it fits, otherwise allocate memory |
30465
b3367a7a3914
patch 9.0.0568: autocmd code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
30435
diff
changeset
|
1884 * and set "tofree". |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1885 */ |
19330
9c8b803fe598
patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents:
19328
diff
changeset
|
1886 char_u * |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1887 fname_trans_sid(char_u *name, char_u *fname_buf, char_u **tofree, int *error) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1888 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1889 int llen; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1890 char_u *fname; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1891 int i; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1892 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1893 llen = eval_fname_script(name); |
30465
b3367a7a3914
patch 9.0.0568: autocmd code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
30435
diff
changeset
|
1894 if (llen == 0) |
b3367a7a3914
patch 9.0.0568: autocmd code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
30435
diff
changeset
|
1895 return name; // no prefix |
b3367a7a3914
patch 9.0.0568: autocmd code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
30435
diff
changeset
|
1896 |
b3367a7a3914
patch 9.0.0568: autocmd code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
30435
diff
changeset
|
1897 fname_buf[0] = K_SPECIAL; |
b3367a7a3914
patch 9.0.0568: autocmd code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
30435
diff
changeset
|
1898 fname_buf[1] = KS_EXTRA; |
b3367a7a3914
patch 9.0.0568: autocmd code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
30435
diff
changeset
|
1899 fname_buf[2] = (int)KE_SNR; |
b3367a7a3914
patch 9.0.0568: autocmd code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
30435
diff
changeset
|
1900 i = 3; |
b3367a7a3914
patch 9.0.0568: autocmd code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
30435
diff
changeset
|
1901 if (eval_fname_sid(name)) // "<SID>" or "s:" |
b3367a7a3914
patch 9.0.0568: autocmd code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
30435
diff
changeset
|
1902 { |
b3367a7a3914
patch 9.0.0568: autocmd code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
30435
diff
changeset
|
1903 if (current_sctx.sc_sid <= 0) |
b3367a7a3914
patch 9.0.0568: autocmd code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
30435
diff
changeset
|
1904 *error = FCERR_SCRIPT; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1905 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1906 { |
30465
b3367a7a3914
patch 9.0.0568: autocmd code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
30435
diff
changeset
|
1907 sprintf((char *)fname_buf + 3, "%ld_", |
b3367a7a3914
patch 9.0.0568: autocmd code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
30435
diff
changeset
|
1908 (long)current_sctx.sc_sid); |
b3367a7a3914
patch 9.0.0568: autocmd code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
30435
diff
changeset
|
1909 i = (int)STRLEN(fname_buf); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1910 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1911 } |
30465
b3367a7a3914
patch 9.0.0568: autocmd code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
30435
diff
changeset
|
1912 if (i + STRLEN(name + llen) < FLEN_FIXED) |
b3367a7a3914
patch 9.0.0568: autocmd code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
30435
diff
changeset
|
1913 { |
b3367a7a3914
patch 9.0.0568: autocmd code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
30435
diff
changeset
|
1914 STRCPY(fname_buf + i, name + llen); |
b3367a7a3914
patch 9.0.0568: autocmd code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
30435
diff
changeset
|
1915 fname = fname_buf; |
b3367a7a3914
patch 9.0.0568: autocmd code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
30435
diff
changeset
|
1916 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1917 else |
30465
b3367a7a3914
patch 9.0.0568: autocmd code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
30435
diff
changeset
|
1918 { |
b3367a7a3914
patch 9.0.0568: autocmd code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
30435
diff
changeset
|
1919 fname = alloc(i + STRLEN(name + llen) + 1); |
b3367a7a3914
patch 9.0.0568: autocmd code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
30435
diff
changeset
|
1920 if (fname == NULL) |
b3367a7a3914
patch 9.0.0568: autocmd code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
30435
diff
changeset
|
1921 *error = FCERR_OTHER; |
b3367a7a3914
patch 9.0.0568: autocmd code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
30435
diff
changeset
|
1922 else |
b3367a7a3914
patch 9.0.0568: autocmd code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
30435
diff
changeset
|
1923 { |
b3367a7a3914
patch 9.0.0568: autocmd code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
30435
diff
changeset
|
1924 *tofree = fname; |
b3367a7a3914
patch 9.0.0568: autocmd code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
30435
diff
changeset
|
1925 mch_memmove(fname, fname_buf, (size_t)i); |
b3367a7a3914
patch 9.0.0568: autocmd code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
30435
diff
changeset
|
1926 STRCPY(fname + i, name + llen); |
b3367a7a3914
patch 9.0.0568: autocmd code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
30435
diff
changeset
|
1927 } |
b3367a7a3914
patch 9.0.0568: autocmd code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
30435
diff
changeset
|
1928 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1929 return fname; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1930 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1931 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1932 /* |
28249
4b322951ebac
patch 8.2.4650: "import autoload" only works with using 'runtimepath'
Bram Moolenaar <Bram@vim.org>
parents:
28123
diff
changeset
|
1933 * Concatenate the script ID and function name into "<SNR>99_name". |
4b322951ebac
patch 8.2.4650: "import autoload" only works with using 'runtimepath'
Bram Moolenaar <Bram@vim.org>
parents:
28123
diff
changeset
|
1934 * "buffer" must have size MAX_FUNC_NAME_LEN. |
4b322951ebac
patch 8.2.4650: "import autoload" only works with using 'runtimepath'
Bram Moolenaar <Bram@vim.org>
parents:
28123
diff
changeset
|
1935 */ |
4b322951ebac
patch 8.2.4650: "import autoload" only works with using 'runtimepath'
Bram Moolenaar <Bram@vim.org>
parents:
28123
diff
changeset
|
1936 void |
4b322951ebac
patch 8.2.4650: "import autoload" only works with using 'runtimepath'
Bram Moolenaar <Bram@vim.org>
parents:
28123
diff
changeset
|
1937 func_name_with_sid(char_u *name, int sid, char_u *buffer) |
4b322951ebac
patch 8.2.4650: "import autoload" only works with using 'runtimepath'
Bram Moolenaar <Bram@vim.org>
parents:
28123
diff
changeset
|
1938 { |
4b322951ebac
patch 8.2.4650: "import autoload" only works with using 'runtimepath'
Bram Moolenaar <Bram@vim.org>
parents:
28123
diff
changeset
|
1939 // A script-local function is stored as "<SNR>99_name". |
4b322951ebac
patch 8.2.4650: "import autoload" only works with using 'runtimepath'
Bram Moolenaar <Bram@vim.org>
parents:
28123
diff
changeset
|
1940 buffer[0] = K_SPECIAL; |
4b322951ebac
patch 8.2.4650: "import autoload" only works with using 'runtimepath'
Bram Moolenaar <Bram@vim.org>
parents:
28123
diff
changeset
|
1941 buffer[1] = KS_EXTRA; |
4b322951ebac
patch 8.2.4650: "import autoload" only works with using 'runtimepath'
Bram Moolenaar <Bram@vim.org>
parents:
28123
diff
changeset
|
1942 buffer[2] = (int)KE_SNR; |
4b322951ebac
patch 8.2.4650: "import autoload" only works with using 'runtimepath'
Bram Moolenaar <Bram@vim.org>
parents:
28123
diff
changeset
|
1943 vim_snprintf((char *)buffer + 3, MAX_FUNC_NAME_LEN - 3, "%ld_%s", |
4b322951ebac
patch 8.2.4650: "import autoload" only works with using 'runtimepath'
Bram Moolenaar <Bram@vim.org>
parents:
28123
diff
changeset
|
1944 (long)sid, name); |
4b322951ebac
patch 8.2.4650: "import autoload" only works with using 'runtimepath'
Bram Moolenaar <Bram@vim.org>
parents:
28123
diff
changeset
|
1945 } |
4b322951ebac
patch 8.2.4650: "import autoload" only works with using 'runtimepath'
Bram Moolenaar <Bram@vim.org>
parents:
28123
diff
changeset
|
1946 |
4b322951ebac
patch 8.2.4650: "import autoload" only works with using 'runtimepath'
Bram Moolenaar <Bram@vim.org>
parents:
28123
diff
changeset
|
1947 /* |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1948 * Find a function "name" in script "sid". |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1949 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1950 static ufunc_T * |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1951 find_func_with_sid(char_u *name, int sid) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1952 { |
27068
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1953 hashitem_T *hi; |
28249
4b322951ebac
patch 8.2.4650: "import autoload" only works with using 'runtimepath'
Bram Moolenaar <Bram@vim.org>
parents:
28123
diff
changeset
|
1954 char_u buffer[MAX_FUNC_NAME_LEN]; |
27068
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1955 |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1956 if (!SCRIPT_ID_VALID(sid)) |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1957 return NULL; // not in a script |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1958 |
28249
4b322951ebac
patch 8.2.4650: "import autoload" only works with using 'runtimepath'
Bram Moolenaar <Bram@vim.org>
parents:
28123
diff
changeset
|
1959 func_name_with_sid(name, sid, buffer); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1960 hi = hash_find(&func_hashtab, buffer); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1961 if (!HASHITEM_EMPTY(hi)) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1962 return HI2UF(hi); |
27068
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1963 return NULL; |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1964 } |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1965 |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1966 /* |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1967 * Find a function "name" in script "sid" prefixing the autoload prefix. |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1968 */ |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1969 static ufunc_T * |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1970 find_func_with_prefix(char_u *name, int sid) |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1971 { |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1972 hashitem_T *hi; |
28249
4b322951ebac
patch 8.2.4650: "import autoload" only works with using 'runtimepath'
Bram Moolenaar <Bram@vim.org>
parents:
28123
diff
changeset
|
1973 char_u buffer[MAX_FUNC_NAME_LEN]; |
27068
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1974 scriptitem_T *si; |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1975 |
27464
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
1976 if (vim_strchr(name, AUTOLOAD_CHAR) != NULL) |
27068
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1977 return NULL; // already has the prefix |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1978 if (!SCRIPT_ID_VALID(sid)) |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1979 return NULL; // not in a script |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1980 si = SCRIPT_ITEM(sid); |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1981 if (si->sn_autoload_prefix != NULL) |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1982 { |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1983 size_t len = STRLEN(si->sn_autoload_prefix) + STRLEN(name) + 1; |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1984 char_u *auto_name; |
27267
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
1985 char_u *namep; |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
1986 |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
1987 // skip a "<SNR>99_" prefix |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
1988 namep = untrans_function_name(name); |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
1989 if (namep == NULL) |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
1990 namep = name; |
27068
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1991 |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1992 // An exported function in an autoload script is stored as |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1993 // "dir#path#name". |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1994 if (len < sizeof(buffer)) |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1995 auto_name = buffer; |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1996 else |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1997 auto_name = alloc(len); |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1998 if (auto_name != NULL) |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1999 { |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
2000 vim_snprintf((char *)auto_name, len, "%s%s", |
27267
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
2001 si->sn_autoload_prefix, namep); |
27068
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
2002 hi = hash_find(&func_hashtab, auto_name); |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
2003 if (auto_name != buffer) |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
2004 vim_free(auto_name); |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
2005 if (!HASHITEM_EMPTY(hi)) |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
2006 return HI2UF(hi); |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
2007 } |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
2008 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2009 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2010 return NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2011 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2012 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2013 /* |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2014 * Find a function by name, return pointer to it in ufuncs. |
27348
9a9c34c84cd4
patch 8.2.4202: Vim9: cannot export function that exists globally
Bram Moolenaar <Bram@vim.org>
parents:
27291
diff
changeset
|
2015 * When "flags" has FFED_IS_GLOBAL don't find script-local or imported |
9a9c34c84cd4
patch 8.2.4202: Vim9: cannot export function that exists globally
Bram Moolenaar <Bram@vim.org>
parents:
27291
diff
changeset
|
2016 * functions. |
9a9c34c84cd4
patch 8.2.4202: Vim9: cannot export function that exists globally
Bram Moolenaar <Bram@vim.org>
parents:
27291
diff
changeset
|
2017 * When "flags" has "FFED_NO_GLOBAL" don't find global functions. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2018 * Return NULL for unknown function. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2019 */ |
21564
30a997217524
patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents:
21558
diff
changeset
|
2020 ufunc_T * |
27348
9a9c34c84cd4
patch 8.2.4202: Vim9: cannot export function that exists globally
Bram Moolenaar <Bram@vim.org>
parents:
27291
diff
changeset
|
2021 find_func_even_dead(char_u *name, int flags) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2022 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2023 hashitem_T *hi; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2024 ufunc_T *func; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2025 |
27348
9a9c34c84cd4
patch 8.2.4202: Vim9: cannot export function that exists globally
Bram Moolenaar <Bram@vim.org>
parents:
27291
diff
changeset
|
2026 if ((flags & FFED_IS_GLOBAL) == 0) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2027 { |
27807
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
2028 // Find script-local function before global one. |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
2029 if (in_vim9script() && eval_isnamec1(*name) |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
2030 && (name[1] != ':' || *name == 's')) |
20816
9faab49c880f
patch 8.2.0960: cannot use :import in legacy Vim script
Bram Moolenaar <Bram@vim.org>
parents:
20709
diff
changeset
|
2031 { |
26530
2fbd05a873e3
patch 8.2.3794: Vim9: cannot find script-local func using "s:"
Bram Moolenaar <Bram@vim.org>
parents:
26506
diff
changeset
|
2032 func = find_func_with_sid(name[0] == 's' && name[1] == ':' |
2fbd05a873e3
patch 8.2.3794: Vim9: cannot find script-local func using "s:"
Bram Moolenaar <Bram@vim.org>
parents:
26506
diff
changeset
|
2033 ? name + 2 : name, current_sctx.sc_sid); |
20816
9faab49c880f
patch 8.2.0960: cannot use :import in legacy Vim script
Bram Moolenaar <Bram@vim.org>
parents:
20709
diff
changeset
|
2034 if (func != NULL) |
9faab49c880f
patch 8.2.0960: cannot use :import in legacy Vim script
Bram Moolenaar <Bram@vim.org>
parents:
20709
diff
changeset
|
2035 return func; |
9faab49c880f
patch 8.2.0960: cannot use :import in legacy Vim script
Bram Moolenaar <Bram@vim.org>
parents:
20709
diff
changeset
|
2036 } |
27807
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
2037 if (in_vim9script() && STRNCMP(name, "<SNR>", 5) == 0) |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
2038 { |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
2039 char_u *p = name + 5; |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
2040 long sid; |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
2041 |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
2042 // printable "<SNR>123_Name" form |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
2043 sid = getdigits(&p); |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
2044 if (*p == '_') |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
2045 { |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
2046 func = find_func_with_sid(p + 1, (int)sid); |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
2047 if (func != NULL) |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
2048 return func; |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
2049 } |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
2050 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2051 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2052 |
27348
9a9c34c84cd4
patch 8.2.4202: Vim9: cannot export function that exists globally
Bram Moolenaar <Bram@vim.org>
parents:
27291
diff
changeset
|
2053 if ((flags & FFED_NO_GLOBAL) == 0) |
9a9c34c84cd4
patch 8.2.4202: Vim9: cannot export function that exists globally
Bram Moolenaar <Bram@vim.org>
parents:
27291
diff
changeset
|
2054 { |
9a9c34c84cd4
patch 8.2.4202: Vim9: cannot export function that exists globally
Bram Moolenaar <Bram@vim.org>
parents:
27291
diff
changeset
|
2055 hi = hash_find(&func_hashtab, |
20079
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
2056 STRNCMP(name, "g:", 2) == 0 ? name + 2 : name); |
27348
9a9c34c84cd4
patch 8.2.4202: Vim9: cannot export function that exists globally
Bram Moolenaar <Bram@vim.org>
parents:
27291
diff
changeset
|
2057 if (!HASHITEM_EMPTY(hi)) |
9a9c34c84cd4
patch 8.2.4202: Vim9: cannot export function that exists globally
Bram Moolenaar <Bram@vim.org>
parents:
27291
diff
changeset
|
2058 return HI2UF(hi); |
9a9c34c84cd4
patch 8.2.4202: Vim9: cannot export function that exists globally
Bram Moolenaar <Bram@vim.org>
parents:
27291
diff
changeset
|
2059 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2060 |
27068
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
2061 // Find autoload function if this is an autoload script. |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
2062 return find_func_with_prefix(name[0] == 's' && name[1] == ':' |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
2063 ? name + 2 : name, current_sctx.sc_sid); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2064 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2065 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2066 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2067 * Find a function by name, return pointer to it in ufuncs. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2068 * "cctx" is passed in a :def function to find imported functions. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2069 * Return NULL for unknown or dead function. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2070 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2071 ufunc_T * |
27114
98a01021e465
patch 8.2.4086: "cctx" argument of find_func_even_dead() is unused
Bram Moolenaar <Bram@vim.org>
parents:
27092
diff
changeset
|
2072 find_func(char_u *name, int is_global) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2073 { |
27348
9a9c34c84cd4
patch 8.2.4202: Vim9: cannot export function that exists globally
Bram Moolenaar <Bram@vim.org>
parents:
27291
diff
changeset
|
2074 ufunc_T *fp = find_func_even_dead(name, is_global ? FFED_IS_GLOBAL : 0); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2075 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2076 if (fp != NULL && (fp->uf_flags & FC_DEAD) == 0) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2077 return fp; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2078 return NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2079 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2080 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2081 /* |
22236
3d0632b260fd
patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents:
22188
diff
changeset
|
2082 * Return TRUE if "ufunc" is a global function. |
3d0632b260fd
patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents:
22188
diff
changeset
|
2083 */ |
3d0632b260fd
patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents:
22188
diff
changeset
|
2084 int |
3d0632b260fd
patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents:
22188
diff
changeset
|
2085 func_is_global(ufunc_T *ufunc) |
3d0632b260fd
patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents:
22188
diff
changeset
|
2086 { |
3d0632b260fd
patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents:
22188
diff
changeset
|
2087 return ufunc->uf_name[0] != K_SPECIAL; |
3d0632b260fd
patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents:
22188
diff
changeset
|
2088 } |
3d0632b260fd
patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents:
22188
diff
changeset
|
2089 |
3d0632b260fd
patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents:
22188
diff
changeset
|
2090 /* |
27464
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
2091 * Return TRUE if "ufunc" must be called with a g: prefix in Vim9 script. |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
2092 */ |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
2093 int |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
2094 func_requires_g_prefix(ufunc_T *ufunc) |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
2095 { |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
2096 return ufunc->uf_name[0] != K_SPECIAL |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
2097 && (ufunc->uf_flags & FC_LAMBDA) == 0 |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
2098 && vim_strchr(ufunc->uf_name, AUTOLOAD_CHAR) == NULL; |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
2099 } |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
2100 |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
2101 /* |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2102 * Copy the function name of "fp" to buffer "buf". |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2103 * "buf" must be able to hold the function name plus three bytes. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2104 * Takes care of script-local function names. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2105 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2106 static void |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2107 cat_func_name(char_u *buf, ufunc_T *fp) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2108 { |
22236
3d0632b260fd
patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents:
22188
diff
changeset
|
2109 if (!func_is_global(fp)) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2110 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2111 STRCPY(buf, "<SNR>"); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2112 STRCAT(buf, fp->uf_name + 3); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2113 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2114 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2115 STRCPY(buf, fp->uf_name); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2116 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2117 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2118 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2119 * Add a number variable "name" to dict "dp" with value "nr". |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2120 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2121 static void |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2122 add_nr_var( |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2123 dict_T *dp, |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2124 dictitem_T *v, |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2125 char *name, |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2126 varnumber_T nr) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2127 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2128 STRCPY(v->di_key, name); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2129 v->di_flags = DI_FLAGS_RO | DI_FLAGS_FIX; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2130 hash_add(&dp->dv_hashtab, DI2HIKEY(v)); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2131 v->di_tv.v_type = VAR_NUMBER; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2132 v->di_tv.v_lock = VAR_FIXED; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2133 v->di_tv.vval.v_number = nr; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2134 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2135 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2136 /* |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2137 * Free "fc". |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2138 */ |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2139 static void |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2140 free_funccal(funccall_T *fc) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2141 { |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2142 int i; |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
2143 |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2144 for (i = 0; i < fc->fc_ufuncs.ga_len; ++i) |
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2145 { |
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2146 ufunc_T *fp = ((ufunc_T **)(fc->fc_ufuncs.ga_data))[i]; |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2147 |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2148 // When garbage collecting a funccall_T may be freed before the |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2149 // function that references it, clear its uf_scoped field. |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2150 // The function may have been redefined and point to another |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2151 // funccall_T, don't clear it then. |
9735
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
2152 if (fp != NULL && fp->uf_scoped == fc) |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
2153 fp->uf_scoped = NULL; |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
2154 } |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2155 ga_clear(&fc->fc_ufuncs); |
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2156 |
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2157 func_ptr_unref(fc->fc_func); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2158 vim_free(fc); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2159 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2160 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2161 /* |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2162 * Free "fc" and what it contains. |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2163 * Can be called only when "fc" is kept beyond the period of it called, |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2164 * i.e. after cleanup_function_call(fc). |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2165 */ |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2166 static void |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2167 free_funccal_contents(funccall_T *fc) |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2168 { |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2169 listitem_T *li; |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2170 |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2171 // Free all l: variables. |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2172 vars_clear(&fc->fc_l_vars.dv_hashtab); |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2173 |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2174 // Free all a: variables. |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2175 vars_clear(&fc->fc_l_avars.dv_hashtab); |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2176 |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2177 // Free the a:000 variables. |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2178 FOR_ALL_LIST_ITEMS(&fc->fc_l_varlist, li) |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2179 clear_tv(&li->li_tv); |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2180 |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2181 free_funccal(fc); |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2182 } |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2183 |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2184 /* |
11299
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2185 * Handle the last part of returning from a function: free the local hashtable. |
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2186 * Unless it is still in use by a closure. |
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2187 */ |
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2188 static void |
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2189 cleanup_function_call(funccall_T *fc) |
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2190 { |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2191 int may_free_fc = fc->fc_refcount <= 0; |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2192 int free_fc = TRUE; |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2193 |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2194 current_funccal = fc->fc_caller; |
11299
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2195 |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2196 // Free all l: variables if not referred. |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2197 if (may_free_fc && fc->fc_l_vars.dv_refcount == DO_NOT_FREE_CNT) |
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2198 vars_clear(&fc->fc_l_vars.dv_hashtab); |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2199 else |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2200 free_fc = FALSE; |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2201 |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2202 // If the a:000 list and the l: and a: dicts are not referenced and |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2203 // there is no closure using it, we can free the funccall_T and what's |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2204 // in it. |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2205 if (may_free_fc && fc->fc_l_avars.dv_refcount == DO_NOT_FREE_CNT) |
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2206 vars_clear_ext(&fc->fc_l_avars.dv_hashtab, FALSE); |
11299
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2207 else |
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2208 { |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2209 int todo; |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2210 hashitem_T *hi; |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2211 dictitem_T *di; |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2212 |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2213 free_fc = FALSE; |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2214 |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2215 // Make a copy of the a: variables, since we didn't do that above. |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2216 todo = (int)fc->fc_l_avars.dv_hashtab.ht_used; |
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2217 for (hi = fc->fc_l_avars.dv_hashtab.ht_array; todo > 0; ++hi) |
11299
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2218 { |
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2219 if (!HASHITEM_EMPTY(hi)) |
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2220 { |
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2221 --todo; |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2222 di = HI2DI(hi); |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2223 copy_tv(&di->di_tv, &di->di_tv); |
11299
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2224 } |
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2225 } |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2226 } |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2227 |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2228 if (may_free_fc && fc->fc_l_varlist.lv_refcount == DO_NOT_FREE_CNT) |
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2229 fc->fc_l_varlist.lv_first = NULL; |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2230 else |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2231 { |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2232 listitem_T *li; |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2233 |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2234 free_fc = FALSE; |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2235 |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2236 // Make a copy of the a:000 items, since we didn't do that above. |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2237 FOR_ALL_LIST_ITEMS(&fc->fc_l_varlist, li) |
11299
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2238 copy_tv(&li->li_tv, &li->li_tv); |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2239 } |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2240 |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2241 if (free_fc) |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2242 free_funccal(fc); |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2243 else |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2244 { |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2245 static int made_copy = 0; |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2246 |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2247 // "fc" is still in use. This can happen when returning "a:000", |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2248 // assigning "l:" to a global variable or defining a closure. |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2249 // Link "fc" in the list for garbage collection later. |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2250 fc->fc_caller = previous_funccal; |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2251 previous_funccal = fc; |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2252 |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2253 if (want_garbage_collect) |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2254 // If garbage collector is ready, clear count. |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2255 made_copy = 0; |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2256 else if (++made_copy >= (int)((4096 * 1024) / sizeof(*fc))) |
15585
6ca8f0350723
patch 8.1.0800: may use a lot of memory when a function refers itself
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2257 { |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2258 // We have made a lot of copies, worth 4 Mbyte. This can happen |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2259 // when repetitively calling a function that creates a reference to |
15721
e84eb23f4670
patch 8.1.0868: crash if triggering garbage collector after a function call
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
2260 // itself somehow. Call the garbage collector soon to avoid using |
15585
6ca8f0350723
patch 8.1.0800: may use a lot of memory when a function refers itself
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2261 // too much memory. |
6ca8f0350723
patch 8.1.0800: may use a lot of memory when a function refers itself
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2262 made_copy = 0; |
15721
e84eb23f4670
patch 8.1.0868: crash if triggering garbage collector after a function call
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
2263 want_garbage_collect = TRUE; |
15585
6ca8f0350723
patch 8.1.0800: may use a lot of memory when a function refers itself
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2264 } |
11299
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2265 } |
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2266 } |
22324
a4ed0de125d9
patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
2267 |
a4ed0de125d9
patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
2268 /* |
26566
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
2269 * Return TRUE if "name" is a numbered function, ignoring a "g:" prefix. |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
2270 */ |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
2271 static int |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
2272 numbered_function(char_u *name) |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
2273 { |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
2274 return isdigit(*name) |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
2275 || (name[0] == 'g' && name[1] == ':' && isdigit(name[2])); |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
2276 } |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
2277 |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
2278 /* |
22324
a4ed0de125d9
patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
2279 * There are two kinds of function names: |
28047
b10fa9b17c85
patch 8.2.4548: script-local function is deleted when used in a funcref
Bram Moolenaar <Bram@vim.org>
parents:
28008
diff
changeset
|
2280 * 1. ordinary names, function defined with :function or :def; |
b10fa9b17c85
patch 8.2.4548: script-local function is deleted when used in a funcref
Bram Moolenaar <Bram@vim.org>
parents:
28008
diff
changeset
|
2281 * can start with "<SNR>123_" literally or with K_SPECIAL. |
b10fa9b17c85
patch 8.2.4548: script-local function is deleted when used in a funcref
Bram Moolenaar <Bram@vim.org>
parents:
28008
diff
changeset
|
2282 * 2. Numbered functions and lambdas: "<lambda>123" |
22324
a4ed0de125d9
patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
2283 * For the first we only count the name stored in func_hashtab as a reference, |
a4ed0de125d9
patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
2284 * using function() does not count as a reference, because the function is |
a4ed0de125d9
patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
2285 * looked up by name. |
a4ed0de125d9
patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
2286 */ |
22326
fb69b43d73f3
patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents:
22324
diff
changeset
|
2287 int |
22324
a4ed0de125d9
patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
2288 func_name_refcount(char_u *name) |
a4ed0de125d9
patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
2289 { |
28047
b10fa9b17c85
patch 8.2.4548: script-local function is deleted when used in a funcref
Bram Moolenaar <Bram@vim.org>
parents:
28008
diff
changeset
|
2290 return numbered_function(name) || (name[0] == '<' && name[1] == 'l'); |
22324
a4ed0de125d9
patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
2291 } |
a4ed0de125d9
patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
2292 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2293 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2294 * Unreference "fc": decrement the reference count and free it when it |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2295 * becomes zero. "fp" is detached from "fc". |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2296 * When "force" is TRUE we are exiting. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2297 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2298 static void |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2299 funccal_unref(funccall_T *fc, ufunc_T *fp, int force) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2300 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2301 funccall_T **pfc; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2302 int i; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2303 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2304 if (fc == NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2305 return; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2306 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2307 if (--fc->fc_refcount <= 0 && (force || ( |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2308 fc->fc_l_varlist.lv_refcount == DO_NOT_FREE_CNT |
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2309 && fc->fc_l_vars.dv_refcount == DO_NOT_FREE_CNT |
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2310 && fc->fc_l_avars.dv_refcount == DO_NOT_FREE_CNT))) |
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2311 for (pfc = &previous_funccal; *pfc != NULL; pfc = &(*pfc)->fc_caller) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2312 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2313 if (fc == *pfc) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2314 { |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2315 *pfc = fc->fc_caller; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2316 free_funccal_contents(fc); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2317 return; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2318 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2319 } |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2320 for (i = 0; i < fc->fc_ufuncs.ga_len; ++i) |
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2321 if (((ufunc_T **)(fc->fc_ufuncs.ga_data))[i] == fp) |
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2322 ((ufunc_T **)(fc->fc_ufuncs.ga_data))[i] = NULL; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2323 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2324 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2325 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2326 * Remove the function from the function hashtable. If the function was |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2327 * deleted while it still has references this was already done. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2328 * Return TRUE if the entry was deleted, FALSE if it wasn't found. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2329 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2330 static int |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2331 func_remove(ufunc_T *fp) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2332 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2333 hashitem_T *hi; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2334 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2335 // Return if it was already virtually deleted. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2336 if (fp->uf_flags & FC_DEAD) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2337 return FALSE; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2338 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2339 hi = hash_find(&func_hashtab, UF2HIKEY(fp)); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2340 if (!HASHITEM_EMPTY(hi)) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2341 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2342 // When there is a def-function index do not actually remove the |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2343 // function, so we can find the index when defining the function again. |
21558
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21552
diff
changeset
|
2344 // Do remove it when it's a copy. |
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21552
diff
changeset
|
2345 if (fp->uf_def_status == UF_COMPILED && (fp->uf_flags & FC_COPY) == 0) |
24146
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
2346 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2347 fp->uf_flags |= FC_DEAD; |
24146
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
2348 return FALSE; |
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
2349 } |
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
2350 hash_remove(&func_hashtab, hi); |
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
2351 fp->uf_flags |= FC_DELETED; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2352 return TRUE; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2353 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2354 return FALSE; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2355 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2356 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2357 static void |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2358 func_clear_items(ufunc_T *fp) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2359 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2360 ga_clear_strings(&(fp->uf_args)); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2361 ga_clear_strings(&(fp->uf_def_args)); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2362 ga_clear_strings(&(fp->uf_lines)); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2363 VIM_CLEAR(fp->uf_arg_types); |
22596
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22496
diff
changeset
|
2364 VIM_CLEAR(fp->uf_block_ids); |
19685
d64f403289db
patch 8.2.0399: various memory leaks
Bram Moolenaar <Bram@vim.org>
parents:
19579
diff
changeset
|
2365 VIM_CLEAR(fp->uf_va_name); |
21218
1f4d0375f947
patch 8.2.1160: Vim9: memory leak in allocated types
Bram Moolenaar <Bram@vim.org>
parents:
21118
diff
changeset
|
2366 clear_type_list(&fp->uf_type_list); |
23699
317018f62643
patch 8.2.2391: memory leak when creating a global function with closure
Bram Moolenaar <Bram@vim.org>
parents:
23644
diff
changeset
|
2367 |
317018f62643
patch 8.2.2391: memory leak when creating a global function with closure
Bram Moolenaar <Bram@vim.org>
parents:
23644
diff
changeset
|
2368 // Increment the refcount of this function to avoid it being freed |
317018f62643
patch 8.2.2391: memory leak when creating a global function with closure
Bram Moolenaar <Bram@vim.org>
parents:
23644
diff
changeset
|
2369 // recursively when the partial is freed. |
317018f62643
patch 8.2.2391: memory leak when creating a global function with closure
Bram Moolenaar <Bram@vim.org>
parents:
23644
diff
changeset
|
2370 fp->uf_refcount += 3; |
23249
43532077b5ff
patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents:
23237
diff
changeset
|
2371 partial_unref(fp->uf_partial); |
43532077b5ff
patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents:
23237
diff
changeset
|
2372 fp->uf_partial = NULL; |
23699
317018f62643
patch 8.2.2391: memory leak when creating a global function with closure
Bram Moolenaar <Bram@vim.org>
parents:
23644
diff
changeset
|
2373 fp->uf_refcount -= 3; |
21006
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
2374 |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
2375 #ifdef FEAT_LUA |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
2376 if (fp->uf_cb_free != NULL) |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
2377 { |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
2378 fp->uf_cb_free(fp->uf_cb_state); |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
2379 fp->uf_cb_free = NULL; |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
2380 } |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
2381 |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
2382 fp->uf_cb_state = NULL; |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
2383 fp->uf_cb = NULL; |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
2384 #endif |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2385 #ifdef FEAT_PROFILE |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2386 VIM_CLEAR(fp->uf_tml_count); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2387 VIM_CLEAR(fp->uf_tml_total); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2388 VIM_CLEAR(fp->uf_tml_self); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2389 #endif |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2390 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2391 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2392 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2393 * Free all things that a function contains. Does not free the function |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2394 * itself, use func_free() for that. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2395 * When "force" is TRUE we are exiting. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2396 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2397 static void |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2398 func_clear(ufunc_T *fp, int force) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2399 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2400 if (fp->uf_cleared) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2401 return; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2402 fp->uf_cleared = TRUE; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2403 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2404 // clear this function |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2405 func_clear_items(fp); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2406 funccal_unref(fp->uf_scoped, fp, force); |
23285
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2407 unlink_def_function(fp); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2408 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2409 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2410 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2411 * Free a function and remove it from the list of functions. Does not free |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2412 * what a function contains, call func_clear() first. |
20257
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20255
diff
changeset
|
2413 * When "force" is TRUE we are exiting. |
22326
fb69b43d73f3
patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents:
22324
diff
changeset
|
2414 * Returns OK when the function was actually freed. |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2415 */ |
22326
fb69b43d73f3
patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents:
22324
diff
changeset
|
2416 static int |
20257
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20255
diff
changeset
|
2417 func_free(ufunc_T *fp, int force) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2418 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2419 // Only remove it when not done already, otherwise we would remove a newer |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2420 // version of the function with the same name. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2421 if ((fp->uf_flags & (FC_DELETED | FC_REMOVED)) == 0) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2422 func_remove(fp); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2423 |
20257
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20255
diff
changeset
|
2424 if ((fp->uf_flags & FC_DEAD) == 0 || force) |
21791
d504fcd3d2c0
patch 8.2.1445: Vim9: function expanded name is cleared when sourcing again
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
2425 { |
22324
a4ed0de125d9
patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
2426 if (fp->uf_dfunc_idx > 0) |
a4ed0de125d9
patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
2427 unlink_def_function(fp); |
21791
d504fcd3d2c0
patch 8.2.1445: Vim9: function expanded name is cleared when sourcing again
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
2428 VIM_CLEAR(fp->uf_name_exp); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2429 vim_free(fp); |
22326
fb69b43d73f3
patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents:
22324
diff
changeset
|
2430 return OK; |
21791
d504fcd3d2c0
patch 8.2.1445: Vim9: function expanded name is cleared when sourcing again
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
2431 } |
22326
fb69b43d73f3
patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents:
22324
diff
changeset
|
2432 return FAIL; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2433 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2434 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2435 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2436 * Free all things that a function contains and free the function itself. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2437 * When "force" is TRUE we are exiting. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2438 */ |
26445
568f93dcdc62
patch 8.2.3753: Vim9: function unreferenced while called is never deleted
Bram Moolenaar <Bram@vim.org>
parents:
26439
diff
changeset
|
2439 void |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2440 func_clear_free(ufunc_T *fp, int force) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2441 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2442 func_clear(fp, force); |
22324
a4ed0de125d9
patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
2443 if (force || fp->uf_dfunc_idx == 0 || func_name_refcount(fp->uf_name) |
a4ed0de125d9
patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
2444 || (fp->uf_flags & FC_COPY)) |
20943
1693ca876049
patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
2445 func_free(fp, force); |
21479
90d859a402cc
patch 8.2.1290: Vim9: cannot replace a global function
Bram Moolenaar <Bram@vim.org>
parents:
21461
diff
changeset
|
2446 else |
90d859a402cc
patch 8.2.1290: Vim9: cannot replace a global function
Bram Moolenaar <Bram@vim.org>
parents:
21461
diff
changeset
|
2447 fp->uf_flags |= FC_DEAD; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2448 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2449 |
21558
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21552
diff
changeset
|
2450 /* |
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21552
diff
changeset
|
2451 * Copy already defined function "lambda" to a new function with name "global". |
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21552
diff
changeset
|
2452 * This is for when a compiled function defines a global function. |
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21552
diff
changeset
|
2453 */ |
23285
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2454 int |
30291
61a688be1899
patch 9.0.0481: in :def function all closures in loop get the same variables
Bram Moolenaar <Bram@vim.org>
parents:
30281
diff
changeset
|
2455 copy_lambda_to_global_func( |
30333
fc0830246f49
patch 9.0.0502: a closure in a nested loop in a :def function does not work
Bram Moolenaar <Bram@vim.org>
parents:
30291
diff
changeset
|
2456 char_u *lambda, |
fc0830246f49
patch 9.0.0502: a closure in a nested loop in a :def function does not work
Bram Moolenaar <Bram@vim.org>
parents:
30291
diff
changeset
|
2457 char_u *global, |
fc0830246f49
patch 9.0.0502: a closure in a nested loop in a :def function does not work
Bram Moolenaar <Bram@vim.org>
parents:
30291
diff
changeset
|
2458 loopvarinfo_T *loopvarinfo, |
fc0830246f49
patch 9.0.0502: a closure in a nested loop in a :def function does not work
Bram Moolenaar <Bram@vim.org>
parents:
30291
diff
changeset
|
2459 ectx_T *ectx) |
21558
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21552
diff
changeset
|
2460 { |
27348
9a9c34c84cd4
patch 8.2.4202: Vim9: cannot export function that exists globally
Bram Moolenaar <Bram@vim.org>
parents:
27291
diff
changeset
|
2461 ufunc_T *ufunc = find_func_even_dead(lambda, FFED_IS_GLOBAL); |
23249
43532077b5ff
patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents:
23237
diff
changeset
|
2462 ufunc_T *fp = NULL; |
21558
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21552
diff
changeset
|
2463 |
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21552
diff
changeset
|
2464 if (ufunc == NULL) |
23285
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2465 { |
21821
0deb6f96a5a3
patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
21791
diff
changeset
|
2466 semsg(_(e_lambda_function_not_found_str), lambda); |
23285
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2467 return FAIL; |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2468 } |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2469 |
27114
98a01021e465
patch 8.2.4086: "cctx" argument of find_func_even_dead() is unused
Bram Moolenaar <Bram@vim.org>
parents:
27092
diff
changeset
|
2470 fp = find_func(global, TRUE); |
23285
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2471 if (fp != NULL) |
21558
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21552
diff
changeset
|
2472 { |
23699
317018f62643
patch 8.2.2391: memory leak when creating a global function with closure
Bram Moolenaar <Bram@vim.org>
parents:
23644
diff
changeset
|
2473 // TODO: handle ! to overwrite |
26857
2aeea8611342
patch 8.2.3957: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26833
diff
changeset
|
2474 semsg(_(e_function_str_already_exists_add_bang_to_replace), global); |
23285
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2475 return FAIL; |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2476 } |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2477 |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2478 fp = alloc_clear(offsetof(ufunc_T, uf_name) + STRLEN(global) + 1); |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2479 if (fp == NULL) |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2480 return FAIL; |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2481 |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2482 fp->uf_varargs = ufunc->uf_varargs; |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2483 fp->uf_flags = (ufunc->uf_flags & ~FC_VIM9) | FC_COPY; |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2484 fp->uf_def_status = ufunc->uf_def_status; |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2485 fp->uf_dfunc_idx = ufunc->uf_dfunc_idx; |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2486 if (ga_copy_strings(&ufunc->uf_args, &fp->uf_args) == FAIL |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2487 || ga_copy_strings(&ufunc->uf_def_args, &fp->uf_def_args) |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2488 == FAIL |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2489 || ga_copy_strings(&ufunc->uf_lines, &fp->uf_lines) == FAIL) |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2490 goto failed; |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2491 |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2492 fp->uf_name_exp = ufunc->uf_name_exp == NULL ? NULL |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2493 : vim_strsave(ufunc->uf_name_exp); |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2494 if (ufunc->uf_arg_types != NULL) |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2495 { |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2496 fp->uf_arg_types = ALLOC_MULT(type_T *, fp->uf_args.ga_len); |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2497 if (fp->uf_arg_types == NULL) |
21558
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21552
diff
changeset
|
2498 goto failed; |
23285
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2499 mch_memmove(fp->uf_arg_types, ufunc->uf_arg_types, |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2500 sizeof(type_T *) * fp->uf_args.ga_len); |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2501 } |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2502 if (ufunc->uf_va_name != NULL) |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2503 { |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2504 fp->uf_va_name = vim_strsave(ufunc->uf_va_name); |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2505 if (fp->uf_va_name == NULL) |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2506 goto failed; |
21558
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21552
diff
changeset
|
2507 } |
23285
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2508 fp->uf_ret_type = ufunc->uf_ret_type; |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2509 |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2510 fp->uf_refcount = 1; |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2511 STRCPY(fp->uf_name, global); |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2512 hash_add(&func_hashtab, UF2HIKEY(fp)); |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2513 |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2514 // the referenced dfunc_T is now used one more time |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2515 link_def_function(fp); |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2516 |
23699
317018f62643
patch 8.2.2391: memory leak when creating a global function with closure
Bram Moolenaar <Bram@vim.org>
parents:
23644
diff
changeset
|
2517 // Create a partial to store the context of the function where it was |
317018f62643
patch 8.2.2391: memory leak when creating a global function with closure
Bram Moolenaar <Bram@vim.org>
parents:
23644
diff
changeset
|
2518 // instantiated. Only needs to be done once. Do this on the original |
317018f62643
patch 8.2.2391: memory leak when creating a global function with closure
Bram Moolenaar <Bram@vim.org>
parents:
23644
diff
changeset
|
2519 // function, "dfunc->df_ufunc" will point to it. |
23285
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2520 if ((ufunc->uf_flags & FC_CLOSURE) && ufunc->uf_partial == NULL) |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2521 { |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2522 partial_T *pt = ALLOC_CLEAR_ONE(partial_T); |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2523 |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2524 if (pt == NULL) |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2525 goto failed; |
30333
fc0830246f49
patch 9.0.0502: a closure in a nested loop in a :def function does not work
Bram Moolenaar <Bram@vim.org>
parents:
30291
diff
changeset
|
2526 if (fill_partial_and_closure(pt, ufunc, loopvarinfo, ectx) == FAIL) |
23699
317018f62643
patch 8.2.2391: memory leak when creating a global function with closure
Bram Moolenaar <Bram@vim.org>
parents:
23644
diff
changeset
|
2527 { |
28809
d0241e74bfdb
patch 8.2.4928: various white space and cosmetic mistakes
Bram Moolenaar <Bram@vim.org>
parents:
28727
diff
changeset
|
2528 vim_free(pt); |
23285
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2529 goto failed; |
23699
317018f62643
patch 8.2.2391: memory leak when creating a global function with closure
Bram Moolenaar <Bram@vim.org>
parents:
23644
diff
changeset
|
2530 } |
23285
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2531 ufunc->uf_partial = pt; |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2532 } |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2533 |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2534 return OK; |
21558
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21552
diff
changeset
|
2535 |
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21552
diff
changeset
|
2536 failed: |
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21552
diff
changeset
|
2537 func_clear_free(fp, TRUE); |
23285
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2538 return FAIL; |
21558
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21552
diff
changeset
|
2539 } |
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21552
diff
changeset
|
2540 |
22908
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2541 static int funcdepth = 0; |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2542 |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2543 /* |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2544 * Increment the function call depth count. |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2545 * Return FAIL when going over 'maxfuncdepth'. |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2546 * Otherwise return OK, must call funcdepth_decrement() later! |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2547 */ |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2548 int |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2549 funcdepth_increment(void) |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2550 { |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2551 if (funcdepth >= p_mfd) |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2552 { |
26757
3a2b222107a6
patch 8.2.3907: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26747
diff
changeset
|
2553 emsg(_(e_function_call_depth_is_higher_than_macfuncdepth)); |
22908
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2554 return FAIL; |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2555 } |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2556 ++funcdepth; |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2557 return OK; |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2558 } |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2559 |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2560 void |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2561 funcdepth_decrement(void) |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2562 { |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2563 --funcdepth; |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2564 } |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2565 |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2566 /* |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2567 * Get the current function call depth. |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2568 */ |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2569 int |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2570 funcdepth_get(void) |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2571 { |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2572 return funcdepth; |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2573 } |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2574 |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2575 /* |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2576 * Restore the function call depth. This is for cases where there is no |
23229
b545334ae654
patch 8.2.2160: various typos
Bram Moolenaar <Bram@vim.org>
parents:
23193
diff
changeset
|
2577 * guarantee funcdepth_decrement() can be called exactly the same number of |
22908
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2578 * times as funcdepth_increment(). |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2579 */ |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2580 void |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2581 funcdepth_restore(int depth) |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2582 { |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2583 funcdepth = depth; |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2584 } |
11299
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2585 |
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2586 /* |
30140
3b42bdfff7cb
patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents:
30138
diff
changeset
|
2587 * Allocate a funccall_T, link it in current_funccal and fill in "fp" and |
3b42bdfff7cb
patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents:
30138
diff
changeset
|
2588 * "rettv". |
3b42bdfff7cb
patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents:
30138
diff
changeset
|
2589 * Must be followed by one call to remove_funccal() or cleanup_function_call(). |
3b42bdfff7cb
patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents:
30138
diff
changeset
|
2590 * Returns NULL when allocation fails. |
3b42bdfff7cb
patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents:
30138
diff
changeset
|
2591 */ |
3b42bdfff7cb
patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents:
30138
diff
changeset
|
2592 funccall_T * |
3b42bdfff7cb
patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents:
30138
diff
changeset
|
2593 create_funccal(ufunc_T *fp, typval_T *rettv) |
3b42bdfff7cb
patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents:
30138
diff
changeset
|
2594 { |
3b42bdfff7cb
patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents:
30138
diff
changeset
|
2595 funccall_T *fc = ALLOC_CLEAR_ONE(funccall_T); |
3b42bdfff7cb
patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents:
30138
diff
changeset
|
2596 |
3b42bdfff7cb
patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents:
30138
diff
changeset
|
2597 if (fc == NULL) |
3b42bdfff7cb
patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents:
30138
diff
changeset
|
2598 return NULL; |
3b42bdfff7cb
patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents:
30138
diff
changeset
|
2599 fc->fc_caller = current_funccal; |
3b42bdfff7cb
patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents:
30138
diff
changeset
|
2600 current_funccal = fc; |
3b42bdfff7cb
patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents:
30138
diff
changeset
|
2601 fc->fc_func = fp; |
3b42bdfff7cb
patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents:
30138
diff
changeset
|
2602 func_ptr_ref(fp); |
3b42bdfff7cb
patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents:
30138
diff
changeset
|
2603 fc->fc_rettv = rettv; |
3b42bdfff7cb
patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents:
30138
diff
changeset
|
2604 return fc; |
3b42bdfff7cb
patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents:
30138
diff
changeset
|
2605 } |
3b42bdfff7cb
patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents:
30138
diff
changeset
|
2606 |
3b42bdfff7cb
patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents:
30138
diff
changeset
|
2607 /* |
3b42bdfff7cb
patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents:
30138
diff
changeset
|
2608 * To be called when returning from a compiled function; restores |
3b42bdfff7cb
patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents:
30138
diff
changeset
|
2609 * current_funccal. |
3b42bdfff7cb
patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents:
30138
diff
changeset
|
2610 */ |
3b42bdfff7cb
patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents:
30138
diff
changeset
|
2611 void |
3b42bdfff7cb
patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents:
30138
diff
changeset
|
2612 remove_funccal() |
3b42bdfff7cb
patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents:
30138
diff
changeset
|
2613 { |
3b42bdfff7cb
patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents:
30138
diff
changeset
|
2614 funccall_T *fc = current_funccal; |
3b42bdfff7cb
patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents:
30138
diff
changeset
|
2615 |
3b42bdfff7cb
patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents:
30138
diff
changeset
|
2616 current_funccal = fc->fc_caller; |
3b42bdfff7cb
patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents:
30138
diff
changeset
|
2617 free_funccal(fc); |
3b42bdfff7cb
patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents:
30138
diff
changeset
|
2618 } |
3b42bdfff7cb
patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents:
30138
diff
changeset
|
2619 |
3b42bdfff7cb
patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents:
30138
diff
changeset
|
2620 /* |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2621 * Call a user function. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2622 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2623 static void |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2624 call_user_func( |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2625 ufunc_T *fp, // pointer to function |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2626 int argcount, // nr of args |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2627 typval_T *argvars, // arguments |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2628 typval_T *rettv, // return value |
20433
5950284a517f
patch 8.2.0771: Vim9: cannot call a compiled closure from not compiled code
Bram Moolenaar <Bram@vim.org>
parents:
20397
diff
changeset
|
2629 funcexe_T *funcexe, // context |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2630 dict_T *selfdict) // Dictionary for "self" |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2631 { |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14430
diff
changeset
|
2632 sctx_T save_current_sctx; |
30126
01408b56f093
patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents:
30124
diff
changeset
|
2633 ectx_T *save_current_ectx; |
14323
9df95cf9ea7e
patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
2634 int using_sandbox = FALSE; |
27678
1646525507aa
patch 8.2.4365: sticky command modifiers are too sticky
Bram Moolenaar <Bram@vim.org>
parents:
27669
diff
changeset
|
2635 int save_sticky_cmdmod_flags = sticky_cmdmod_flags; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2636 funccall_T *fc; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2637 int save_did_emsg; |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2638 int default_arg_err = FALSE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2639 dictitem_T *v; |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2640 int fixvar_idx = 0; // index in fc_fixvar[] |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2641 int i; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2642 int ai; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2643 int islambda = FALSE; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2644 char_u numbuf[NUMBUFLEN]; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2645 char_u *name; |
24448
faac16c365b6
patch 8.2.2764: memory leak when default function argument is allocated
Bram Moolenaar <Bram@vim.org>
parents:
24436
diff
changeset
|
2646 typval_T *tv_to_free[MAX_FUNC_ARGS]; |
faac16c365b6
patch 8.2.2764: memory leak when default function argument is allocated
Bram Moolenaar <Bram@vim.org>
parents:
24436
diff
changeset
|
2647 int tv_to_free_len = 0; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2648 #ifdef FEAT_PROFILE |
23717
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23699
diff
changeset
|
2649 profinfo_T profile_info; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2650 #endif |
19075
af1eca322b9e
patch 8.2.0098: exe stack length can be wrong without being detected
Bram Moolenaar <Bram@vim.org>
parents:
19035
diff
changeset
|
2651 ESTACK_CHECK_DECLARATION |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2652 |
23717
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23699
diff
changeset
|
2653 #ifdef FEAT_PROFILE |
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23699
diff
changeset
|
2654 CLEAR_FIELD(profile_info); |
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23699
diff
changeset
|
2655 #endif |
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23699
diff
changeset
|
2656 |
22908
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2657 // If depth of calling is getting too high, don't execute the function. |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2658 if (funcdepth_increment() == FAIL) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2659 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2660 rettv->v_type = VAR_NUMBER; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2661 rettv->vval.v_number = -1; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2662 return; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2663 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2664 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2665 line_breakcheck(); // check for CTRL-C hit |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2666 |
30140
3b42bdfff7cb
patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents:
30138
diff
changeset
|
2667 fc = create_funccal(fp, rettv); |
15585
6ca8f0350723
patch 8.1.0800: may use a lot of memory when a function refers itself
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2668 if (fc == NULL) |
6ca8f0350723
patch 8.1.0800: may use a lot of memory when a function refers itself
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2669 return; |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2670 fc->fc_level = ex_nesting_level; |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2671 // Check if this function has a breakpoint. |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2672 fc->fc_breakpoint = dbg_find_breakpoint(FALSE, fp->uf_name, (linenr_T)0); |
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2673 fc->fc_dbg_tick = debug_tick; |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2674 // Set up fields for closure. |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2675 ga_init2(&fc->fc_ufuncs, sizeof(ufunc_T *), 1); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2676 |
20943
1693ca876049
patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
2677 if (fp->uf_def_status != UF_NOT_COMPILED) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2678 { |
23976
03819ebd3e6d
patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents:
23925
diff
changeset
|
2679 #ifdef FEAT_PROFILE |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2680 ufunc_T *caller = fc->fc_caller == NULL ? NULL : fc->fc_caller->fc_func; |
23976
03819ebd3e6d
patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents:
23925
diff
changeset
|
2681 #endif |
20538
9f921ba86d05
patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents:
20532
diff
changeset
|
2682 // Execute the function, possibly compiling it first. |
23717
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23699
diff
changeset
|
2683 #ifdef FEAT_PROFILE |
23976
03819ebd3e6d
patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents:
23925
diff
changeset
|
2684 if (do_profiling == PROF_YES) |
03819ebd3e6d
patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents:
23925
diff
changeset
|
2685 profile_may_start_func(&profile_info, fp, caller); |
23717
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23699
diff
changeset
|
2686 #endif |
27678
1646525507aa
patch 8.2.4365: sticky command modifiers are too sticky
Bram Moolenaar <Bram@vim.org>
parents:
27669
diff
changeset
|
2687 sticky_cmdmod_flags = 0; |
30138
6575d0bf6061
patch 9.0.0405: arguments in a partial not used by a :def function
Bram Moolenaar <Bram@vim.org>
parents:
30126
diff
changeset
|
2688 call_def_function(fp, argcount, argvars, 0, funcexe->fe_partial, |
30122
458162398682
patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents:
30108
diff
changeset
|
2689 fc, rettv); |
22908
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2690 funcdepth_decrement(); |
23717
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23699
diff
changeset
|
2691 #ifdef FEAT_PROFILE |
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23699
diff
changeset
|
2692 if (do_profiling == PROF_YES && (fp->uf_profiling |
23976
03819ebd3e6d
patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents:
23925
diff
changeset
|
2693 || (caller != NULL && caller->uf_profiling))) |
03819ebd3e6d
patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents:
23925
diff
changeset
|
2694 profile_may_end_func(&profile_info, fp, caller); |
23717
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23699
diff
changeset
|
2695 #endif |
30140
3b42bdfff7cb
patch 9.0.0406: deferred functions not invoked when partial func exits
Bram Moolenaar <Bram@vim.org>
parents:
30138
diff
changeset
|
2696 remove_funccal(); |
27678
1646525507aa
patch 8.2.4365: sticky command modifiers are too sticky
Bram Moolenaar <Bram@vim.org>
parents:
27669
diff
changeset
|
2697 sticky_cmdmod_flags = save_sticky_cmdmod_flags; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2698 return; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2699 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2700 |
26323
3841da4eac23
patch 8.2.3692: Vim9: cannot use :func inside a :def function
Bram Moolenaar <Bram@vim.org>
parents:
26205
diff
changeset
|
2701 islambda = fp->uf_flags & FC_LAMBDA; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2702 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2703 /* |
30126
01408b56f093
patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents:
30124
diff
changeset
|
2704 * Note about using fc->fc_fixvar[]: This is an array of FIXVAR_CNT |
01408b56f093
patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents:
30124
diff
changeset
|
2705 * variables with names up to VAR_SHORT_LEN long. This avoids having to |
01408b56f093
patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents:
30124
diff
changeset
|
2706 * alloc/free each argument variable and saves a lot of time. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2707 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2708 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2709 * Init l: variables. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2710 */ |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2711 init_var_dict(&fc->fc_l_vars, &fc->fc_l_vars_var, VAR_DEF_SCOPE); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2712 if (selfdict != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2713 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2714 // Set l:self to "selfdict". Use "name" to avoid a warning from |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2715 // some compiler that checks the destination size. |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2716 v = &fc->fc_fixvar[fixvar_idx++].var; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2717 name = v->di_key; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2718 STRCPY(name, "self"); |
15762
dff66c4670b1
patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents:
15721
diff
changeset
|
2719 v->di_flags = DI_FLAGS_RO | DI_FLAGS_FIX; |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2720 hash_add(&fc->fc_l_vars.dv_hashtab, DI2HIKEY(v)); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2721 v->di_tv.v_type = VAR_DICT; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2722 v->di_tv.v_lock = 0; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2723 v->di_tv.vval.v_dict = selfdict; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2724 ++selfdict->dv_refcount; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2725 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2726 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2727 /* |
19886
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2728 * Init a: variables, unless none found (in lambda). |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2729 * Set a:0 to "argcount" less number of named arguments, if >= 0. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2730 * Set a:000 to a list with room for the "..." arguments. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2731 */ |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2732 init_var_dict(&fc->fc_l_avars, &fc->fc_l_avars_var, VAR_SCOPE); |
19886
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2733 if ((fp->uf_flags & FC_NOARGS) == 0) |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2734 add_nr_var(&fc->fc_l_avars, &fc->fc_fixvar[fixvar_idx++].var, "0", |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2735 (varnumber_T)(argcount >= fp->uf_args.ga_len |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2736 ? argcount - fp->uf_args.ga_len : 0)); |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2737 fc->fc_l_avars.dv_lock = VAR_FIXED; |
19886
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2738 if ((fp->uf_flags & FC_NOARGS) == 0) |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2739 { |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2740 // Use "name" to avoid a warning from some compiler that checks the |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2741 // destination size. |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2742 v = &fc->fc_fixvar[fixvar_idx++].var; |
19886
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2743 name = v->di_key; |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2744 STRCPY(name, "000"); |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2745 v->di_flags = DI_FLAGS_RO | DI_FLAGS_FIX; |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2746 hash_add(&fc->fc_l_avars.dv_hashtab, DI2HIKEY(v)); |
19886
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2747 v->di_tv.v_type = VAR_LIST; |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2748 v->di_tv.v_lock = VAR_FIXED; |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2749 v->di_tv.vval.v_list = &fc->fc_l_varlist; |
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2750 } |
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2751 CLEAR_FIELD(fc->fc_l_varlist); |
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2752 fc->fc_l_varlist.lv_refcount = DO_NOT_FREE_CNT; |
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2753 fc->fc_l_varlist.lv_lock = VAR_FIXED; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2754 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2755 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2756 * Set a:firstline to "firstline" and a:lastline to "lastline". |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2757 * Set a:name to named arguments. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2758 * Set a:N to the "..." arguments. |
19886
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2759 * Skipped when no a: variables used (in lambda). |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2760 */ |
19886
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2761 if ((fp->uf_flags & FC_NOARGS) == 0) |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2762 { |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2763 add_nr_var(&fc->fc_l_avars, &fc->fc_fixvar[fixvar_idx++].var, |
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2764 "firstline", (varnumber_T)funcexe->fe_firstline); |
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2765 add_nr_var(&fc->fc_l_avars, &fc->fc_fixvar[fixvar_idx++].var, |
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2766 "lastline", (varnumber_T)funcexe->fe_lastline); |
19886
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2767 } |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2768 for (i = 0; i < argcount || i < fp->uf_args.ga_len; ++i) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2769 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2770 int addlocal = FALSE; |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2771 typval_T def_rettv; |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2772 int isdefault = FALSE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2773 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2774 ai = i - fp->uf_args.ga_len; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2775 if (ai < 0) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2776 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2777 // named argument a:name |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2778 name = FUNCARG(fp, i); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2779 if (islambda) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2780 addlocal = TRUE; |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2781 |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2782 // evaluate named argument default expression |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2783 isdefault = ai + fp->uf_def_args.ga_len >= 0 |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2784 && (i >= argcount || (argvars[i].v_type == VAR_SPECIAL |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2785 && argvars[i].vval.v_number == VVAL_NONE)); |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2786 if (isdefault) |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2787 { |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2788 char_u *default_expr = NULL; |
24448
faac16c365b6
patch 8.2.2764: memory leak when default function argument is allocated
Bram Moolenaar <Bram@vim.org>
parents:
24436
diff
changeset
|
2789 |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2790 def_rettv.v_type = VAR_NUMBER; |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2791 def_rettv.vval.v_number = -1; |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2792 |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2793 default_expr = ((char_u **)(fp->uf_def_args.ga_data)) |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2794 [ai + fp->uf_def_args.ga_len]; |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20945
diff
changeset
|
2795 if (eval1(&default_expr, &def_rettv, &EVALARG_EVALUATE) == FAIL) |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2796 { |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2797 default_arg_err = 1; |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2798 break; |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2799 } |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2800 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2801 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2802 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2803 { |
19886
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2804 if ((fp->uf_flags & FC_NOARGS) != 0) |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2805 // Bail out if no a: arguments used (in lambda). |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2806 break; |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2807 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2808 // "..." argument a:1, a:2, etc. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2809 sprintf((char *)numbuf, "%d", ai + 1); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2810 name = numbuf; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2811 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2812 if (fixvar_idx < FIXVAR_CNT && STRLEN(name) <= VAR_SHORT_LEN) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2813 { |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2814 v = &fc->fc_fixvar[fixvar_idx++].var; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2815 v->di_flags = DI_FLAGS_RO | DI_FLAGS_FIX; |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2816 STRCPY(v->di_key, name); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2817 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2818 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2819 { |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2820 v = dictitem_alloc(name); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2821 if (v == NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2822 break; |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2823 v->di_flags |= DI_FLAGS_RO | DI_FLAGS_FIX; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2824 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2825 |
17127
d244a9be99db
patch 8.1.1563: crash when using closures
Bram Moolenaar <Bram@vim.org>
parents:
16969
diff
changeset
|
2826 // Note: the values are copied directly to avoid alloc/free. |
d244a9be99db
patch 8.1.1563: crash when using closures
Bram Moolenaar <Bram@vim.org>
parents:
16969
diff
changeset
|
2827 // "argvars" must have VAR_FIXED for v_lock. |
d244a9be99db
patch 8.1.1563: crash when using closures
Bram Moolenaar <Bram@vim.org>
parents:
16969
diff
changeset
|
2828 v->di_tv = isdefault ? def_rettv : argvars[i]; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2829 v->di_tv.v_lock = VAR_FIXED; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2830 |
24448
faac16c365b6
patch 8.2.2764: memory leak when default function argument is allocated
Bram Moolenaar <Bram@vim.org>
parents:
24436
diff
changeset
|
2831 if (isdefault) |
faac16c365b6
patch 8.2.2764: memory leak when default function argument is allocated
Bram Moolenaar <Bram@vim.org>
parents:
24436
diff
changeset
|
2832 // Need to free this later, no matter where it's stored. |
faac16c365b6
patch 8.2.2764: memory leak when default function argument is allocated
Bram Moolenaar <Bram@vim.org>
parents:
24436
diff
changeset
|
2833 tv_to_free[tv_to_free_len++] = &v->di_tv; |
faac16c365b6
patch 8.2.2764: memory leak when default function argument is allocated
Bram Moolenaar <Bram@vim.org>
parents:
24436
diff
changeset
|
2834 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2835 if (addlocal) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2836 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2837 // Named arguments should be accessed without the "a:" prefix in |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2838 // lambda expressions. Add to the l: dict. |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
2839 copy_tv(&v->di_tv, &v->di_tv); |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2840 hash_add(&fc->fc_l_vars.dv_hashtab, DI2HIKEY(v)); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2841 } |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
2842 else |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2843 hash_add(&fc->fc_l_avars.dv_hashtab, DI2HIKEY(v)); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2844 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2845 if (ai >= 0 && ai < MAX_FUNC_ARGS) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2846 { |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2847 listitem_T *li = &fc->fc_l_listitems[ai]; |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2848 |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2849 li->li_tv = argvars[i]; |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2850 li->li_tv.v_lock = VAR_FIXED; |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2851 list_append(&fc->fc_l_varlist, li); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2852 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2853 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2854 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2855 // Don't redraw while executing the function. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2856 ++RedrawingDisabled; |
14323
9df95cf9ea7e
patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
2857 |
9df95cf9ea7e
patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
2858 if (fp->uf_flags & FC_SANDBOX) |
9df95cf9ea7e
patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
2859 { |
9df95cf9ea7e
patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
2860 using_sandbox = TRUE; |
9df95cf9ea7e
patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
2861 ++sandbox; |
9df95cf9ea7e
patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
2862 } |
9df95cf9ea7e
patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
2863 |
20538
9f921ba86d05
patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents:
20532
diff
changeset
|
2864 estack_push_ufunc(fp, 1); |
19075
af1eca322b9e
patch 8.2.0098: exe stack length can be wrong without being detected
Bram Moolenaar <Bram@vim.org>
parents:
19035
diff
changeset
|
2865 ESTACK_CHECK_SETUP |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2866 if (p_verbose >= 12) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2867 { |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2868 ++no_wait_return; |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2869 verbose_enter_scroll(); |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2870 |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2871 smsg(_("calling %s"), SOURCING_NAME); |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2872 if (p_verbose >= 14) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2873 { |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2874 char_u buf[MSG_BUF_LEN]; |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2875 char_u numbuf2[NUMBUFLEN]; |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2876 char_u *tofree; |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2877 char_u *s; |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2878 |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2879 msg_puts("("); |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2880 for (i = 0; i < argcount; ++i) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2881 { |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2882 if (i > 0) |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2883 msg_puts(", "); |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2884 if (argvars[i].v_type == VAR_NUMBER) |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2885 msg_outnum((long)argvars[i].vval.v_number); |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2886 else |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2887 { |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2888 // Do not want errors such as E724 here. |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2889 ++emsg_off; |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2890 s = tv2string(&argvars[i], &tofree, numbuf2, 0); |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2891 --emsg_off; |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2892 if (s != NULL) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2893 { |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2894 if (vim_strsize(s) > MSG_BUF_CLEN) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2895 { |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2896 trunc_string(s, buf, MSG_BUF_CLEN, MSG_BUF_LEN); |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2897 s = buf; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2898 } |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2899 msg_puts((char *)s); |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2900 vim_free(tofree); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2901 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2902 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2903 } |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2904 msg_puts(")"); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2905 } |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2906 msg_puts("\n"); // don't overwrite this either |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2907 |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2908 verbose_leave_scroll(); |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2909 --no_wait_return; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2910 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2911 #ifdef FEAT_PROFILE |
23976
03819ebd3e6d
patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents:
23925
diff
changeset
|
2912 if (do_profiling == PROF_YES) |
03819ebd3e6d
patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents:
23925
diff
changeset
|
2913 profile_may_start_func(&profile_info, fp, |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2914 fc->fc_caller == NULL ? NULL : fc->fc_caller->fc_func); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2915 #endif |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2916 |
27678
1646525507aa
patch 8.2.4365: sticky command modifiers are too sticky
Bram Moolenaar <Bram@vim.org>
parents:
27669
diff
changeset
|
2917 // "legacy" does not apply to commands in the function |
1646525507aa
patch 8.2.4365: sticky command modifiers are too sticky
Bram Moolenaar <Bram@vim.org>
parents:
27669
diff
changeset
|
2918 sticky_cmdmod_flags = 0; |
1646525507aa
patch 8.2.4365: sticky command modifiers are too sticky
Bram Moolenaar <Bram@vim.org>
parents:
27669
diff
changeset
|
2919 |
30126
01408b56f093
patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents:
30124
diff
changeset
|
2920 // If called from a compiled :def function the execution context must be |
01408b56f093
patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents:
30124
diff
changeset
|
2921 // hidden, any deferred functions need to be added to the function being |
01408b56f093
patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents:
30124
diff
changeset
|
2922 // executed here. |
01408b56f093
patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents:
30124
diff
changeset
|
2923 save_current_ectx = clear_currrent_ectx(); |
01408b56f093
patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents:
30124
diff
changeset
|
2924 |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14430
diff
changeset
|
2925 save_current_sctx = current_sctx; |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14430
diff
changeset
|
2926 current_sctx = fp->uf_script_ctx; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2927 save_did_emsg = did_emsg; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2928 did_emsg = FALSE; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2929 |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2930 if (default_arg_err && (fp->uf_flags & FC_ABORT)) |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2931 did_emsg = TRUE; |
19886
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2932 else if (islambda) |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2933 { |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2934 char_u *p = *(char_u **)fp->uf_lines.ga_data + 7; |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2935 |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2936 // A Lambda always has the command "return {expr}". It is much faster |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2937 // to evaluate {expr} directly. |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2938 ++ex_nesting_level; |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20945
diff
changeset
|
2939 (void)eval1(&p, rettv, &EVALARG_EVALUATE); |
19886
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2940 --ex_nesting_level; |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2941 } |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2942 else |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2943 // call do_cmdline() to execute the lines |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2944 do_cmdline(NULL, get_func_line, (void *)fc, |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2945 DOCMD_NOWAIT|DOCMD_VERBOSE|DOCMD_REPEAT); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2946 |
30065
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
2947 // Invoke functions added with ":defer". |
30122
458162398682
patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents:
30108
diff
changeset
|
2948 handle_defer_one(current_funccal); |
30065
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
2949 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2950 --RedrawingDisabled; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2951 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2952 // when the function was aborted because of an error, return -1 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2953 if ((did_emsg && (fp->uf_flags & FC_ABORT)) || rettv->v_type == VAR_UNKNOWN) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2954 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2955 clear_tv(rettv); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2956 rettv->v_type = VAR_NUMBER; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2957 rettv->vval.v_number = -1; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2958 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2959 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2960 #ifdef FEAT_PROFILE |
23976
03819ebd3e6d
patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents:
23925
diff
changeset
|
2961 if (do_profiling == PROF_YES) |
03819ebd3e6d
patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents:
23925
diff
changeset
|
2962 { |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2963 ufunc_T *caller = fc->fc_caller == NULL ? NULL : fc->fc_caller->fc_func; |
23976
03819ebd3e6d
patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents:
23925
diff
changeset
|
2964 |
03819ebd3e6d
patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents:
23925
diff
changeset
|
2965 if (fp->uf_profiling || (caller != NULL && caller->uf_profiling)) |
03819ebd3e6d
patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents:
23925
diff
changeset
|
2966 profile_may_end_func(&profile_info, fp, caller); |
03819ebd3e6d
patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents:
23925
diff
changeset
|
2967 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2968 #endif |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2969 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2970 // when being verbose, mention the return value |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2971 if (p_verbose >= 12) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2972 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2973 ++no_wait_return; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2974 verbose_enter_scroll(); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2975 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2976 if (aborting()) |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2977 smsg(_("%s aborted"), SOURCING_NAME); |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2978 else if (fc->fc_rettv->v_type == VAR_NUMBER) |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2979 smsg(_("%s returning #%ld"), SOURCING_NAME, |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2980 (long)fc->fc_rettv->vval.v_number); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2981 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2982 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2983 char_u buf[MSG_BUF_LEN]; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2984 char_u numbuf2[NUMBUFLEN]; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2985 char_u *tofree; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2986 char_u *s; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2987 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2988 // The value may be very long. Skip the middle part, so that we |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2989 // have some idea how it starts and ends. smsg() would always |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2990 // truncate it at the end. Don't want errors such as E724 here. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2991 ++emsg_off; |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
2992 s = tv2string(fc->fc_rettv, &tofree, numbuf2, 0); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2993 --emsg_off; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2994 if (s != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2995 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2996 if (vim_strsize(s) > MSG_BUF_CLEN) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2997 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2998 trunc_string(s, buf, MSG_BUF_CLEN, MSG_BUF_LEN); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2999 s = buf; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3000 } |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
3001 smsg(_("%s returning %s"), SOURCING_NAME, s); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3002 vim_free(tofree); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3003 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3004 } |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3005 msg_puts("\n"); // don't overwrite this either |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3006 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3007 verbose_leave_scroll(); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3008 --no_wait_return; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3009 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3010 |
19075
af1eca322b9e
patch 8.2.0098: exe stack length can be wrong without being detected
Bram Moolenaar <Bram@vim.org>
parents:
19035
diff
changeset
|
3011 ESTACK_CHECK_NOW |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
3012 estack_pop(); |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14430
diff
changeset
|
3013 current_sctx = save_current_sctx; |
30126
01408b56f093
patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents:
30124
diff
changeset
|
3014 restore_current_ectx(save_current_ectx); |
01408b56f093
patch 9.0.0399: using :defer in expression funcref not tested
Bram Moolenaar <Bram@vim.org>
parents:
30124
diff
changeset
|
3015 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3016 #ifdef FEAT_PROFILE |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3017 if (do_profiling == PROF_YES) |
23717
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23699
diff
changeset
|
3018 script_prof_restore(&profile_info.pi_wait_start); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3019 #endif |
14323
9df95cf9ea7e
patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
3020 if (using_sandbox) |
9df95cf9ea7e
patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
3021 --sandbox; |
27678
1646525507aa
patch 8.2.4365: sticky command modifiers are too sticky
Bram Moolenaar <Bram@vim.org>
parents:
27669
diff
changeset
|
3022 sticky_cmdmod_flags = save_sticky_cmdmod_flags; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3023 |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
3024 if (p_verbose >= 12 && SOURCING_NAME != NULL) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3025 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3026 ++no_wait_return; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3027 verbose_enter_scroll(); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3028 |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
3029 smsg(_("continuing in %s"), SOURCING_NAME); |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3030 msg_puts("\n"); // don't overwrite this either |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3031 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3032 verbose_leave_scroll(); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3033 --no_wait_return; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3034 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3035 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3036 did_emsg |= save_did_emsg; |
22908
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
3037 funcdepth_decrement(); |
24448
faac16c365b6
patch 8.2.2764: memory leak when default function argument is allocated
Bram Moolenaar <Bram@vim.org>
parents:
24436
diff
changeset
|
3038 for (i = 0; i < tv_to_free_len; ++i) |
faac16c365b6
patch 8.2.2764: memory leak when default function argument is allocated
Bram Moolenaar <Bram@vim.org>
parents:
24436
diff
changeset
|
3039 clear_tv(tv_to_free[i]); |
11299
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
3040 cleanup_function_call(fc); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3041 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3042 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3043 /* |
23252
35583da6397e
patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents:
23249
diff
changeset
|
3044 * Check the argument count for user function "fp". |
35583da6397e
patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents:
23249
diff
changeset
|
3045 * Return FCERR_UNKNOWN if OK, FCERR_TOOFEW or FCERR_TOOMANY otherwise. |
35583da6397e
patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents:
23249
diff
changeset
|
3046 */ |
35583da6397e
patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents:
23249
diff
changeset
|
3047 int |
35583da6397e
patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents:
23249
diff
changeset
|
3048 check_user_func_argcount(ufunc_T *fp, int argcount) |
35583da6397e
patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents:
23249
diff
changeset
|
3049 { |
35583da6397e
patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents:
23249
diff
changeset
|
3050 int regular_args = fp->uf_args.ga_len; |
35583da6397e
patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents:
23249
diff
changeset
|
3051 |
35583da6397e
patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents:
23249
diff
changeset
|
3052 if (argcount < regular_args - fp->uf_def_args.ga_len) |
35583da6397e
patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents:
23249
diff
changeset
|
3053 return FCERR_TOOFEW; |
35583da6397e
patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents:
23249
diff
changeset
|
3054 else if (!has_varargs(fp) && argcount > regular_args) |
35583da6397e
patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents:
23249
diff
changeset
|
3055 return FCERR_TOOMANY; |
35583da6397e
patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents:
23249
diff
changeset
|
3056 return FCERR_UNKNOWN; |
35583da6397e
patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents:
23249
diff
changeset
|
3057 } |
35583da6397e
patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents:
23249
diff
changeset
|
3058 |
35583da6397e
patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents:
23249
diff
changeset
|
3059 /* |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3060 * Call a user function after checking the arguments. |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
3061 */ |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3062 int |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3063 call_user_func_check( |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3064 ufunc_T *fp, |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3065 int argcount, |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3066 typval_T *argvars, |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3067 typval_T *rettv, |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3068 funcexe_T *funcexe, |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3069 dict_T *selfdict) |
14430
2fba714294b9
patch 8.1.0229: crash when dumping profiling data
Christian Brabandt <cb@256bit.org>
parents:
14323
diff
changeset
|
3070 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3071 int error; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3072 |
29196
e391590249a1
patch 8.2.5117: crash when calling a Lua callback from a :def function
Bram Moolenaar <Bram@vim.org>
parents:
28940
diff
changeset
|
3073 #ifdef FEAT_LUA |
e391590249a1
patch 8.2.5117: crash when calling a Lua callback from a :def function
Bram Moolenaar <Bram@vim.org>
parents:
28940
diff
changeset
|
3074 if (fp->uf_flags & FC_CFUNC) |
e391590249a1
patch 8.2.5117: crash when calling a Lua callback from a :def function
Bram Moolenaar <Bram@vim.org>
parents:
28940
diff
changeset
|
3075 { |
e391590249a1
patch 8.2.5117: crash when calling a Lua callback from a :def function
Bram Moolenaar <Bram@vim.org>
parents:
28940
diff
changeset
|
3076 cfunc_T cb = fp->uf_cb; |
e391590249a1
patch 8.2.5117: crash when calling a Lua callback from a :def function
Bram Moolenaar <Bram@vim.org>
parents:
28940
diff
changeset
|
3077 |
e391590249a1
patch 8.2.5117: crash when calling a Lua callback from a :def function
Bram Moolenaar <Bram@vim.org>
parents:
28940
diff
changeset
|
3078 return (*cb)(argcount, argvars, rettv, fp->uf_cb_state); |
e391590249a1
patch 8.2.5117: crash when calling a Lua callback from a :def function
Bram Moolenaar <Bram@vim.org>
parents:
28940
diff
changeset
|
3079 } |
e391590249a1
patch 8.2.5117: crash when calling a Lua callback from a :def function
Bram Moolenaar <Bram@vim.org>
parents:
28940
diff
changeset
|
3080 #endif |
e391590249a1
patch 8.2.5117: crash when calling a Lua callback from a :def function
Bram Moolenaar <Bram@vim.org>
parents:
28940
diff
changeset
|
3081 |
26534
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3082 if (fp->uf_flags & FC_RANGE && funcexe->fe_doesrange != NULL) |
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3083 *funcexe->fe_doesrange = TRUE; |
23252
35583da6397e
patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents:
23249
diff
changeset
|
3084 error = check_user_func_argcount(fp, argcount); |
35583da6397e
patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents:
23249
diff
changeset
|
3085 if (error != FCERR_UNKNOWN) |
35583da6397e
patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents:
23249
diff
changeset
|
3086 return error; |
35583da6397e
patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents:
23249
diff
changeset
|
3087 if ((fp->uf_flags & FC_DICT) && selfdict == NULL) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3088 error = FCERR_DICT; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3089 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3090 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3091 int did_save_redo = FALSE; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3092 save_redo_T save_redo; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3093 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3094 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3095 * Call the user function. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3096 * Save and restore search patterns, script variables and |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3097 * redo buffer. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3098 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3099 save_search_patterns(); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3100 if (!ins_compl_active()) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3101 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3102 saveRedobuff(&save_redo); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3103 did_save_redo = TRUE; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3104 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3105 ++fp->uf_calls; |
20433
5950284a517f
patch 8.2.0771: Vim9: cannot call a compiled closure from not compiled code
Bram Moolenaar <Bram@vim.org>
parents:
20397
diff
changeset
|
3106 call_user_func(fp, argcount, argvars, rettv, funcexe, |
5950284a517f
patch 8.2.0771: Vim9: cannot call a compiled closure from not compiled code
Bram Moolenaar <Bram@vim.org>
parents:
20397
diff
changeset
|
3107 (fp->uf_flags & FC_DICT) ? selfdict : NULL); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3108 if (--fp->uf_calls <= 0 && fp->uf_refcount <= 0) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3109 // Function was unreferenced while being used, free it now. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3110 func_clear_free(fp, FALSE); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3111 if (did_save_redo) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3112 restoreRedobuff(&save_redo); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3113 restore_search_patterns(); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3114 error = FCERR_NONE; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3115 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3116 return error; |
10815
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3117 } |
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3118 |
14927
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3119 static funccal_entry_T *funccal_stack = NULL; |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3120 |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3121 /* |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3122 * Save the current function call pointer, and set it to NULL. |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3123 * Used when executing autocommands and for ":source". |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3124 */ |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3125 void |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3126 save_funccal(funccal_entry_T *entry) |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3127 { |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3128 entry->top_funccal = current_funccal; |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3129 entry->next = funccal_stack; |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3130 funccal_stack = entry; |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3131 current_funccal = NULL; |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3132 } |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3133 |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3134 void |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3135 restore_funccal(void) |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3136 { |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3137 if (funccal_stack == NULL) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15138
diff
changeset
|
3138 iemsg("INTERNAL: restore_funccal()"); |
14927
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3139 else |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3140 { |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3141 current_funccal = funccal_stack->top_funccal; |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3142 funccal_stack = funccal_stack->next; |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3143 } |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3144 } |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3145 |
17370
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17251
diff
changeset
|
3146 funccall_T * |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17251
diff
changeset
|
3147 get_current_funccal(void) |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17251
diff
changeset
|
3148 { |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17251
diff
changeset
|
3149 return current_funccal; |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17251
diff
changeset
|
3150 } |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17251
diff
changeset
|
3151 |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3152 /* |
27669
5c4ab8d4472c
patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents:
27611
diff
changeset
|
3153 * Return TRUE when currently at the script level: |
5c4ab8d4472c
patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents:
27611
diff
changeset
|
3154 * - not in a function |
5c4ab8d4472c
patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents:
27611
diff
changeset
|
3155 * - not executing an autocommand |
5c4ab8d4472c
patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents:
27611
diff
changeset
|
3156 * Note that when an autocommand sources a script the result is FALSE; |
5c4ab8d4472c
patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents:
27611
diff
changeset
|
3157 */ |
5c4ab8d4472c
patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents:
27611
diff
changeset
|
3158 int |
5c4ab8d4472c
patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents:
27611
diff
changeset
|
3159 at_script_level(void) |
5c4ab8d4472c
patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents:
27611
diff
changeset
|
3160 { |
5c4ab8d4472c
patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents:
27611
diff
changeset
|
3161 return current_funccal == NULL && autocmd_match == NULL; |
5c4ab8d4472c
patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents:
27611
diff
changeset
|
3162 } |
5c4ab8d4472c
patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents:
27611
diff
changeset
|
3163 |
5c4ab8d4472c
patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents:
27611
diff
changeset
|
3164 /* |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3165 * Mark all functions of script "sid" as deleted. |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3166 */ |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3167 void |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3168 delete_script_functions(int sid) |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3169 { |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3170 hashitem_T *hi; |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3171 ufunc_T *fp; |
21564
30a997217524
patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents:
21558
diff
changeset
|
3172 long_u todo = 1; |
20193
cf13b26be258
patch 8.2.0652: compiler warning for char conversion
Bram Moolenaar <Bram@vim.org>
parents:
20189
diff
changeset
|
3173 char_u buf[30]; |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3174 size_t len; |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3175 |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3176 buf[0] = K_SPECIAL; |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3177 buf[1] = KS_EXTRA; |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3178 buf[2] = (int)KE_SNR; |
20193
cf13b26be258
patch 8.2.0652: compiler warning for char conversion
Bram Moolenaar <Bram@vim.org>
parents:
20189
diff
changeset
|
3179 sprintf((char *)buf + 3, "%d_", sid); |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3180 len = STRLEN(buf); |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3181 |
21564
30a997217524
patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents:
21558
diff
changeset
|
3182 while (todo > 0) |
30a997217524
patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents:
21558
diff
changeset
|
3183 { |
30a997217524
patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents:
21558
diff
changeset
|
3184 todo = func_hashtab.ht_used; |
30a997217524
patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents:
21558
diff
changeset
|
3185 for (hi = func_hashtab.ht_array; todo > 0; ++hi) |
30a997217524
patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents:
21558
diff
changeset
|
3186 if (!HASHITEM_EMPTY(hi)) |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3187 { |
21564
30a997217524
patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents:
21558
diff
changeset
|
3188 fp = HI2UF(hi); |
30a997217524
patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents:
21558
diff
changeset
|
3189 if (STRNCMP(fp->uf_name, buf, len) == 0) |
30a997217524
patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents:
21558
diff
changeset
|
3190 { |
30a997217524
patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents:
21558
diff
changeset
|
3191 int changed = func_hashtab.ht_changed; |
30a997217524
patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents:
21558
diff
changeset
|
3192 |
30a997217524
patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents:
21558
diff
changeset
|
3193 fp->uf_flags |= FC_DEAD; |
24146
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
3194 |
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
3195 if (fp->uf_calls > 0) |
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
3196 { |
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
3197 // Function is executing, don't free it but do remove |
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
3198 // it from the hashtable. |
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
3199 if (func_remove(fp)) |
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
3200 fp->uf_refcount--; |
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
3201 } |
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
3202 else |
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
3203 { |
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
3204 func_clear(fp, TRUE); |
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
3205 // When clearing a function another function can be |
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
3206 // cleared as a side effect. When that happens start |
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
3207 // over. |
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
3208 if (changed != func_hashtab.ht_changed) |
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
3209 break; |
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
3210 } |
21564
30a997217524
patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents:
21558
diff
changeset
|
3211 } |
30a997217524
patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents:
21558
diff
changeset
|
3212 --todo; |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3213 } |
21564
30a997217524
patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents:
21558
diff
changeset
|
3214 } |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3215 } |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3216 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3217 #if defined(EXITFREE) || defined(PROTO) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3218 void |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3219 free_all_functions(void) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3220 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3221 hashitem_T *hi; |
9844
9ce5941b77d3
commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents:
9735
diff
changeset
|
3222 ufunc_T *fp; |
9ce5941b77d3
commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents:
9735
diff
changeset
|
3223 long_u skipped = 0; |
10815
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3224 long_u todo = 1; |
21319
fb3dcd8ed14d
patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents:
21313
diff
changeset
|
3225 int changed; |
10815
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3226 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3227 // Clean up the current_funccal chain and the funccal stack. |
11299
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
3228 while (current_funccal != NULL) |
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
3229 { |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
3230 clear_tv(current_funccal->fc_rettv); |
11299
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
3231 cleanup_function_call(current_funccal); |
14927
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3232 if (current_funccal == NULL && funccal_stack != NULL) |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3233 restore_funccal(); |
11299
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
3234 } |
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
3235 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3236 // First clear what the functions contain. Since this may lower the |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3237 // reference count of a function, it may also free a function and change |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3238 // the hash table. Restart if that happens. |
10815
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3239 while (todo > 0) |
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3240 { |
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3241 todo = func_hashtab.ht_used; |
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3242 for (hi = func_hashtab.ht_array; todo > 0; ++hi) |
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3243 if (!HASHITEM_EMPTY(hi)) |
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3244 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3245 // clear the def function index now |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3246 fp = HI2UF(hi); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3247 fp->uf_flags &= ~FC_DEAD; |
20943
1693ca876049
patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
3248 fp->uf_def_status = UF_NOT_COMPILED; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3249 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3250 // Only free functions that are not refcounted, those are |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3251 // supposed to be freed when no longer referenced. |
10815
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3252 if (func_name_refcount(fp->uf_name)) |
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3253 ++skipped; |
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3254 else |
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3255 { |
21319
fb3dcd8ed14d
patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents:
21313
diff
changeset
|
3256 changed = func_hashtab.ht_changed; |
10815
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3257 func_clear(fp, TRUE); |
21319
fb3dcd8ed14d
patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents:
21313
diff
changeset
|
3258 if (changed != func_hashtab.ht_changed) |
10815
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3259 { |
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3260 skipped = 0; |
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3261 break; |
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3262 } |
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3263 } |
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3264 --todo; |
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3265 } |
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3266 } |
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3267 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3268 // Now actually free the functions. Need to start all over every time, |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3269 // because func_free() may change the hash table. |
10815
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3270 skipped = 0; |
9844
9ce5941b77d3
commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents:
9735
diff
changeset
|
3271 while (func_hashtab.ht_used > skipped) |
9ce5941b77d3
commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents:
9735
diff
changeset
|
3272 { |
9ce5941b77d3
commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents:
9735
diff
changeset
|
3273 todo = func_hashtab.ht_used; |
9ce5941b77d3
commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents:
9735
diff
changeset
|
3274 for (hi = func_hashtab.ht_array; todo > 0; ++hi) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3275 if (!HASHITEM_EMPTY(hi)) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3276 { |
9844
9ce5941b77d3
commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents:
9735
diff
changeset
|
3277 --todo; |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3278 // Only free functions that are not refcounted, those are |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3279 // supposed to be freed when no longer referenced. |
9844
9ce5941b77d3
commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents:
9735
diff
changeset
|
3280 fp = HI2UF(hi); |
9ce5941b77d3
commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents:
9735
diff
changeset
|
3281 if (func_name_refcount(fp->uf_name)) |
9ce5941b77d3
commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents:
9735
diff
changeset
|
3282 ++skipped; |
9ce5941b77d3
commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents:
9735
diff
changeset
|
3283 else |
9ce5941b77d3
commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents:
9735
diff
changeset
|
3284 { |
22326
fb69b43d73f3
patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents:
22324
diff
changeset
|
3285 if (func_free(fp, FALSE) == OK) |
fb69b43d73f3
patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents:
22324
diff
changeset
|
3286 { |
fb69b43d73f3
patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents:
22324
diff
changeset
|
3287 skipped = 0; |
fb69b43d73f3
patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents:
22324
diff
changeset
|
3288 break; |
fb69b43d73f3
patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents:
22324
diff
changeset
|
3289 } |
fb69b43d73f3
patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents:
22324
diff
changeset
|
3290 // did not actually free it |
fb69b43d73f3
patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents:
22324
diff
changeset
|
3291 ++skipped; |
9844
9ce5941b77d3
commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents:
9735
diff
changeset
|
3292 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3293 } |
9844
9ce5941b77d3
commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents:
9735
diff
changeset
|
3294 } |
9ce5941b77d3
commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents:
9735
diff
changeset
|
3295 if (skipped == 0) |
9ce5941b77d3
commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents:
9735
diff
changeset
|
3296 hash_clear(&func_hashtab); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3297 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3298 free_def_functions(); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3299 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3300 #endif |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3301 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3302 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3303 * Return TRUE if "name" looks like a builtin function name: starts with a |
27189
a10936038ec9
patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
3304 * lower case letter, doesn't contain AUTOLOAD_CHAR or ':', no "." after the |
a10936038ec9
patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
3305 * name. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3306 * "len" is the length of "name", or -1 for NUL terminated. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3307 */ |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3308 int |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3309 builtin_function(char_u *name, int len) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3310 { |
27189
a10936038ec9
patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
3311 int i; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3312 |
20079
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
3313 if (!ASCII_ISLOWER(name[0]) || name[1] == ':') |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3314 return FALSE; |
27189
a10936038ec9
patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
3315 for (i = 0; name[i] != NUL && (len < 0 || i < len); ++i) |
a10936038ec9
patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
3316 { |
a10936038ec9
patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
3317 if (name[i] == AUTOLOAD_CHAR) |
a10936038ec9
patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
3318 return FALSE; |
a10936038ec9
patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
3319 if (!eval_isnamec(name[i])) |
a10936038ec9
patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
3320 { |
a10936038ec9
patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
3321 // "name.something" is not a builtin function |
a10936038ec9
patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
3322 if (name[i] == '.') |
a10936038ec9
patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
3323 return FALSE; |
a10936038ec9
patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
3324 break; |
a10936038ec9
patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
3325 } |
a10936038ec9
patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
3326 } |
a10936038ec9
patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
3327 return TRUE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3328 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3329 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3330 int |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3331 func_call( |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3332 char_u *name, |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3333 typval_T *args, |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3334 partial_T *partial, |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3335 dict_T *selfdict, |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3336 typval_T *rettv) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3337 { |
19201
e7b4fff348dd
patch 8.2.0159: non-materialized range() list causes problems
Bram Moolenaar <Bram@vim.org>
parents:
19183
diff
changeset
|
3338 list_T *l = args->vval.v_list; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3339 listitem_T *item; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3340 typval_T argv[MAX_FUNC_ARGS + 1]; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3341 int argc = 0; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3342 int r = 0; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3343 |
20392
4c317d8c1051
patch 8.2.0751: Vim9: performance can be improved
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
3344 CHECK_LIST_MATERIALIZE(l); |
19934
3ff714d765ba
patch 8.2.0523: loops are repeated
Bram Moolenaar <Bram@vim.org>
parents:
19912
diff
changeset
|
3345 FOR_ALL_LIST_ITEMS(l, item) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3346 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3347 if (argc == MAX_FUNC_ARGS - (partial == NULL ? 0 : partial->pt_argc)) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3348 { |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
3349 emsg(_(e_too_many_arguments)); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3350 break; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3351 } |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3352 // Make a copy of each argument. This is needed to be able to set |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3353 // v_lock to VAR_FIXED in the copy without changing the original list. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3354 copy_tv(&item->li_tv, &argv[argc++]); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3355 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3356 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3357 if (item == NULL) |
17606
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17462
diff
changeset
|
3358 { |
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17462
diff
changeset
|
3359 funcexe_T funcexe; |
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17462
diff
changeset
|
3360 |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
3361 CLEAR_FIELD(funcexe); |
26534
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3362 funcexe.fe_firstline = curwin->w_cursor.lnum; |
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3363 funcexe.fe_lastline = curwin->w_cursor.lnum; |
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3364 funcexe.fe_evaluate = TRUE; |
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3365 funcexe.fe_partial = partial; |
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3366 funcexe.fe_selfdict = selfdict; |
17606
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17462
diff
changeset
|
3367 r = call_func(name, -1, rettv, argc, argv, &funcexe); |
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17462
diff
changeset
|
3368 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3369 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3370 // Free the arguments. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3371 while (argc > 0) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3372 clear_tv(&argv[--argc]); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3373 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3374 return r; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3375 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3376 |
18104
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
17883
diff
changeset
|
3377 static int callback_depth = 0; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
17883
diff
changeset
|
3378 |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
17883
diff
changeset
|
3379 int |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
17883
diff
changeset
|
3380 get_callback_depth(void) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
17883
diff
changeset
|
3381 { |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
17883
diff
changeset
|
3382 return callback_depth; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
17883
diff
changeset
|
3383 } |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
17883
diff
changeset
|
3384 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3385 /* |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3386 * Invoke call_func() with a callback. |
26452
65b4109a4297
patch 8.2.3756: might crash when callback is not valid
Bram Moolenaar <Bram@vim.org>
parents:
26445
diff
changeset
|
3387 * Returns FAIL if the callback could not be called. |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3388 */ |
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3389 int |
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3390 call_callback( |
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3391 callback_T *callback, |
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3392 int len, // length of "name" or -1 to use strlen() |
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3393 typval_T *rettv, // return value goes here |
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3394 int argcount, // number of "argvars" |
17606
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17462
diff
changeset
|
3395 typval_T *argvars) // vars for arguments, must have "argcount" |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3396 // PLUS ONE elements! |
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3397 { |
17606
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17462
diff
changeset
|
3398 funcexe_T funcexe; |
18104
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
17883
diff
changeset
|
3399 int ret; |
17606
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17462
diff
changeset
|
3400 |
26452
65b4109a4297
patch 8.2.3756: might crash when callback is not valid
Bram Moolenaar <Bram@vim.org>
parents:
26445
diff
changeset
|
3401 if (callback->cb_name == NULL || *callback->cb_name == NUL) |
65b4109a4297
patch 8.2.3756: might crash when callback is not valid
Bram Moolenaar <Bram@vim.org>
parents:
26445
diff
changeset
|
3402 return FAIL; |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
3403 CLEAR_FIELD(funcexe); |
26534
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3404 funcexe.fe_evaluate = TRUE; |
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3405 funcexe.fe_partial = callback->cb_partial; |
18104
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
17883
diff
changeset
|
3406 ++callback_depth; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
17883
diff
changeset
|
3407 ret = call_func(callback->cb_name, len, rettv, argcount, argvars, &funcexe); |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
17883
diff
changeset
|
3408 --callback_depth; |
26538
dfa658800f21
patch 8.2.3798: a :def callback function postpones an error message
Bram Moolenaar <Bram@vim.org>
parents:
26534
diff
changeset
|
3409 |
dfa658800f21
patch 8.2.3798: a :def callback function postpones an error message
Bram Moolenaar <Bram@vim.org>
parents:
26534
diff
changeset
|
3410 // When a :def function was called that uses :try an error would be turned |
dfa658800f21
patch 8.2.3798: a :def callback function postpones an error message
Bram Moolenaar <Bram@vim.org>
parents:
26534
diff
changeset
|
3411 // into an exception. Need to give the error here. |
26540
682ff45f289f
patch 8.2.3799: edit test hangs or fails
Bram Moolenaar <Bram@vim.org>
parents:
26538
diff
changeset
|
3412 if (need_rethrow && current_exception != NULL && trylevel == 0) |
26538
dfa658800f21
patch 8.2.3798: a :def callback function postpones an error message
Bram Moolenaar <Bram@vim.org>
parents:
26534
diff
changeset
|
3413 { |
dfa658800f21
patch 8.2.3798: a :def callback function postpones an error message
Bram Moolenaar <Bram@vim.org>
parents:
26534
diff
changeset
|
3414 need_rethrow = FALSE; |
dfa658800f21
patch 8.2.3798: a :def callback function postpones an error message
Bram Moolenaar <Bram@vim.org>
parents:
26534
diff
changeset
|
3415 handle_did_throw(); |
dfa658800f21
patch 8.2.3798: a :def callback function postpones an error message
Bram Moolenaar <Bram@vim.org>
parents:
26534
diff
changeset
|
3416 } |
dfa658800f21
patch 8.2.3798: a :def callback function postpones an error message
Bram Moolenaar <Bram@vim.org>
parents:
26534
diff
changeset
|
3417 |
18104
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
17883
diff
changeset
|
3418 return ret; |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3419 } |
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3420 |
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3421 /* |
26388
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26348
diff
changeset
|
3422 * call the 'callback' function and return the result as a number. |
26452
65b4109a4297
patch 8.2.3756: might crash when callback is not valid
Bram Moolenaar <Bram@vim.org>
parents:
26445
diff
changeset
|
3423 * Returns -2 when calling the function fails. Uses argv[0] to argv[argc - 1] |
26388
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26348
diff
changeset
|
3424 * for the function arguments. argv[argc] should have type VAR_UNKNOWN. |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26348
diff
changeset
|
3425 */ |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26348
diff
changeset
|
3426 varnumber_T |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26348
diff
changeset
|
3427 call_callback_retnr( |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26348
diff
changeset
|
3428 callback_T *callback, |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26348
diff
changeset
|
3429 int argcount, // number of "argvars" |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26348
diff
changeset
|
3430 typval_T *argvars) // vars for arguments, must have "argcount" |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26348
diff
changeset
|
3431 // PLUS ONE elements! |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26348
diff
changeset
|
3432 { |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26348
diff
changeset
|
3433 typval_T rettv; |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26348
diff
changeset
|
3434 varnumber_T retval; |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26348
diff
changeset
|
3435 |
27285
53edd190a607
patch 8.2.4171: cannot invoke option function using autoload import
Bram Moolenaar <Bram@vim.org>
parents:
27279
diff
changeset
|
3436 if (call_callback(callback, -1, &rettv, argcount, argvars) == FAIL) |
26452
65b4109a4297
patch 8.2.3756: might crash when callback is not valid
Bram Moolenaar <Bram@vim.org>
parents:
26445
diff
changeset
|
3437 return -2; |
26388
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26348
diff
changeset
|
3438 |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26348
diff
changeset
|
3439 retval = tv_get_number_chk(&rettv, NULL); |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26348
diff
changeset
|
3440 clear_tv(&rettv); |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26348
diff
changeset
|
3441 return retval; |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26348
diff
changeset
|
3442 } |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26348
diff
changeset
|
3443 |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26348
diff
changeset
|
3444 /* |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3445 * Give an error message for the result of a function. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3446 * Nothing if "error" is FCERR_NONE. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3447 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3448 void |
26506
4a1d2abc2016
patch 8.2.3783: confusing error for using a variable as a function
Bram Moolenaar <Bram@vim.org>
parents:
26504
diff
changeset
|
3449 user_func_error(int error, char_u *name, funcexe_T *funcexe) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3450 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3451 switch (error) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3452 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3453 case FCERR_UNKNOWN: |
26506
4a1d2abc2016
patch 8.2.3783: confusing error for using a variable as a function
Bram Moolenaar <Bram@vim.org>
parents:
26504
diff
changeset
|
3454 if (funcexe->fe_found_var) |
28263
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28249
diff
changeset
|
3455 emsg_funcname(e_not_callable_type_str, name); |
26506
4a1d2abc2016
patch 8.2.3783: confusing error for using a variable as a function
Bram Moolenaar <Bram@vim.org>
parents:
26504
diff
changeset
|
3456 else |
26602
fac6673086df
patch 8.2.3830: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26574
diff
changeset
|
3457 emsg_funcname(e_unknown_function_str, name); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3458 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3459 case FCERR_NOTMETHOD: |
28263
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28249
diff
changeset
|
3460 emsg_funcname(e_cannot_use_function_as_method_str, name); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3461 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3462 case FCERR_DELETED: |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
3463 emsg_funcname(e_function_was_deleted_str, name); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3464 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3465 case FCERR_TOOMANY: |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
3466 emsg_funcname(e_too_many_arguments_for_function_str, name); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3467 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3468 case FCERR_TOOFEW: |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
3469 emsg_funcname(e_not_enough_arguments_for_function_str, name); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3470 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3471 case FCERR_SCRIPT: |
28263
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28249
diff
changeset
|
3472 emsg_funcname(e_using_sid_not_in_script_context_str, name); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3473 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3474 case FCERR_DICT: |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
3475 emsg_funcname(e_calling_dict_function_without_dictionary_str, |
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
3476 name); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3477 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3478 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3479 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3480 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3481 /* |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3482 * Call a function with its resolved parameters |
9626
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9612
diff
changeset
|
3483 * |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3484 * Return FAIL when the function can't be called, OK otherwise. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3485 * Also returns OK when an error was encountered while executing the function. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3486 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3487 int |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3488 call_func( |
16634
a1ba0bd74e7d
patch 8.1.1319: computing function length name in many places
Bram Moolenaar <Bram@vim.org>
parents:
16615
diff
changeset
|
3489 char_u *funcname, // name of the function |
a1ba0bd74e7d
patch 8.1.1319: computing function length name in many places
Bram Moolenaar <Bram@vim.org>
parents:
16615
diff
changeset
|
3490 int len, // length of "name" or -1 to use strlen() |
a1ba0bd74e7d
patch 8.1.1319: computing function length name in many places
Bram Moolenaar <Bram@vim.org>
parents:
16615
diff
changeset
|
3491 typval_T *rettv, // return value goes here |
a1ba0bd74e7d
patch 8.1.1319: computing function length name in many places
Bram Moolenaar <Bram@vim.org>
parents:
16615
diff
changeset
|
3492 int argcount_in, // number of "argvars" |
a1ba0bd74e7d
patch 8.1.1319: computing function length name in many places
Bram Moolenaar <Bram@vim.org>
parents:
16615
diff
changeset
|
3493 typval_T *argvars_in, // vars for arguments, must have "argcount" |
a1ba0bd74e7d
patch 8.1.1319: computing function length name in many places
Bram Moolenaar <Bram@vim.org>
parents:
16615
diff
changeset
|
3494 // PLUS ONE elements! |
17606
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17462
diff
changeset
|
3495 funcexe_T *funcexe) // more arguments |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3496 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3497 int ret = FAIL; |
19013
dd9ab0674eec
patch 8.2.0067: ERROR_UNKNOWN clashes on some systems
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
3498 int error = FCERR_NONE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3499 int i; |
19886
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
3500 ufunc_T *fp = NULL; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3501 char_u fname_buf[FLEN_FIXED + 1]; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3502 char_u *tofree = NULL; |
19886
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
3503 char_u *fname = NULL; |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
3504 char_u *name = NULL; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3505 int argcount = argcount_in; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3506 typval_T *argvars = argvars_in; |
26534
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3507 dict_T *selfdict = funcexe->fe_selfdict; |
17638
9ffec4eb8d33
patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents:
17612
diff
changeset
|
3508 typval_T argv[MAX_FUNC_ARGS + 1]; // used when "partial" or |
26534
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3509 // "funcexe->fe_basetv" is not NULL |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3510 int argv_clear = 0; |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3511 int argv_base = 0; |
26534
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3512 partial_T *partial = funcexe->fe_partial; |
25137
34f18d4081af
patch 8.2.3105: Vim9: type of partial is wrong when it has arguments
Bram Moolenaar <Bram@vim.org>
parents:
25104
diff
changeset
|
3513 type_T check_type; |
26833
434eaef2ac62
patch 8.2.3945: Vim9: partial variable argument types are wrong
Bram Moolenaar <Bram@vim.org>
parents:
26804
diff
changeset
|
3514 type_T *check_type_args[MAX_FUNC_ARGS]; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3515 |
17883
6249953b0609
patch 8.1.1938: may crash when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3516 // Initialize rettv so that it is safe for caller to invoke clear_tv(rettv) |
6249953b0609
patch 8.1.1938: may crash when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3517 // even when call_func() returns FAIL. |
6249953b0609
patch 8.1.1938: may crash when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3518 rettv->v_type = VAR_UNKNOWN; |
6249953b0609
patch 8.1.1938: may crash when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3519 |
19886
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
3520 if (partial != NULL) |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
3521 fp = partial->pt_func; |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
3522 if (fp == NULL) |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
3523 { |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
3524 // Make a copy of the name, if it comes from a funcref variable it |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
3525 // could be changed or deleted in the called function. |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
3526 name = len > 0 ? vim_strnsave(funcname, len) : vim_strsave(funcname); |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
3527 if (name == NULL) |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
3528 return ret; |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
3529 |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
3530 fname = fname_trans_sid(name, fname_buf, &tofree, &error); |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
3531 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3532 |
26534
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3533 if (funcexe->fe_doesrange != NULL) |
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3534 *funcexe->fe_doesrange = FALSE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3535 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3536 if (partial != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3537 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3538 // When the function has a partial with a dict and there is a dict |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3539 // argument, use the dict argument. That is backwards compatible. |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3540 // When the dict was bound explicitly use the one from the partial. |
17606
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17462
diff
changeset
|
3541 if (partial->pt_dict != NULL && (selfdict == NULL || !partial->pt_auto)) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3542 selfdict = partial->pt_dict; |
19013
dd9ab0674eec
patch 8.2.0067: ERROR_UNKNOWN clashes on some systems
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
3543 if (error == FCERR_NONE && partial->pt_argc > 0) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3544 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3545 for (argv_clear = 0; argv_clear < partial->pt_argc; ++argv_clear) |
18576
e9675870c480
patch 8.1.2282: crash when passing many arguments through a partial
Bram Moolenaar <Bram@vim.org>
parents:
18572
diff
changeset
|
3546 { |
e9675870c480
patch 8.1.2282: crash when passing many arguments through a partial
Bram Moolenaar <Bram@vim.org>
parents:
18572
diff
changeset
|
3547 if (argv_clear + argcount_in >= MAX_FUNC_ARGS) |
e9675870c480
patch 8.1.2282: crash when passing many arguments through a partial
Bram Moolenaar <Bram@vim.org>
parents:
18572
diff
changeset
|
3548 { |
19013
dd9ab0674eec
patch 8.2.0067: ERROR_UNKNOWN clashes on some systems
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
3549 error = FCERR_TOOMANY; |
18576
e9675870c480
patch 8.1.2282: crash when passing many arguments through a partial
Bram Moolenaar <Bram@vim.org>
parents:
18572
diff
changeset
|
3550 goto theend; |
e9675870c480
patch 8.1.2282: crash when passing many arguments through a partial
Bram Moolenaar <Bram@vim.org>
parents:
18572
diff
changeset
|
3551 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3552 copy_tv(&partial->pt_argv[argv_clear], &argv[argv_clear]); |
18576
e9675870c480
patch 8.1.2282: crash when passing many arguments through a partial
Bram Moolenaar <Bram@vim.org>
parents:
18572
diff
changeset
|
3553 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3554 for (i = 0; i < argcount_in; ++i) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3555 argv[i + argv_clear] = argvars_in[i]; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3556 argvars = argv; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3557 argcount = partial->pt_argc + argcount_in; |
25137
34f18d4081af
patch 8.2.3105: Vim9: type of partial is wrong when it has arguments
Bram Moolenaar <Bram@vim.org>
parents:
25104
diff
changeset
|
3558 |
26534
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3559 if (funcexe->fe_check_type != NULL |
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3560 && funcexe->fe_check_type->tt_argcount != -1) |
25137
34f18d4081af
patch 8.2.3105: Vim9: type of partial is wrong when it has arguments
Bram Moolenaar <Bram@vim.org>
parents:
25104
diff
changeset
|
3561 { |
26534
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3562 // Now funcexe->fe_check_type is missing the added arguments, |
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3563 // make a copy of the type with the correction. |
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3564 check_type = *funcexe->fe_check_type; |
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3565 funcexe->fe_check_type = &check_type; |
26833
434eaef2ac62
patch 8.2.3945: Vim9: partial variable argument types are wrong
Bram Moolenaar <Bram@vim.org>
parents:
26804
diff
changeset
|
3566 check_type.tt_args = check_type_args; |
434eaef2ac62
patch 8.2.3945: Vim9: partial variable argument types are wrong
Bram Moolenaar <Bram@vim.org>
parents:
26804
diff
changeset
|
3567 CLEAR_FIELD(check_type_args); |
434eaef2ac62
patch 8.2.3945: Vim9: partial variable argument types are wrong
Bram Moolenaar <Bram@vim.org>
parents:
26804
diff
changeset
|
3568 for (i = 0; i < check_type.tt_argcount; ++i) |
434eaef2ac62
patch 8.2.3945: Vim9: partial variable argument types are wrong
Bram Moolenaar <Bram@vim.org>
parents:
26804
diff
changeset
|
3569 check_type_args[i + partial->pt_argc] = |
434eaef2ac62
patch 8.2.3945: Vim9: partial variable argument types are wrong
Bram Moolenaar <Bram@vim.org>
parents:
26804
diff
changeset
|
3570 check_type.tt_args[i]; |
25137
34f18d4081af
patch 8.2.3105: Vim9: type of partial is wrong when it has arguments
Bram Moolenaar <Bram@vim.org>
parents:
25104
diff
changeset
|
3571 check_type.tt_argcount += partial->pt_argc; |
34f18d4081af
patch 8.2.3105: Vim9: type of partial is wrong when it has arguments
Bram Moolenaar <Bram@vim.org>
parents:
25104
diff
changeset
|
3572 check_type.tt_min_argcount += partial->pt_argc; |
34f18d4081af
patch 8.2.3105: Vim9: type of partial is wrong when it has arguments
Bram Moolenaar <Bram@vim.org>
parents:
25104
diff
changeset
|
3573 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3574 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3575 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3576 |
26534
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3577 if (error == FCERR_NONE && funcexe->fe_check_type != NULL |
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3578 && funcexe->fe_evaluate) |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
3579 { |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
3580 // Check that the argument types are OK for the types of the funcref. |
27171
374c7d5a096a
patch 8.2.4114: Vim9: type checking for a funcref does not work for method
Bram Moolenaar <Bram@vim.org>
parents:
27114
diff
changeset
|
3581 if (check_argument_types(funcexe->fe_check_type, |
374c7d5a096a
patch 8.2.4114: Vim9: type checking for a funcref does not work for method
Bram Moolenaar <Bram@vim.org>
parents:
27114
diff
changeset
|
3582 argvars, argcount, funcexe->fe_basetv, |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
3583 (name != NULL) ? name : funcname) == FAIL) |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
3584 error = FCERR_OTHER; |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
3585 } |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
3586 |
26534
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3587 if (error == FCERR_NONE && funcexe->fe_evaluate) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3588 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3589 char_u *rfname = fname; |
21586
5470c36ed7e6
patch 8.2.1343: Vim9: cannot find global function when using g:
Bram Moolenaar <Bram@vim.org>
parents:
21566
diff
changeset
|
3590 int is_global = FALSE; |
5470c36ed7e6
patch 8.2.1343: Vim9: cannot find global function when using g:
Bram Moolenaar <Bram@vim.org>
parents:
21566
diff
changeset
|
3591 |
5470c36ed7e6
patch 8.2.1343: Vim9: cannot find global function when using g:
Bram Moolenaar <Bram@vim.org>
parents:
21566
diff
changeset
|
3592 // Skip "g:" before a function name. |
19886
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
3593 if (fp == NULL && fname[0] == 'g' && fname[1] == ':') |
21586
5470c36ed7e6
patch 8.2.1343: Vim9: cannot find global function when using g:
Bram Moolenaar <Bram@vim.org>
parents:
21566
diff
changeset
|
3594 { |
5470c36ed7e6
patch 8.2.1343: Vim9: cannot find global function when using g:
Bram Moolenaar <Bram@vim.org>
parents:
21566
diff
changeset
|
3595 is_global = TRUE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3596 rfname = fname + 2; |
21586
5470c36ed7e6
patch 8.2.1343: Vim9: cannot find global function when using g:
Bram Moolenaar <Bram@vim.org>
parents:
21566
diff
changeset
|
3597 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3598 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3599 rettv->v_type = VAR_NUMBER; // default rettv is number zero |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3600 rettv->vval.v_number = 0; |
19013
dd9ab0674eec
patch 8.2.0067: ERROR_UNKNOWN clashes on some systems
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
3601 error = FCERR_UNKNOWN; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3602 |
19886
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
3603 if (fp != NULL || !builtin_function(rfname, -1)) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3604 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3605 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3606 * User defined function. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3607 */ |
19886
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
3608 if (fp == NULL) |
27464
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
3609 { |
27114
98a01021e465
patch 8.2.4086: "cctx" argument of find_func_even_dead() is unused
Bram Moolenaar <Bram@vim.org>
parents:
27092
diff
changeset
|
3610 fp = find_func(rfname, is_global); |
27464
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
3611 if (fp != NULL && !is_global && in_vim9script() |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
3612 && func_requires_g_prefix(fp)) |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
3613 // In Vim9 script g: is required to find a global |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
3614 // non-autoload function. |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
3615 fp = NULL; |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
3616 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3617 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3618 // Trigger FuncUndefined event, may load the function. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3619 if (fp == NULL |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3620 && apply_autocmds(EVENT_FUNCUNDEFINED, |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3621 rfname, rfname, TRUE, NULL) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3622 && !aborting()) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3623 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3624 // executed an autocommand, search for the function again |
27114
98a01021e465
patch 8.2.4086: "cctx" argument of find_func_even_dead() is unused
Bram Moolenaar <Bram@vim.org>
parents:
27092
diff
changeset
|
3625 fp = find_func(rfname, is_global); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3626 } |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3627 // Try loading a package. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3628 if (fp == NULL && script_autoload(rfname, TRUE) && !aborting()) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3629 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3630 // loaded a package, search for the function again |
27114
98a01021e465
patch 8.2.4086: "cctx" argument of find_func_even_dead() is unused
Bram Moolenaar <Bram@vim.org>
parents:
27092
diff
changeset
|
3631 fp = find_func(rfname, is_global); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3632 } |
20079
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
3633 if (fp == NULL) |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
3634 { |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
3635 char_u *p = untrans_function_name(rfname); |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
3636 |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
3637 // If using Vim9 script try not local to the script. |
21747
7e1316c6d0eb
patch 8.2.1423: Vim9: find global function when looking for script-local
Bram Moolenaar <Bram@vim.org>
parents:
21737
diff
changeset
|
3638 // Don't do this if the name starts with "s:". |
7e1316c6d0eb
patch 8.2.1423: Vim9: find global function when looking for script-local
Bram Moolenaar <Bram@vim.org>
parents:
21737
diff
changeset
|
3639 if (p != NULL && (funcname[0] != 's' || funcname[1] != ':')) |
27114
98a01021e465
patch 8.2.4086: "cctx" argument of find_func_even_dead() is unused
Bram Moolenaar <Bram@vim.org>
parents:
27092
diff
changeset
|
3640 fp = find_func(p, is_global); |
20079
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
3641 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3642 |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
3643 if (fp != NULL && (fp->uf_flags & FC_DELETED)) |
19013
dd9ab0674eec
patch 8.2.0067: ERROR_UNKNOWN clashes on some systems
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
3644 error = FCERR_DELETED; |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
3645 else if (fp != NULL) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3646 { |
26534
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3647 if (funcexe->fe_argv_func != NULL) |
18572
23fef64352a1
patch 8.1.2280: crash when passing partial to substitute()
Bram Moolenaar <Bram@vim.org>
parents:
18536
diff
changeset
|
3648 // postponed filling in the arguments, do it now |
26534
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3649 argcount = funcexe->fe_argv_func(argcount, argvars, |
30281
d3cfd12839ef
patch 9.0.0476: varargs does not work for replacement function of substitute()
Bram Moolenaar <Bram@vim.org>
parents:
30166
diff
changeset
|
3650 argv_clear, fp); |
26534
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3651 |
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3652 if (funcexe->fe_basetv != NULL) |
17638
9ffec4eb8d33
patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents:
17612
diff
changeset
|
3653 { |
9ffec4eb8d33
patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents:
17612
diff
changeset
|
3654 // Method call: base->Method() |
9ffec4eb8d33
patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents:
17612
diff
changeset
|
3655 mch_memmove(&argv[1], argvars, sizeof(typval_T) * argcount); |
26534
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3656 argv[0] = *funcexe->fe_basetv; |
17638
9ffec4eb8d33
patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents:
17612
diff
changeset
|
3657 argcount++; |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3658 argvars = argv; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3659 argv_base = 1; |
17638
9ffec4eb8d33
patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents:
17612
diff
changeset
|
3660 } |
9ffec4eb8d33
patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents:
17612
diff
changeset
|
3661 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3662 error = call_user_func_check(fp, argcount, argvars, rettv, |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3663 funcexe, selfdict); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3664 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3665 } |
26534
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3666 else if (funcexe->fe_basetv != NULL) |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3667 { |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3668 /* |
17638
9ffec4eb8d33
patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents:
17612
diff
changeset
|
3669 * expr->method(): Find the method name in the table, call its |
9ffec4eb8d33
patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents:
17612
diff
changeset
|
3670 * implementation with the base as one of the arguments. |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3671 */ |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3672 error = call_internal_method(fname, argcount, argvars, rettv, |
26534
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3673 funcexe->fe_basetv); |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3674 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3675 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3676 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3677 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3678 * Find the function name in the table, call its implementation. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3679 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3680 error = call_internal_func(fname, argcount, argvars, rettv); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3681 } |
21586
5470c36ed7e6
patch 8.2.1343: Vim9: cannot find global function when using g:
Bram Moolenaar <Bram@vim.org>
parents:
21566
diff
changeset
|
3682 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3683 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3684 * The function call (or "FuncUndefined" autocommand sequence) might |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3685 * have been aborted by an error, an interrupt, or an explicitly thrown |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3686 * exception that has not been caught so far. This situation can be |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3687 * tested for by calling aborting(). For an error in an internal |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3688 * function or for the "E132" error in call_user_func(), however, the |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3689 * throw point at which the "force_abort" flag (temporarily reset by |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3690 * emsg()) is normally updated has not been reached yet. We need to |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3691 * update that flag first to make aborting() reliable. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3692 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3693 update_force_abort(); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3694 } |
19013
dd9ab0674eec
patch 8.2.0067: ERROR_UNKNOWN clashes on some systems
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
3695 if (error == FCERR_NONE) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3696 ret = OK; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3697 |
18576
e9675870c480
patch 8.1.2282: crash when passing many arguments through a partial
Bram Moolenaar <Bram@vim.org>
parents:
18572
diff
changeset
|
3698 theend: |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3699 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3700 * Report an error unless the argument evaluation or function call has been |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3701 * cancelled due to an aborting error, an interrupt, or an exception. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3702 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3703 if (!aborting()) |
26506
4a1d2abc2016
patch 8.2.3783: confusing error for using a variable as a function
Bram Moolenaar <Bram@vim.org>
parents:
26504
diff
changeset
|
3704 user_func_error(error, (name != NULL) ? name : funcname, funcexe); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3705 |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3706 // clear the copies made from the partial |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3707 while (argv_clear > 0) |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3708 clear_tv(&argv[--argv_clear + argv_base]); |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3709 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3710 vim_free(tofree); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3711 vim_free(name); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3712 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3713 return ret; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3714 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3715 |
21401
aa7675a4a0cd
patch 8.2.1251: Vim9: warning for pointer usage, test failure undetected
Bram Moolenaar <Bram@vim.org>
parents:
21319
diff
changeset
|
3716 char_u * |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3717 printable_func_name(ufunc_T *fp) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3718 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3719 return fp->uf_name_exp != NULL ? fp->uf_name_exp : fp->uf_name; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3720 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3721 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3722 /* |
19579
aae19dd172c0
patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents:
19443
diff
changeset
|
3723 * List the head of the function: "function name(arg1, arg2)". |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3724 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3725 static void |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3726 list_func_head(ufunc_T *fp, int indent) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3727 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3728 int j; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3729 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3730 msg_start(); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3731 if (indent) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3732 msg_puts(" "); |
20943
1693ca876049
patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
3733 if (fp->uf_def_status != UF_NOT_COMPILED) |
19579
aae19dd172c0
patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents:
19443
diff
changeset
|
3734 msg_puts("def "); |
aae19dd172c0
patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents:
19443
diff
changeset
|
3735 else |
aae19dd172c0
patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents:
19443
diff
changeset
|
3736 msg_puts("function "); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3737 msg_puts((char *)printable_func_name(fp)); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3738 msg_putchar('('); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3739 for (j = 0; j < fp->uf_args.ga_len; ++j) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3740 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3741 if (j) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3742 msg_puts(", "); |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3743 msg_puts((char *)FUNCARG(fp, j)); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3744 if (fp->uf_arg_types != NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3745 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3746 char *tofree; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3747 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3748 msg_puts(": "); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3749 msg_puts(type_name(fp->uf_arg_types[j], &tofree)); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3750 vim_free(tofree); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3751 } |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
3752 if (j >= fp->uf_args.ga_len - fp->uf_def_args.ga_len) |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
3753 { |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
3754 msg_puts(" = "); |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
3755 msg_puts(((char **)(fp->uf_def_args.ga_data)) |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
3756 [j - fp->uf_args.ga_len + fp->uf_def_args.ga_len]); |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
3757 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3758 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3759 if (fp->uf_varargs) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3760 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3761 if (j) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3762 msg_puts(", "); |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3763 msg_puts("..."); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3764 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3765 if (fp->uf_va_name != NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3766 { |
28727
30862b2f7431
patch 8.2.4888: line number of lambda ignores line continuation
Bram Moolenaar <Bram@vim.org>
parents:
28515
diff
changeset
|
3767 if (!fp->uf_varargs) |
30862b2f7431
patch 8.2.4888: line number of lambda ignores line continuation
Bram Moolenaar <Bram@vim.org>
parents:
28515
diff
changeset
|
3768 { |
30862b2f7431
patch 8.2.4888: line number of lambda ignores line continuation
Bram Moolenaar <Bram@vim.org>
parents:
28515
diff
changeset
|
3769 if (j) |
30862b2f7431
patch 8.2.4888: line number of lambda ignores line continuation
Bram Moolenaar <Bram@vim.org>
parents:
28515
diff
changeset
|
3770 msg_puts(", "); |
30862b2f7431
patch 8.2.4888: line number of lambda ignores line continuation
Bram Moolenaar <Bram@vim.org>
parents:
28515
diff
changeset
|
3771 msg_puts("..."); |
30862b2f7431
patch 8.2.4888: line number of lambda ignores line continuation
Bram Moolenaar <Bram@vim.org>
parents:
28515
diff
changeset
|
3772 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3773 msg_puts((char *)fp->uf_va_name); |
24400
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
3774 if (fp->uf_va_type != NULL) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3775 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3776 char *tofree; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3777 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3778 msg_puts(": "); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3779 msg_puts(type_name(fp->uf_va_type, &tofree)); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3780 vim_free(tofree); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3781 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3782 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3783 msg_putchar(')'); |
19579
aae19dd172c0
patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents:
19443
diff
changeset
|
3784 |
20943
1693ca876049
patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
3785 if (fp->uf_def_status != UF_NOT_COMPILED) |
19579
aae19dd172c0
patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents:
19443
diff
changeset
|
3786 { |
aae19dd172c0
patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents:
19443
diff
changeset
|
3787 if (fp->uf_ret_type != &t_void) |
aae19dd172c0
patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents:
19443
diff
changeset
|
3788 { |
aae19dd172c0
patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents:
19443
diff
changeset
|
3789 char *tofree; |
aae19dd172c0
patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents:
19443
diff
changeset
|
3790 |
aae19dd172c0
patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents:
19443
diff
changeset
|
3791 msg_puts(": "); |
aae19dd172c0
patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents:
19443
diff
changeset
|
3792 msg_puts(type_name(fp->uf_ret_type, &tofree)); |
aae19dd172c0
patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents:
19443
diff
changeset
|
3793 vim_free(tofree); |
aae19dd172c0
patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents:
19443
diff
changeset
|
3794 } |
aae19dd172c0
patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents:
19443
diff
changeset
|
3795 } |
aae19dd172c0
patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents:
19443
diff
changeset
|
3796 else if (fp->uf_flags & FC_ABORT) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3797 msg_puts(" abort"); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3798 if (fp->uf_flags & FC_RANGE) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3799 msg_puts(" range"); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3800 if (fp->uf_flags & FC_DICT) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3801 msg_puts(" dict"); |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
3802 if (fp->uf_flags & FC_CLOSURE) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3803 msg_puts(" closure"); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3804 msg_clr_eos(); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3805 if (p_verbose > 0) |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14430
diff
changeset
|
3806 last_set_msg(fp->uf_script_ctx); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3807 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3808 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3809 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3810 * Get a function name, translating "<SID>" and "<SNR>". |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3811 * Also handles a Funcref in a List or Dictionary. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3812 * Returns the function name in allocated memory, or NULL for failure. |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3813 * Set "*is_global" to TRUE when the function must be global, unless |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3814 * "is_global" is NULL. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3815 * flags: |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3816 * TFN_INT: internal function name OK |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3817 * TFN_QUIET: be quiet |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3818 * TFN_NO_AUTOLOAD: do not use script autoloading |
9717
6226de5f8137
commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents:
9688
diff
changeset
|
3819 * TFN_NO_DEREF: do not dereference a Funcref |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3820 * Advances "pp" to just after the function name (if no error). |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3821 */ |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
3822 char_u * |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3823 trans_function_name( |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3824 char_u **pp, |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3825 int *is_global, |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3826 int skip, // only find the end, don't evaluate |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3827 int flags, |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3828 funcdict_T *fdp, // return: info about dictionary used |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
3829 partial_T **partial, // return: partial of a FuncRef |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
3830 type_T **type) // return: type of funcref if not NULL |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3831 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3832 char_u *name = NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3833 char_u *start; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3834 char_u *end; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3835 int lead; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3836 char_u sid_buf[20]; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3837 int len; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3838 int extra = 0; |
27464
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
3839 int prefix_g = FALSE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3840 lval_T lv; |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
3841 int vim9script = in_vim9script(); |
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
3842 int vim9_local; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3843 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3844 if (fdp != NULL) |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
3845 CLEAR_POINTER(fdp); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3846 start = *pp; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3847 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3848 // Check for hard coded <SNR>: already translated function ID (from a user |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3849 // command). |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3850 if ((*pp)[0] == K_SPECIAL && (*pp)[1] == KS_EXTRA |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3851 && (*pp)[2] == (int)KE_SNR) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3852 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3853 *pp += 3; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3854 len = get_id_len(pp) + 3; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3855 return vim_strnsave(start, len); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3856 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3857 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3858 // A name starting with "<SID>" or "<SNR>" is local to a script. But |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3859 // don't skip over "s:", get_lval() needs it for "s:dict.func". |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3860 lead = eval_fname_script(start); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3861 if (lead > 2) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3862 start += lead; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3863 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3864 // Note that TFN_ flags use the same values as GLV_ flags. |
13002
f7b2ecaeb79c
patch 8.0.1377: cannot call a dict function in autoloaded dict
Christian Brabandt <cb@256bit.org>
parents:
11569
diff
changeset
|
3865 end = get_lval(start, NULL, &lv, FALSE, skip, flags | GLV_READ_ONLY, |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3866 lead > 2 ? 0 : FNE_CHECK_START); |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
3867 if (end == start || (vim9script && end != NULL |
27279
6e1b0c4ab668
patch 8.2.4168: disallowing empty function name breaks existing plugins
Bram Moolenaar <Bram@vim.org>
parents:
27271
diff
changeset
|
3868 && end[-1] == AUTOLOAD_CHAR && *end == '(')) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3869 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3870 if (!skip) |
26757
3a2b222107a6
patch 8.2.3907: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26747
diff
changeset
|
3871 emsg(_(e_function_name_required)); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3872 goto theend; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3873 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3874 if (end == NULL || (lv.ll_tv != NULL && (lead > 2 || lv.ll_range))) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3875 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3876 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3877 * Report an invalid expression in braces, unless the expression |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3878 * evaluation has been cancelled due to an aborting error, an |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3879 * interrupt, or an exception. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3880 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3881 if (!aborting()) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3882 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3883 if (end != NULL) |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26857
diff
changeset
|
3884 semsg(_(e_invalid_argument_str), start); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3885 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3886 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3887 *pp = find_name_end(start, NULL, NULL, FNE_INCL_BR); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3888 goto theend; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3889 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3890 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3891 if (lv.ll_tv != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3892 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3893 if (fdp != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3894 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3895 fdp->fd_dict = lv.ll_dict; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3896 fdp->fd_newkey = lv.ll_newkey; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3897 lv.ll_newkey = NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3898 fdp->fd_di = lv.ll_di; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3899 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3900 if (lv.ll_tv->v_type == VAR_FUNC && lv.ll_tv->vval.v_string != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3901 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3902 name = vim_strsave(lv.ll_tv->vval.v_string); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3903 *pp = end; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3904 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3905 else if (lv.ll_tv->v_type == VAR_PARTIAL |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3906 && lv.ll_tv->vval.v_partial != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3907 { |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
3908 name = vim_strsave(partial_name(lv.ll_tv->vval.v_partial)); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3909 *pp = end; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3910 if (partial != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3911 *partial = lv.ll_tv->vval.v_partial; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3912 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3913 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3914 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3915 if (!skip && !(flags & TFN_QUIET) && (fdp == NULL |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3916 || lv.ll_dict == NULL || fdp->fd_newkey == NULL)) |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
3917 emsg(_(e_funcref_required)); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3918 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3919 *pp = end; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3920 name = NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3921 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3922 goto theend; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3923 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3924 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3925 if (lv.ll_name == NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3926 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3927 // Error found, but continue after the function name. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3928 *pp = end; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3929 goto theend; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3930 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3931 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3932 // Check if the name is a Funcref. If so, use the value. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3933 if (lv.ll_exp_name != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3934 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3935 len = (int)STRLEN(lv.ll_exp_name); |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
3936 name = deref_func_name(lv.ll_exp_name, &len, partial, type, |
27233
73232ed49cf2
patch 8.2.4145: confusing error when using name of import for a function
Bram Moolenaar <Bram@vim.org>
parents:
27189
diff
changeset
|
3937 flags & TFN_NO_AUTOLOAD, flags & TFN_NEW_FUNC, NULL); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3938 if (name == lv.ll_exp_name) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3939 name = NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3940 } |
27076
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3941 else if (lv.ll_sid > 0) |
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3942 { |
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3943 scriptitem_T *si = SCRIPT_ITEM(lv.ll_sid); |
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3944 int cc = *lv.ll_name_end; |
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3945 |
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3946 // function in another script. Prefix <SNR>99_ or the autoload prefix. |
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3947 *lv.ll_name_end = NUL; |
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3948 if (si->sn_autoload_prefix != NULL) |
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3949 { |
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3950 name = concat_str(si->sn_autoload_prefix, lv.ll_name); |
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3951 } |
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3952 else |
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3953 { |
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3954 sid_buf[0] = K_SPECIAL; |
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3955 sid_buf[1] = KS_EXTRA; |
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3956 sid_buf[2] = (int)KE_SNR; |
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3957 vim_snprintf((char *)sid_buf + 3, sizeof(sid_buf) - 3, |
27457
4c16acb2525f
patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
27348
diff
changeset
|
3958 "%ld_", (long)lv.ll_sid); |
27076
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3959 name = concat_str(sid_buf, lv.ll_name); |
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3960 } |
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3961 *lv.ll_name_end = cc; |
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3962 *pp = end; |
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3963 goto theend; |
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3964 } |
9717
6226de5f8137
commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents:
9688
diff
changeset
|
3965 else if (!(flags & TFN_NO_DEREF)) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3966 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3967 len = (int)(end - *pp); |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
3968 name = deref_func_name(*pp, &len, partial, type, |
27233
73232ed49cf2
patch 8.2.4145: confusing error when using name of import for a function
Bram Moolenaar <Bram@vim.org>
parents:
27189
diff
changeset
|
3969 flags & TFN_NO_AUTOLOAD, flags & TFN_NEW_FUNC, NULL); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3970 if (name == *pp) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3971 name = NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3972 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3973 if (name != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3974 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3975 name = vim_strsave(name); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3976 *pp = end; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3977 if (STRNCMP(name, "<SNR>", 5) == 0) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3978 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3979 // Change "<SNR>" to the byte sequence. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3980 name[0] = K_SPECIAL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3981 name[1] = KS_EXTRA; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3982 name[2] = (int)KE_SNR; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3983 mch_memmove(name + 3, name + 5, STRLEN(name + 5) + 1); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3984 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3985 goto theend; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3986 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3987 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3988 if (lv.ll_exp_name != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3989 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3990 len = (int)STRLEN(lv.ll_exp_name); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3991 if (lead <= 2 && lv.ll_name == lv.ll_exp_name |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3992 && STRNCMP(lv.ll_name, "s:", 2) == 0) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3993 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3994 // When there was "s:" already or the name expanded to get a |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3995 // leading "s:" then remove it. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3996 lv.ll_name += 2; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3997 len -= 2; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3998 lead = 2; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3999 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4000 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4001 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4002 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4003 // skip over "s:" and "g:" |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4004 if (lead == 2 || (lv.ll_name[0] == 'g' && lv.ll_name[1] == ':')) |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
4005 { |
27464
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
4006 if (lv.ll_name[0] == 'g') |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
4007 { |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
4008 if (is_global != NULL) |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
4009 { |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
4010 *is_global = TRUE; |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
4011 } |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
4012 else |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
4013 { |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
4014 // dropping "g:" without setting "is_global" won't work in |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
4015 // Vim9script, put it back later |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
4016 prefix_g = TRUE; |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
4017 extra = 2; |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
4018 } |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
4019 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4020 lv.ll_name += 2; |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
4021 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4022 len = (int)(end - lv.ll_name); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4023 } |
22496
454b78ca8247
patch 8.2.1796: Vim9: invalid memory access with weird function name
Bram Moolenaar <Bram@vim.org>
parents:
22415
diff
changeset
|
4024 if (len <= 0) |
454b78ca8247
patch 8.2.1796: Vim9: invalid memory access with weird function name
Bram Moolenaar <Bram@vim.org>
parents:
22415
diff
changeset
|
4025 { |
454b78ca8247
patch 8.2.1796: Vim9: invalid memory access with weird function name
Bram Moolenaar <Bram@vim.org>
parents:
22415
diff
changeset
|
4026 if (!skip) |
26757
3a2b222107a6
patch 8.2.3907: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26747
diff
changeset
|
4027 emsg(_(e_function_name_required)); |
22496
454b78ca8247
patch 8.2.1796: Vim9: invalid memory access with weird function name
Bram Moolenaar <Bram@vim.org>
parents:
22415
diff
changeset
|
4028 goto theend; |
454b78ca8247
patch 8.2.1796: Vim9: invalid memory access with weird function name
Bram Moolenaar <Bram@vim.org>
parents:
22415
diff
changeset
|
4029 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4030 |
23237
033b2a97d59b
patch 8.2.2164: Vim9: autoload function doesn't work in uppercased script
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
4031 // In Vim9 script a user function is script-local by default, unless it |
033b2a97d59b
patch 8.2.2164: Vim9: autoload function doesn't work in uppercased script
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
4032 // starts with a lower case character: dict.func(). |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
4033 vim9_local = ASCII_ISUPPER(*start) && vim9script; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4034 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4035 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4036 * Copy the function name to allocated memory. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4037 * Accept <SID>name() inside a script, translate into <SNR>123_name(). |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4038 * Accept <SNR>123_name() outside a script. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4039 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4040 if (skip) |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4041 lead = 0; // do nothing |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
4042 else if (lead > 0 || vim9_local) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4043 { |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
4044 if (!vim9_local) |
27595
d504745607bc
patch 8.2.4324: Vim9: script-local function name can start with "_"
Bram Moolenaar <Bram@vim.org>
parents:
27563
diff
changeset
|
4045 { |
29759
d19adfd545e2
patch 9.0.0219: cannot make a funcref with "s:func" in a def function
Bram Moolenaar <Bram@vim.org>
parents:
29531
diff
changeset
|
4046 if (vim9script && lead == 2 && !ASCII_ISUPPER(*lv.ll_name) |
d19adfd545e2
patch 9.0.0219: cannot make a funcref with "s:func" in a def function
Bram Moolenaar <Bram@vim.org>
parents:
29531
diff
changeset
|
4047 && current_script_is_vim9()) |
27595
d504745607bc
patch 8.2.4324: Vim9: script-local function name can start with "_"
Bram Moolenaar <Bram@vim.org>
parents:
27563
diff
changeset
|
4048 { |
29531
9f93092fb3cc
patch 9.0.0107: condition always has the same value
Bram Moolenaar <Bram@vim.org>
parents:
29320
diff
changeset
|
4049 semsg(_(e_function_name_must_start_with_capital_str), start); |
27595
d504745607bc
patch 8.2.4324: Vim9: script-local function name can start with "_"
Bram Moolenaar <Bram@vim.org>
parents:
27563
diff
changeset
|
4050 goto theend; |
d504745607bc
patch 8.2.4324: Vim9: script-local function name can start with "_"
Bram Moolenaar <Bram@vim.org>
parents:
27563
diff
changeset
|
4051 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4052 lead = 3; |
27595
d504745607bc
patch 8.2.4324: Vim9: script-local function name can start with "_"
Bram Moolenaar <Bram@vim.org>
parents:
27563
diff
changeset
|
4053 } |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
4054 if (vim9_local || (lv.ll_exp_name != NULL |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4055 && eval_fname_sid(lv.ll_exp_name)) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4056 || eval_fname_sid(*pp)) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4057 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4058 // It's script-local, "s:" or "<SID>" |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14430
diff
changeset
|
4059 if (current_sctx.sc_sid <= 0) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4060 { |
26439
b18f3b0f317c
patch 8.2.3750: error messages are everywhere
Bram Moolenaar <Bram@vim.org>
parents:
26388
diff
changeset
|
4061 emsg(_(e_using_sid_not_in_script_context)); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4062 goto theend; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4063 } |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14430
diff
changeset
|
4064 sprintf((char *)sid_buf, "%ld_", (long)current_sctx.sc_sid); |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
4065 if (vim9_local) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4066 extra = 3 + (int)STRLEN(sid_buf); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4067 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4068 lead += (int)STRLEN(sid_buf); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4069 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4070 } |
24988
494112d2aa93
patch 8.2.3031: no error if a function name starts with an underscore
Bram Moolenaar <Bram@vim.org>
parents:
24895
diff
changeset
|
4071 else if (!(flags & TFN_INT) && (builtin_function(lv.ll_name, len) |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
4072 || (vim9script && *lv.ll_name == '_'))) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4073 { |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
4074 semsg(_(vim9script ? e_function_name_must_start_with_capital_str |
27595
d504745607bc
patch 8.2.4324: Vim9: script-local function name can start with "_"
Bram Moolenaar <Bram@vim.org>
parents:
27563
diff
changeset
|
4075 : e_function_name_must_start_with_capital_or_s_str), |
d504745607bc
patch 8.2.4324: Vim9: script-local function name can start with "_"
Bram Moolenaar <Bram@vim.org>
parents:
27563
diff
changeset
|
4076 start); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4077 goto theend; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4078 } |
9717
6226de5f8137
commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents:
9688
diff
changeset
|
4079 if (!skip && !(flags & TFN_QUIET) && !(flags & TFN_NO_DEREF)) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4080 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4081 char_u *cp = vim_strchr(lv.ll_name, ':'); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4082 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4083 if (cp != NULL && cp < end) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4084 { |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
4085 semsg(_(e_function_name_cannot_contain_colon_str), start); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4086 goto theend; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4087 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4088 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4089 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4090 name = alloc(len + lead + extra + 1); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4091 if (name != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4092 { |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
4093 if (!skip && (lead > 0 || vim9_local)) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4094 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4095 name[0] = K_SPECIAL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4096 name[1] = KS_EXTRA; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4097 name[2] = (int)KE_SNR; |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
4098 if (vim9_local || lead > 3) // If it's "<SID>" |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4099 STRCPY(name + 3, sid_buf); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4100 } |
27464
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
4101 else if (prefix_g) |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
4102 { |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
4103 name[0] = 'g'; |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
4104 name[1] = ':'; |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
4105 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4106 mch_memmove(name + lead + extra, lv.ll_name, (size_t)len); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4107 name[lead + extra + len] = NUL; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4108 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4109 *pp = end; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4110 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4111 theend: |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4112 clear_lval(&lv); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4113 return name; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4114 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4115 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4116 /* |
20079
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4117 * Assuming "name" is the result of trans_function_name() and it was prefixed |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4118 * to use the script-local name, return the unmodified name (points into |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4119 * "name"). Otherwise return NULL. |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4120 * This can be used to first search for a script-local function and fall back |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4121 * to the global function if not found. |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4122 */ |
29320
a74398c432a4
patch 9.0.0003: functions are global while they could be local
Bram Moolenaar <Bram@vim.org>
parents:
29196
diff
changeset
|
4123 static char_u * |
20079
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4124 untrans_function_name(char_u *name) |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4125 { |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4126 char_u *p; |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4127 |
21279
8d1d11afd8c8
patch 8.2.1190: Vim9: checking for Vim9 syntax is spread out
Bram Moolenaar <Bram@vim.org>
parents:
21263
diff
changeset
|
4128 if (*name == K_SPECIAL && in_vim9script()) |
20079
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4129 { |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4130 p = vim_strchr(name, '_'); |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4131 if (p != NULL) |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4132 return p + 1; |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4133 } |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4134 return NULL; |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4135 } |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4136 |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4137 /* |
26721
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4138 * If the 'funcname' starts with "s:" or "<SID>", then expands it to the |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4139 * current script ID and returns the expanded function name. The caller should |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4140 * free the returned name. If not called from a script context or the function |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4141 * name doesn't start with these prefixes, then returns NULL. |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4142 * This doesn't check whether the script-local function exists or not. |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4143 */ |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4144 char_u * |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4145 get_scriptlocal_funcname(char_u *funcname) |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4146 { |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4147 char sid_buf[25]; |
27782
40ae50de0d27
patch 8.2.4417: using NULL pointer
Bram Moolenaar <Bram@vim.org>
parents:
27780
diff
changeset
|
4148 int off; |
26721
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4149 char_u *newname; |
27780
f1d5822ca0d7
patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
4150 char_u *p = funcname; |
26721
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4151 |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4152 if (funcname == NULL) |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4153 return NULL; |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4154 |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4155 if (STRNCMP(funcname, "s:", 2) != 0 |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4156 && STRNCMP(funcname, "<SID>", 5) != 0) |
27780
f1d5822ca0d7
patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
4157 { |
f1d5822ca0d7
patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
4158 ufunc_T *ufunc; |
f1d5822ca0d7
patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
4159 |
f1d5822ca0d7
patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
4160 // The function name does not have a script-local prefix. Try finding |
f1d5822ca0d7
patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
4161 // it when in a Vim9 script and there is no "g:" prefix. |
f1d5822ca0d7
patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
4162 if (!in_vim9script() || STRNCMP(funcname, "g:", 2) == 0) |
f1d5822ca0d7
patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
4163 return NULL; |
f1d5822ca0d7
patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
4164 ufunc = find_func(funcname, FALSE); |
f1d5822ca0d7
patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
4165 if (ufunc == NULL || func_is_global(ufunc) |
f1d5822ca0d7
patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
4166 || (p = vim_strchr(ufunc->uf_name, '_')) == NULL) |
f1d5822ca0d7
patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
4167 return NULL; |
f1d5822ca0d7
patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
4168 ++p; |
f1d5822ca0d7
patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
4169 off = 0; |
f1d5822ca0d7
patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
4170 } |
27782
40ae50de0d27
patch 8.2.4417: using NULL pointer
Bram Moolenaar <Bram@vim.org>
parents:
27780
diff
changeset
|
4171 else |
40ae50de0d27
patch 8.2.4417: using NULL pointer
Bram Moolenaar <Bram@vim.org>
parents:
27780
diff
changeset
|
4172 off = *funcname == 's' ? 2 : 5; |
26721
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4173 |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4174 if (!SCRIPT_ID_VALID(current_sctx.sc_sid)) |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4175 { |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4176 emsg(_(e_using_sid_not_in_script_context)); |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4177 return NULL; |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4178 } |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4179 // Expand s: prefix into <SNR>nr_<name> |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4180 vim_snprintf(sid_buf, sizeof(sid_buf), "<SNR>%ld_", |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4181 (long)current_sctx.sc_sid); |
27780
f1d5822ca0d7
patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
4182 newname = alloc(STRLEN(sid_buf) + STRLEN(p + off) + 1); |
26721
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4183 if (newname == NULL) |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4184 return NULL; |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4185 STRCPY(newname, sid_buf); |
27780
f1d5822ca0d7
patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
4186 STRCAT(newname, p + off); |
26721
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4187 |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4188 return newname; |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4189 } |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4190 |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4191 /* |
27807
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
4192 * Return script-local "fname" with the 3-byte sequence replaced by |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
4193 * printable <SNR> in allocated memory. |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
4194 */ |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
4195 char_u * |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
4196 alloc_printable_func_name(char_u *fname) |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
4197 { |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
4198 char_u *n = alloc(STRLEN(fname + 3) + 6); |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
4199 |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
4200 if (n != NULL) |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
4201 { |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
4202 STRCPY(n, "<SNR>"); |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
4203 STRCPY(n + 5, fname + 3); |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
4204 } |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
4205 return n; |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
4206 } |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
4207 |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
4208 /* |
26348
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4209 * Call trans_function_name(), except that a lambda is returned as-is. |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4210 * Returns the name in allocated memory. |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4211 */ |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4212 char_u * |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4213 save_function_name( |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4214 char_u **name, |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4215 int *is_global, |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4216 int skip, |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4217 int flags, |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4218 funcdict_T *fudi) |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4219 { |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4220 char_u *p = *name; |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4221 char_u *saved; |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4222 |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4223 if (STRNCMP(p, "<lambda>", 8) == 0) |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4224 { |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4225 p += 8; |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4226 (void)getdigits(&p); |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4227 saved = vim_strnsave(*name, p - *name); |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4228 if (fudi != NULL) |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4229 CLEAR_POINTER(fudi); |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4230 } |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4231 else |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4232 saved = trans_function_name(&p, is_global, skip, |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4233 flags, fudi, NULL, NULL); |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4234 *name = p; |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4235 return saved; |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4236 } |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4237 |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4238 /* |
20709
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4239 * List functions. When "regmatch" is NULL all of then. |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4240 * Otherwise functions matching "regmatch". |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4241 */ |
22973
4c97c0747017
patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents:
22908
diff
changeset
|
4242 void |
20709
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4243 list_functions(regmatch_T *regmatch) |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4244 { |
21319
fb3dcd8ed14d
patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents:
21313
diff
changeset
|
4245 int changed = func_hashtab.ht_changed; |
fb3dcd8ed14d
patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents:
21313
diff
changeset
|
4246 long_u todo = func_hashtab.ht_used; |
20709
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4247 hashitem_T *hi; |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4248 |
21319
fb3dcd8ed14d
patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents:
21313
diff
changeset
|
4249 for (hi = func_hashtab.ht_array; todo > 0 && !got_int; ++hi) |
20709
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4250 { |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4251 if (!HASHITEM_EMPTY(hi)) |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4252 { |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4253 ufunc_T *fp = HI2UF(hi); |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4254 |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4255 --todo; |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4256 if ((fp->uf_flags & FC_DEAD) == 0 |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4257 && (regmatch == NULL |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4258 ? !message_filtered(fp->uf_name) |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4259 && !func_name_refcount(fp->uf_name) |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4260 : !isdigit(*fp->uf_name) |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4261 && vim_regexec(regmatch, fp->uf_name, 0))) |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4262 { |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4263 list_func_head(fp, FALSE); |
21319
fb3dcd8ed14d
patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents:
21313
diff
changeset
|
4264 if (changed != func_hashtab.ht_changed) |
20709
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4265 { |
26915
3631d2deb36c
patch 8.2.3986: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26897
diff
changeset
|
4266 emsg(_(e_function_list_was_modified)); |
20709
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4267 return; |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4268 } |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4269 } |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4270 } |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4271 } |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4272 } |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4273 |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4274 /* |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4275 * ":function" also supporting nested ":def". |
21558
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21552
diff
changeset
|
4276 * When "name_arg" is not NULL this is a nested function, using "name_arg" for |
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21552
diff
changeset
|
4277 * the function name. |
27022
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
4278 * "lines_to_free" is a list of strings to be freed later. |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4279 * Returns a pointer to the function or NULL if no function defined. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4280 */ |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4281 ufunc_T * |
27022
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
4282 define_function(exarg_T *eap, char_u *name_arg, garray_T *lines_to_free) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4283 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4284 int j; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4285 int c; |
27476
4f1cf9579e4e
patch 8.2.4266: compiler warning for uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
27472
diff
changeset
|
4286 int saved_did_emsg = FALSE; |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4287 char_u *name = name_arg; |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
4288 int is_global = FALSE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4289 char_u *p; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4290 char_u *arg; |
23511
7e8703464f01
patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23446
diff
changeset
|
4291 char_u *whitep; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4292 char_u *line_arg = NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4293 garray_T newargs; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4294 garray_T argtypes; |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
4295 garray_T default_args; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4296 garray_T newlines; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4297 int varargs = FALSE; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4298 int flags = 0; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4299 char_u *ret_type = NULL; |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4300 ufunc_T *fp = NULL; |
26566
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4301 int fp_allocated = FALSE; |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4302 int free_fp = FALSE; |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
4303 int overwrite = FALSE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4304 dictitem_T *v; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4305 funcdict_T fudi; |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4306 static int func_nr = 0; // number for nameless function |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4307 int paren; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4308 hashitem_T *hi; |
17251
984eef966002
patch 8.1.1625: script line numbers are not exactly right
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
4309 linenr_T sourcing_lnum_top; |
21435
8ec9e2b54ce7
patch 8.2.1268: Vim9: no error for using double quote comment
Bram Moolenaar <Bram@vim.org>
parents:
21401
diff
changeset
|
4310 int vim9script = in_vim9script(); |
21598
7b5b9558500a
patch 8.2.1349: Vim9: can define a function with the name of an import
Bram Moolenaar <Bram@vim.org>
parents:
21586
diff
changeset
|
4311 imported_T *import = NULL; |
21435
8ec9e2b54ce7
patch 8.2.1268: Vim9: no error for using double quote comment
Bram Moolenaar <Bram@vim.org>
parents:
21401
diff
changeset
|
4312 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4313 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4314 * ":function" without argument: list functions. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4315 */ |
20138
d0a9766167ab
patch 8.2.0624: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20081
diff
changeset
|
4316 if (ends_excmd2(eap->cmd, eap->arg)) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4317 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4318 if (!eap->skip) |
20709
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4319 list_functions(NULL); |
25521
2063b858cad9
patch 8.2.3297: cannot use all commands inside a {} block
Bram Moolenaar <Bram@vim.org>
parents:
25473
diff
changeset
|
4320 set_nextcmd(eap, eap->arg); |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4321 return NULL; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4322 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4323 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4324 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4325 * ":function /pat": list functions matching pattern. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4326 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4327 if (*eap->arg == '/') |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4328 { |
19892
5feb426d2ea1
patch 8.2.0502: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
4329 p = skip_regexp(eap->arg + 1, '/', TRUE); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4330 if (!eap->skip) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4331 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4332 regmatch_T regmatch; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4333 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4334 c = *p; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4335 *p = NUL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4336 regmatch.regprog = vim_regcomp(eap->arg + 1, RE_MAGIC); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4337 *p = c; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4338 if (regmatch.regprog != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4339 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4340 regmatch.rm_ic = p_ic; |
20709
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4341 list_functions(®match); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4342 vim_regfree(regmatch.regprog); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4343 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4344 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4345 if (*p == '/') |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4346 ++p; |
25521
2063b858cad9
patch 8.2.3297: cannot use all commands inside a {} block
Bram Moolenaar <Bram@vim.org>
parents:
25473
diff
changeset
|
4347 set_nextcmd(eap, p); |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4348 return NULL; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4349 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4350 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4351 ga_init(&newargs); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4352 ga_init(&argtypes); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4353 ga_init(&default_args); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4354 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4355 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4356 * Get the function name. There are these situations: |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4357 * func normal function name |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4358 * "name" == func, "fudi.fd_dict" == NULL |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4359 * dict.func new dictionary entry |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4360 * "name" == NULL, "fudi.fd_dict" set, |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4361 * "fudi.fd_di" == NULL, "fudi.fd_newkey" == func |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4362 * dict.func existing dict entry with a Funcref |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4363 * "name" == func, "fudi.fd_dict" set, |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4364 * "fudi.fd_di" set, "fudi.fd_newkey" == NULL |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4365 * dict.func existing dict entry that's not a Funcref |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4366 * "name" == NULL, "fudi.fd_dict" set, |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4367 * "fudi.fd_di" set, "fudi.fd_newkey" == NULL |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4368 * s:func script-local function name |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4369 * g:func global function name, same as "func" |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4370 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4371 p = eap->arg; |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4372 if (name_arg != NULL) |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4373 { |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4374 // nested function, argument is (args). |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4375 paren = TRUE; |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4376 CLEAR_FIELD(fudi); |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4377 } |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4378 else |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4379 { |
27869
6a0ecde89d35
patch 8.2.4460: Vim9: wrong error for defining dict function
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
4380 if (vim9script) |
27669
5c4ab8d4472c
patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents:
27611
diff
changeset
|
4381 { |
27869
6a0ecde89d35
patch 8.2.4460: Vim9: wrong error for defining dict function
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
4382 if (p[0] == 's' && p[1] == ':') |
6a0ecde89d35
patch 8.2.4460: Vim9: wrong error for defining dict function
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
4383 { |
6a0ecde89d35
patch 8.2.4460: Vim9: wrong error for defining dict function
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
4384 semsg(_(e_cannot_use_s_colon_in_vim9_script_str), p); |
6a0ecde89d35
patch 8.2.4460: Vim9: wrong error for defining dict function
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
4385 return NULL; |
6a0ecde89d35
patch 8.2.4460: Vim9: wrong error for defining dict function
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
4386 } |
6a0ecde89d35
patch 8.2.4460: Vim9: wrong error for defining dict function
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
4387 p = to_name_end(p, TRUE); |
6a0ecde89d35
patch 8.2.4460: Vim9: wrong error for defining dict function
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
4388 if (*skipwhite(p) == '.' && vim_strchr(p, '(') != NULL) |
6a0ecde89d35
patch 8.2.4460: Vim9: wrong error for defining dict function
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
4389 { |
6a0ecde89d35
patch 8.2.4460: Vim9: wrong error for defining dict function
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
4390 semsg(_(e_cannot_define_dict_func_in_vim9_script_str), |
6a0ecde89d35
patch 8.2.4460: Vim9: wrong error for defining dict function
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
4391 eap->arg); |
6a0ecde89d35
patch 8.2.4460: Vim9: wrong error for defining dict function
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
4392 return NULL; |
6a0ecde89d35
patch 8.2.4460: Vim9: wrong error for defining dict function
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
4393 } |
6a0ecde89d35
patch 8.2.4460: Vim9: wrong error for defining dict function
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
4394 p = eap->arg; |
27669
5c4ab8d4472c
patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents:
27611
diff
changeset
|
4395 } |
5c4ab8d4472c
patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents:
27611
diff
changeset
|
4396 |
26348
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4397 name = save_function_name(&p, &is_global, eap->skip, |
27233
73232ed49cf2
patch 8.2.4145: confusing error when using name of import for a function
Bram Moolenaar <Bram@vim.org>
parents:
27189
diff
changeset
|
4398 TFN_NO_AUTOLOAD | TFN_NEW_FUNC, &fudi); |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4399 paren = (vim_strchr(p, '(') != NULL); |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4400 if (name == NULL && (fudi.fd_dict == NULL || !paren) && !eap->skip) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4401 { |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4402 /* |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4403 * Return on an invalid expression in braces, unless the expression |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4404 * evaluation has been cancelled due to an aborting error, an |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4405 * interrupt, or an exception. |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4406 */ |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4407 if (!aborting()) |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4408 { |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4409 if (!eap->skip && fudi.fd_newkey != NULL) |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
4410 semsg(_(e_key_not_present_in_dictionary), fudi.fd_newkey); |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4411 vim_free(fudi.fd_newkey); |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4412 return NULL; |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4413 } |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4414 else |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4415 eap->skip = TRUE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4416 } |
27043
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
4417 |
27049
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27043
diff
changeset
|
4418 // For "export def FuncName()" in an autoload script the function name |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27043
diff
changeset
|
4419 // is stored with the legacy autoload name "dir#script#FuncName" so |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27043
diff
changeset
|
4420 // that it can also be found in legacy script. |
27092
6d063974af23
patch 8.2.4075: test failures
Bram Moolenaar <Bram@vim.org>
parents:
27088
diff
changeset
|
4421 if (is_export && name != NULL) |
27267
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4422 { |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4423 char_u *prefixed = may_prefix_autoload(name); |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4424 |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4425 if (prefixed != NULL && prefixed != name) |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4426 { |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4427 vim_free(name); |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4428 name = prefixed; |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4429 } |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4430 } |
27563
a54064e14114
patch 8.2.4308: Vim9: cannot list autoload function
Bram Moolenaar <Bram@vim.org>
parents:
27482
diff
changeset
|
4431 else if (paren && vim9script && name != NULL |
27482
14640c6fe1fe
patch 8.2.4269: Coverity warns for using a NULL pointer
Bram Moolenaar <Bram@vim.org>
parents:
27476
diff
changeset
|
4432 && vim_strchr(name, AUTOLOAD_CHAR) != NULL) |
27472
55613f0d59bc
patch 8.2.4264: Vim9: can use old style autoload function name
Bram Moolenaar <Bram@vim.org>
parents:
27464
diff
changeset
|
4433 { |
55613f0d59bc
patch 8.2.4264: Vim9: can use old style autoload function name
Bram Moolenaar <Bram@vim.org>
parents:
27464
diff
changeset
|
4434 emsg(_(e_cannot_use_name_with_hash_in_vim9_script_use_export_instead)); |
55613f0d59bc
patch 8.2.4264: Vim9: can use old style autoload function name
Bram Moolenaar <Bram@vim.org>
parents:
27464
diff
changeset
|
4435 goto ret_free; |
55613f0d59bc
patch 8.2.4264: Vim9: can use old style autoload function name
Bram Moolenaar <Bram@vim.org>
parents:
27464
diff
changeset
|
4436 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4437 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4438 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4439 // An error in a function call during evaluation of an expression in magic |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4440 // braces should not cause the function not to be defined. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4441 saved_did_emsg = did_emsg; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4442 did_emsg = FALSE; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4443 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4444 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4445 * ":function func" with only function name: list function. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4446 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4447 if (!paren) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4448 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4449 if (!ends_excmd(*skipwhite(p))) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4450 { |
26883
7f150a4936f2
patch 8.2.3970: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
4451 semsg(_(e_trailing_characters_str), p); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4452 goto ret_free; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4453 } |
25521
2063b858cad9
patch 8.2.3297: cannot use all commands inside a {} block
Bram Moolenaar <Bram@vim.org>
parents:
25473
diff
changeset
|
4454 set_nextcmd(eap, p); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4455 if (eap->nextcmd != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4456 *p = NUL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4457 if (!eap->skip && !got_int) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4458 { |
27114
98a01021e465
patch 8.2.4086: "cctx" argument of find_func_even_dead() is unused
Bram Moolenaar <Bram@vim.org>
parents:
27092
diff
changeset
|
4459 fp = find_func(name, is_global); |
20079
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4460 if (fp == NULL && ASCII_ISUPPER(*eap->arg)) |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4461 { |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4462 char_u *up = untrans_function_name(name); |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4463 |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4464 // With Vim9 script the name was made script-local, if not |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4465 // found try again with the original name. |
20081
75589416d02d
patch 8.2.0596: crash in test49
Bram Moolenaar <Bram@vim.org>
parents:
20079
diff
changeset
|
4466 if (up != NULL) |
27114
98a01021e465
patch 8.2.4086: "cctx" argument of find_func_even_dead() is unused
Bram Moolenaar <Bram@vim.org>
parents:
27092
diff
changeset
|
4467 fp = find_func(up, FALSE); |
20079
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4468 } |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4469 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4470 if (fp != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4471 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4472 list_func_head(fp, TRUE); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4473 for (j = 0; j < fp->uf_lines.ga_len && !got_int; ++j) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4474 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4475 if (FUNCLINE(fp, j) == NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4476 continue; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4477 msg_putchar('\n'); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4478 msg_outnum((long)(j + 1)); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4479 if (j < 9) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4480 msg_putchar(' '); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4481 if (j < 99) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4482 msg_putchar(' '); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4483 msg_prt_line(FUNCLINE(fp, j), FALSE); |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4484 out_flush(); // show a line at a time |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4485 ui_breakcheck(); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4486 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4487 if (!got_int) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4488 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4489 msg_putchar('\n'); |
20943
1693ca876049
patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
4490 if (fp->uf_def_status != UF_NOT_COMPILED) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4491 msg_puts(" enddef"); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4492 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4493 msg_puts(" endfunction"); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4494 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4495 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4496 else |
26757
3a2b222107a6
patch 8.2.3907: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26747
diff
changeset
|
4497 emsg_funcname(e_undefined_function_str, eap->arg); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4498 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4499 goto ret_free; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4500 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4501 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4502 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4503 * ":function name(arg1, arg2)" Define function. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4504 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4505 p = skipwhite(p); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4506 if (*p != '(') |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4507 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4508 if (!eap->skip) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4509 { |
26757
3a2b222107a6
patch 8.2.3907: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26747
diff
changeset
|
4510 semsg(_(e_missing_paren_str), eap->arg); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4511 goto ret_free; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4512 } |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4513 // attempt to continue by skipping some text |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4514 if (vim_strchr(p, '(') != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4515 p = vim_strchr(p, '('); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4516 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4517 |
23727
7d0959080545
patch 8.2.2405: Vim9: no need to allow white space before "(" for :def
Bram Moolenaar <Bram@vim.org>
parents:
23717
diff
changeset
|
4518 if ((vim9script || eap->cmdidx == CMD_def) && VIM_ISWHITE(p[-1])) |
7d0959080545
patch 8.2.2405: Vim9: no need to allow white space before "(" for :def
Bram Moolenaar <Bram@vim.org>
parents:
23717
diff
changeset
|
4519 { |
23888
d95403445b6b
patch 8.2.2486: Vim9: some errors for white space do not show context
Bram Moolenaar <Bram@vim.org>
parents:
23879
diff
changeset
|
4520 semsg(_(e_no_white_space_allowed_before_str_str), "(", p - 1); |
23727
7d0959080545
patch 8.2.2405: Vim9: no need to allow white space before "(" for :def
Bram Moolenaar <Bram@vim.org>
parents:
23717
diff
changeset
|
4521 goto ret_free; |
7d0959080545
patch 8.2.2405: Vim9: no need to allow white space before "(" for :def
Bram Moolenaar <Bram@vim.org>
parents:
23717
diff
changeset
|
4522 } |
7d0959080545
patch 8.2.2405: Vim9: no need to allow white space before "(" for :def
Bram Moolenaar <Bram@vim.org>
parents:
23717
diff
changeset
|
4523 |
21479
90d859a402cc
patch 8.2.1290: Vim9: cannot replace a global function
Bram Moolenaar <Bram@vim.org>
parents:
21461
diff
changeset
|
4524 // In Vim9 script only global functions can be redefined. |
90d859a402cc
patch 8.2.1290: Vim9: cannot replace a global function
Bram Moolenaar <Bram@vim.org>
parents:
21461
diff
changeset
|
4525 if (vim9script && eap->forceit && !is_global) |
90d859a402cc
patch 8.2.1290: Vim9: cannot replace a global function
Bram Moolenaar <Bram@vim.org>
parents:
21461
diff
changeset
|
4526 { |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
4527 emsg(_(e_no_bang_allowed)); |
21479
90d859a402cc
patch 8.2.1290: Vim9: cannot replace a global function
Bram Moolenaar <Bram@vim.org>
parents:
21461
diff
changeset
|
4528 goto ret_free; |
90d859a402cc
patch 8.2.1290: Vim9: cannot replace a global function
Bram Moolenaar <Bram@vim.org>
parents:
21461
diff
changeset
|
4529 } |
90d859a402cc
patch 8.2.1290: Vim9: cannot replace a global function
Bram Moolenaar <Bram@vim.org>
parents:
21461
diff
changeset
|
4530 |
27028
c9474ae175f4
patch 8.2.4043: using int for second argument of ga_init2()
Bram Moolenaar <Bram@vim.org>
parents:
27022
diff
changeset
|
4531 ga_init2(&newlines, sizeof(char_u *), 10); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4532 |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4533 if (!eap->skip && name_arg == NULL) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4534 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4535 // Check the name of the function. Unless it's a dictionary function |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4536 // (that we are overwriting). |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4537 if (name != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4538 arg = name; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4539 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4540 arg = fudi.fd_newkey; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4541 if (arg != NULL && (fudi.fd_di == NULL |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4542 || (fudi.fd_di->di_tv.v_type != VAR_FUNC |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4543 && fudi.fd_di->di_tv.v_type != VAR_PARTIAL))) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4544 { |
26504
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4545 char_u *name_base = arg; |
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4546 int i; |
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4547 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4548 if (*arg == K_SPECIAL) |
26504
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4549 { |
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4550 name_base = vim_strchr(arg, '_'); |
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4551 if (name_base == NULL) |
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4552 name_base = arg + 3; |
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4553 else |
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4554 ++name_base; |
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4555 } |
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4556 for (i = 0; name_base[i] != NUL && (i == 0 |
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4557 ? eval_isnamec1(name_base[i]) |
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4558 : eval_isnamec(name_base[i])); ++i) |
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4559 ; |
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4560 if (name_base[i] != NUL) |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
4561 emsg_funcname(e_invalid_argument_str, arg); |
26504
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4562 |
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4563 // In Vim9 script a function cannot have the same name as a |
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4564 // variable. |
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4565 if (vim9script && *arg == K_SPECIAL |
26980
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
4566 && eval_variable(name_base, (int)STRLEN(name_base), 0, NULL, |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
4567 NULL, EVAL_VAR_NOAUTOLOAD + EVAL_VAR_IMPORT |
26504
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4568 + EVAL_VAR_NO_FUNC) == OK) |
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4569 { |
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4570 semsg(_(e_redefining_script_item_str), name_base); |
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4571 goto ret_free; |
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4572 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4573 } |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4574 // Disallow using the g: dict. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4575 if (fudi.fd_dict != NULL && fudi.fd_dict->dv_scope == VAR_DEF_SCOPE) |
26504
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4576 { |
26962
85866e069c24
patch 8.2.4010: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26958
diff
changeset
|
4577 emsg(_(e_cannot_use_g_here)); |
26504
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4578 goto ret_free; |
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4579 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4580 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4581 |
20015
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
4582 // This may get more lines and make the pointers into the first line |
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
4583 // invalid. |
23511
7e8703464f01
patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23446
diff
changeset
|
4584 ++p; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4585 if (get_function_args(&p, ')', &newargs, |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
4586 eap->cmdidx == CMD_def ? &argtypes : NULL, FALSE, |
24033
308d29307910
patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents:
24004
diff
changeset
|
4587 NULL, &varargs, &default_args, eap->skip, |
27022
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
4588 eap, lines_to_free) == FAIL) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4589 goto errret_2; |
23511
7e8703464f01
patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23446
diff
changeset
|
4590 whitep = p; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4591 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4592 if (eap->cmdidx == CMD_def) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4593 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4594 // find the return type: :def Func(): type |
25561
164cef0bc7ab
patch 8.2.3317: Vim9: No error for missing white space before return type
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
4595 if (*skipwhite(p) == ':') |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4596 { |
25561
164cef0bc7ab
patch 8.2.3317: Vim9: No error for missing white space before return type
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
4597 if (*p != ':') |
164cef0bc7ab
patch 8.2.3317: Vim9: No error for missing white space before return type
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
4598 { |
164cef0bc7ab
patch 8.2.3317: Vim9: No error for missing white space before return type
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
4599 semsg(_(e_no_white_space_allowed_before_colon_str), p); |
164cef0bc7ab
patch 8.2.3317: Vim9: No error for missing white space before return type
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
4600 p = skipwhite(p); |
164cef0bc7ab
patch 8.2.3317: Vim9: No error for missing white space before return type
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
4601 } |
164cef0bc7ab
patch 8.2.3317: Vim9: No error for missing white space before return type
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
4602 else if (!IS_WHITE_OR_NUL(p[1])) |
164cef0bc7ab
patch 8.2.3317: Vim9: No error for missing white space before return type
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
4603 semsg(_(e_white_space_required_after_str_str), ":", p); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4604 ret_type = skipwhite(p + 1); |
21500
574517d682cf
patch 8.2.1300: Vim9: optional argument type not parsed properly
Bram Moolenaar <Bram@vim.org>
parents:
21479
diff
changeset
|
4605 p = skip_type(ret_type, FALSE); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4606 if (p > ret_type) |
20015
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
4607 { |
20830
9064044fd4f6
patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20816
diff
changeset
|
4608 ret_type = vim_strnsave(ret_type, p - ret_type); |
23511
7e8703464f01
patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23446
diff
changeset
|
4609 whitep = p; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4610 p = skipwhite(p); |
20015
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
4611 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4612 else |
20015
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
4613 { |
21821
0deb6f96a5a3
patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
21791
diff
changeset
|
4614 semsg(_(e_expected_type_str), ret_type); |
20015
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
4615 ret_type = NULL; |
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
4616 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4617 } |
21435
8ec9e2b54ce7
patch 8.2.1268: Vim9: no error for using double quote comment
Bram Moolenaar <Bram@vim.org>
parents:
21401
diff
changeset
|
4618 p = skipwhite(p); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4619 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4620 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4621 // find extra arguments "range", "dict", "abort" and "closure" |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4622 for (;;) |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
4623 { |
23511
7e8703464f01
patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23446
diff
changeset
|
4624 whitep = p; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4625 p = skipwhite(p); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4626 if (STRNCMP(p, "range", 5) == 0) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4627 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4628 flags |= FC_RANGE; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4629 p += 5; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4630 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4631 else if (STRNCMP(p, "dict", 4) == 0) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4632 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4633 flags |= FC_DICT; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4634 p += 4; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4635 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4636 else if (STRNCMP(p, "abort", 5) == 0) |
9721
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
4637 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4638 flags |= FC_ABORT; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4639 p += 5; |
9721
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
4640 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4641 else if (STRNCMP(p, "closure", 7) == 0) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4642 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4643 flags |= FC_CLOSURE; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4644 p += 7; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4645 if (current_funccal == NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4646 { |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
4647 emsg_funcname(e_closure_function_should_not_be_at_top_level, |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4648 name == NULL ? (char_u *)"" : name); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4649 goto erret; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4650 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4651 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4652 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4653 break; |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
4654 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4655 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4656 // When there is a line break use what follows for the function body. |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4657 // Makes 'exe "func Test()\n...\nendfunc"' work. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4658 if (*p == '\n') |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4659 line_arg = p + 1; |
21435
8ec9e2b54ce7
patch 8.2.1268: Vim9: no error for using double quote comment
Bram Moolenaar <Bram@vim.org>
parents:
21401
diff
changeset
|
4660 else if (*p != NUL |
21528
e0aa9b81f6a9
patch 8.2.1314: Vim9: rule for comment after :function is confusing
Bram Moolenaar <Bram@vim.org>
parents:
21500
diff
changeset
|
4661 && !(*p == '"' && (!vim9script || eap->cmdidx == CMD_function) |
e0aa9b81f6a9
patch 8.2.1314: Vim9: rule for comment after :function is confusing
Bram Moolenaar <Bram@vim.org>
parents:
21500
diff
changeset
|
4662 && eap->cmdidx != CMD_def) |
23511
7e8703464f01
patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23446
diff
changeset
|
4663 && !(VIM_ISWHITE(*whitep) && *p == '#' |
7e8703464f01
patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23446
diff
changeset
|
4664 && (vim9script || eap->cmdidx == CMD_def)) |
21435
8ec9e2b54ce7
patch 8.2.1268: Vim9: no error for using double quote comment
Bram Moolenaar <Bram@vim.org>
parents:
21401
diff
changeset
|
4665 && !eap->skip |
8ec9e2b54ce7
patch 8.2.1268: Vim9: no error for using double quote comment
Bram Moolenaar <Bram@vim.org>
parents:
21401
diff
changeset
|
4666 && !did_emsg) |
26883
7f150a4936f2
patch 8.2.3970: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
4667 semsg(_(e_trailing_characters_str), p); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4668 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4669 /* |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4670 * Read the body of the function, until "}", ":endfunction" or ":enddef" is |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4671 * found. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4672 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4673 if (KeyTyped) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4674 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4675 // Check if the function already exists, don't let the user type the |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4676 // whole function before telling him it doesn't work! For a script we |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4677 // need to skip the body to be able to find what follows. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4678 if (!eap->skip && !eap->forceit) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4679 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4680 if (fudi.fd_dict != NULL && fudi.fd_newkey == NULL) |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
4681 emsg(_(e_dictionary_entry_already_exists)); |
27114
98a01021e465
patch 8.2.4086: "cctx" argument of find_func_even_dead() is unused
Bram Moolenaar <Bram@vim.org>
parents:
27092
diff
changeset
|
4682 else if (name != NULL && find_func(name, is_global) != NULL) |
26857
2aeea8611342
patch 8.2.3957: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26833
diff
changeset
|
4683 emsg_funcname(e_function_str_already_exists_add_bang_to_replace, name); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4684 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4685 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4686 if (!eap->skip && did_emsg) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4687 goto erret; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4688 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4689 msg_putchar('\n'); // don't overwrite the function name |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4690 cmdline_row = msg_row; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4691 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4692 |
17251
984eef966002
patch 8.1.1625: script line numbers are not exactly right
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
4693 // Save the starting line number. |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
4694 sourcing_lnum_top = SOURCING_LNUM; |
17251
984eef966002
patch 8.1.1625: script line numbers are not exactly right
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
4695 |
24653
0ef7bb28f2c3
patch 8.2.2865: skipping over function body fails
Bram Moolenaar <Bram@vim.org>
parents:
24651
diff
changeset
|
4696 // Do not define the function when getting the body fails and when |
0ef7bb28f2c3
patch 8.2.2865: skipping over function body fails
Bram Moolenaar <Bram@vim.org>
parents:
24651
diff
changeset
|
4697 // skipping. |
27022
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
4698 if (get_function_body(eap, &newlines, line_arg, lines_to_free) == FAIL |
24653
0ef7bb28f2c3
patch 8.2.2865: skipping over function body fails
Bram Moolenaar <Bram@vim.org>
parents:
24651
diff
changeset
|
4699 || eap->skip) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4700 goto erret; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4701 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4702 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4703 * If there are no errors, add the function |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4704 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4705 if (fudi.fd_dict == NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4706 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4707 hashtab_T *ht; |
27267
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4708 char_u *find_name = name; |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4709 int var_conflict = FALSE; |
27348
9a9c34c84cd4
patch 8.2.4202: Vim9: cannot export function that exists globally
Bram Moolenaar <Bram@vim.org>
parents:
27291
diff
changeset
|
4710 int ffed_flags = is_global ? FFED_IS_GLOBAL : 0; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4711 |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
4712 v = find_var(name, &ht, TRUE); |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
4713 if (v != NULL && (vim9script || v->di_tv.v_type == VAR_FUNC)) |
27267
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4714 var_conflict = TRUE; |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4715 |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4716 if (SCRIPT_ID_VALID(current_sctx.sc_sid)) |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4717 { |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4718 scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid); |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4719 |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4720 if (si->sn_autoload_prefix != NULL) |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4721 { |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4722 if (is_export) |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4723 { |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4724 find_name = name + STRLEN(si->sn_autoload_prefix); |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4725 v = find_var(find_name, &ht, TRUE); |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4726 if (v != NULL) |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4727 var_conflict = TRUE; |
27348
9a9c34c84cd4
patch 8.2.4202: Vim9: cannot export function that exists globally
Bram Moolenaar <Bram@vim.org>
parents:
27291
diff
changeset
|
4728 // Only check if the function already exists in the script, |
9a9c34c84cd4
patch 8.2.4202: Vim9: cannot export function that exists globally
Bram Moolenaar <Bram@vim.org>
parents:
27291
diff
changeset
|
4729 // global functions can be shadowed. |
9a9c34c84cd4
patch 8.2.4202: Vim9: cannot export function that exists globally
Bram Moolenaar <Bram@vim.org>
parents:
27291
diff
changeset
|
4730 ffed_flags |= FFED_NO_GLOBAL; |
27267
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4731 } |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4732 else |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4733 { |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4734 char_u *prefixed = may_prefix_autoload(name); |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4735 |
27893
8e630053c59c
patch 8.2.4472: Coverity warns for use of a freed function name
Bram Moolenaar <Bram@vim.org>
parents:
27869
diff
changeset
|
4736 if (prefixed != NULL && prefixed != name) |
27267
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4737 { |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4738 v = find_var(prefixed, &ht, TRUE); |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4739 if (v != NULL) |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4740 var_conflict = TRUE; |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4741 vim_free(prefixed); |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4742 } |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4743 } |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4744 } |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4745 } |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4746 if (var_conflict) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4747 { |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
4748 emsg_funcname(e_function_name_conflicts_with_variable_str, name); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4749 goto erret; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4750 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4751 |
27348
9a9c34c84cd4
patch 8.2.4202: Vim9: cannot export function that exists globally
Bram Moolenaar <Bram@vim.org>
parents:
27291
diff
changeset
|
4752 fp = find_func_even_dead(find_name, ffed_flags); |
21598
7b5b9558500a
patch 8.2.1349: Vim9: can define a function with the name of an import
Bram Moolenaar <Bram@vim.org>
parents:
21586
diff
changeset
|
4753 if (vim9script) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4754 { |
21598
7b5b9558500a
patch 8.2.1349: Vim9: can define a function with the name of an import
Bram Moolenaar <Bram@vim.org>
parents:
21586
diff
changeset
|
4755 char_u *uname = untrans_function_name(name); |
7b5b9558500a
patch 8.2.1349: Vim9: can define a function with the name of an import
Bram Moolenaar <Bram@vim.org>
parents:
21586
diff
changeset
|
4756 |
27698
3813036f19cb
patch 8.2.4375: ctx_imports is not used
Bram Moolenaar <Bram@vim.org>
parents:
27682
diff
changeset
|
4757 import = find_imported(uname == NULL ? name : uname, 0, FALSE); |
21598
7b5b9558500a
patch 8.2.1349: Vim9: can define a function with the name of an import
Bram Moolenaar <Bram@vim.org>
parents:
21586
diff
changeset
|
4758 } |
7b5b9558500a
patch 8.2.1349: Vim9: can define a function with the name of an import
Bram Moolenaar <Bram@vim.org>
parents:
21586
diff
changeset
|
4759 |
7b5b9558500a
patch 8.2.1349: Vim9: can define a function with the name of an import
Bram Moolenaar <Bram@vim.org>
parents:
21586
diff
changeset
|
4760 if (fp != NULL || import != NULL) |
7b5b9558500a
patch 8.2.1349: Vim9: can define a function with the name of an import
Bram Moolenaar <Bram@vim.org>
parents:
21586
diff
changeset
|
4761 { |
7b5b9558500a
patch 8.2.1349: Vim9: can define a function with the name of an import
Bram Moolenaar <Bram@vim.org>
parents:
21586
diff
changeset
|
4762 int dead = fp != NULL && (fp->uf_flags & FC_DEAD); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4763 |
15008
67e3103d6e18
patch 8.1.0515: reloading a script gives errors for existing functions
Bram Moolenaar <Bram@vim.org>
parents:
15000
diff
changeset
|
4764 // Function can be replaced with "function!" and when sourcing the |
67e3103d6e18
patch 8.1.0515: reloading a script gives errors for existing functions
Bram Moolenaar <Bram@vim.org>
parents:
15000
diff
changeset
|
4765 // same script again, but only once. |
21598
7b5b9558500a
patch 8.2.1349: Vim9: can define a function with the name of an import
Bram Moolenaar <Bram@vim.org>
parents:
21586
diff
changeset
|
4766 // A name that is used by an import can not be overruled. |
7b5b9558500a
patch 8.2.1349: Vim9: can define a function with the name of an import
Bram Moolenaar <Bram@vim.org>
parents:
21586
diff
changeset
|
4767 if (import != NULL |
7b5b9558500a
patch 8.2.1349: Vim9: can define a function with the name of an import
Bram Moolenaar <Bram@vim.org>
parents:
21586
diff
changeset
|
4768 || (!dead && !eap->forceit |
15008
67e3103d6e18
patch 8.1.0515: reloading a script gives errors for existing functions
Bram Moolenaar <Bram@vim.org>
parents:
15000
diff
changeset
|
4769 && (fp->uf_script_ctx.sc_sid != current_sctx.sc_sid |
21598
7b5b9558500a
patch 8.2.1349: Vim9: can define a function with the name of an import
Bram Moolenaar <Bram@vim.org>
parents:
21586
diff
changeset
|
4770 || fp->uf_script_ctx.sc_seq == current_sctx.sc_seq))) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4771 { |
26205
9e5e331828da
patch 8.2.3634: error for already defined function uses wrong line number
Bram Moolenaar <Bram@vim.org>
parents:
26203
diff
changeset
|
4772 SOURCING_LNUM = sourcing_lnum_top; |
21598
7b5b9558500a
patch 8.2.1349: Vim9: can define a function with the name of an import
Bram Moolenaar <Bram@vim.org>
parents:
21586
diff
changeset
|
4773 if (vim9script) |
21909
a211bca98bc3
patch 8.2.1504: Vim9: white space checks are only done for a :def function
Bram Moolenaar <Bram@vim.org>
parents:
21883
diff
changeset
|
4774 emsg_funcname(e_name_already_defined_str, name); |
21598
7b5b9558500a
patch 8.2.1349: Vim9: can define a function with the name of an import
Bram Moolenaar <Bram@vim.org>
parents:
21586
diff
changeset
|
4775 else |
26857
2aeea8611342
patch 8.2.3957: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26833
diff
changeset
|
4776 emsg_funcname(e_function_str_already_exists_add_bang_to_replace, name); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4777 goto erret; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4778 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4779 if (fp->uf_calls > 0) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4780 { |
15008
67e3103d6e18
patch 8.1.0515: reloading a script gives errors for existing functions
Bram Moolenaar <Bram@vim.org>
parents:
15000
diff
changeset
|
4781 emsg_funcname( |
26757
3a2b222107a6
patch 8.2.3907: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26747
diff
changeset
|
4782 e_cannot_redefine_function_str_it_is_in_use, name); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4783 goto erret; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4784 } |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
4785 if (fp->uf_refcount > 1) |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
4786 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4787 // This function is referenced somewhere, don't redefine it but |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4788 // create a new one. |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
4789 --fp->uf_refcount; |
9733
59565cdd7261
commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents:
9731
diff
changeset
|
4790 fp->uf_flags |= FC_REMOVED; |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
4791 fp = NULL; |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
4792 overwrite = TRUE; |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
4793 } |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
4794 else |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
4795 { |
19035
b920ae62c7b1
patch 8.2.0078: expanding <sfile> works differently the second time
Bram Moolenaar <Bram@vim.org>
parents:
19013
diff
changeset
|
4796 char_u *exp_name = fp->uf_name_exp; |
b920ae62c7b1
patch 8.2.0078: expanding <sfile> works differently the second time
Bram Moolenaar <Bram@vim.org>
parents:
19013
diff
changeset
|
4797 |
b920ae62c7b1
patch 8.2.0078: expanding <sfile> works differently the second time
Bram Moolenaar <Bram@vim.org>
parents:
19013
diff
changeset
|
4798 // redefine existing function, keep the expanded name |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13096
diff
changeset
|
4799 VIM_CLEAR(name); |
19035
b920ae62c7b1
patch 8.2.0078: expanding <sfile> works differently the second time
Bram Moolenaar <Bram@vim.org>
parents:
19013
diff
changeset
|
4800 fp->uf_name_exp = NULL; |
14430
2fba714294b9
patch 8.1.0229: crash when dumping profiling data
Christian Brabandt <cb@256bit.org>
parents:
14323
diff
changeset
|
4801 func_clear_items(fp); |
19035
b920ae62c7b1
patch 8.2.0078: expanding <sfile> works differently the second time
Bram Moolenaar <Bram@vim.org>
parents:
19013
diff
changeset
|
4802 fp->uf_name_exp = exp_name; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4803 fp->uf_flags &= ~FC_DEAD; |
14430
2fba714294b9
patch 8.1.0229: crash when dumping profiling data
Christian Brabandt <cb@256bit.org>
parents:
14323
diff
changeset
|
4804 #ifdef FEAT_PROFILE |
2fba714294b9
patch 8.1.0229: crash when dumping profiling data
Christian Brabandt <cb@256bit.org>
parents:
14323
diff
changeset
|
4805 fp->uf_profiling = FALSE; |
2fba714294b9
patch 8.1.0229: crash when dumping profiling data
Christian Brabandt <cb@256bit.org>
parents:
14323
diff
changeset
|
4806 fp->uf_prof_initialized = FALSE; |
2fba714294b9
patch 8.1.0229: crash when dumping profiling data
Christian Brabandt <cb@256bit.org>
parents:
14323
diff
changeset
|
4807 #endif |
23360
eb7d8f39363c
patch 8.2.2223: Vim9: Reloading marks a :def function as deleted
Bram Moolenaar <Bram@vim.org>
parents:
23354
diff
changeset
|
4808 fp->uf_def_status = UF_NOT_COMPILED; |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
4809 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4810 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4811 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4812 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4813 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4814 char numbuf[20]; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4815 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4816 fp = NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4817 if (fudi.fd_newkey == NULL && !eap->forceit) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4818 { |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
4819 emsg(_(e_dictionary_entry_already_exists)); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4820 goto erret; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4821 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4822 if (fudi.fd_di == NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4823 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4824 // Can't add a function to a locked dictionary |
22298
07e48ee8c3bb
patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents:
22260
diff
changeset
|
4825 if (value_check_lock(fudi.fd_dict->dv_lock, eap->arg, FALSE)) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4826 goto erret; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4827 } |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4828 // Can't change an existing function if it is locked |
22298
07e48ee8c3bb
patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents:
22260
diff
changeset
|
4829 else if (value_check_lock(fudi.fd_di->di_tv.v_lock, eap->arg, FALSE)) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4830 goto erret; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4831 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4832 // Give the function a sequential number. Can only be used with a |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4833 // Funcref! |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4834 vim_free(name); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4835 sprintf(numbuf, "%d", ++func_nr); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4836 name = vim_strsave((char_u *)numbuf); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4837 if (name == NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4838 goto erret; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4839 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4840 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4841 if (fp == NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4842 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4843 if (fudi.fd_dict == NULL && vim_strchr(name, AUTOLOAD_CHAR) != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4844 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4845 int slen, plen; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4846 char_u *scriptname; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4847 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4848 // Check that the autoload name matches the script name. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4849 j = FAIL; |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
4850 if (SOURCING_NAME != NULL) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4851 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4852 scriptname = autoload_name(name); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4853 if (scriptname != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4854 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4855 p = vim_strchr(scriptname, '/'); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4856 plen = (int)STRLEN(p); |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
4857 slen = (int)STRLEN(SOURCING_NAME); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4858 if (slen > plen && fnamecmp(p, |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
4859 SOURCING_NAME + slen - plen) == 0) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4860 j = OK; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4861 vim_free(scriptname); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4862 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4863 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4864 if (j == FAIL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4865 { |
24436
ccdd5e9a3763
patch 8.2.2758: Vim9: wrong line number for autoload function with wrong name
Bram Moolenaar <Bram@vim.org>
parents:
24422
diff
changeset
|
4866 linenr_T save_lnum = SOURCING_LNUM; |
ccdd5e9a3763
patch 8.2.2758: Vim9: wrong line number for autoload function with wrong name
Bram Moolenaar <Bram@vim.org>
parents:
24422
diff
changeset
|
4867 |
ccdd5e9a3763
patch 8.2.2758: Vim9: wrong line number for autoload function with wrong name
Bram Moolenaar <Bram@vim.org>
parents:
24422
diff
changeset
|
4868 SOURCING_LNUM = sourcing_lnum_top; |
26958
d92e0d85923f
patch 8.2.4008: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26952
diff
changeset
|
4869 semsg(_(e_function_name_does_not_match_script_file_name_str), |
d92e0d85923f
patch 8.2.4008: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26952
diff
changeset
|
4870 name); |
24436
ccdd5e9a3763
patch 8.2.2758: Vim9: wrong line number for autoload function with wrong name
Bram Moolenaar <Bram@vim.org>
parents:
24422
diff
changeset
|
4871 SOURCING_LNUM = save_lnum; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4872 goto erret; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4873 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4874 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4875 |
17659
121bdff812b4
patch 8.1.1827: allocating more memory than needed for extended structs
Bram Moolenaar <Bram@vim.org>
parents:
17646
diff
changeset
|
4876 fp = alloc_clear(offsetof(ufunc_T, uf_name) + STRLEN(name) + 1); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4877 if (fp == NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4878 goto erret; |
26566
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4879 fp_allocated = TRUE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4880 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4881 if (fudi.fd_dict != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4882 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4883 if (fudi.fd_di == NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4884 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4885 // add new dict entry |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4886 fudi.fd_di = dictitem_alloc(fudi.fd_newkey); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4887 if (fudi.fd_di == NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4888 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4889 vim_free(fp); |
20542
dd3165956464
patch 8.2.0825: def_function() may return pointer that was freed
Bram Moolenaar <Bram@vim.org>
parents:
20538
diff
changeset
|
4890 fp = NULL; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4891 goto erret; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4892 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4893 if (dict_add(fudi.fd_dict, fudi.fd_di) == FAIL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4894 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4895 vim_free(fudi.fd_di); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4896 vim_free(fp); |
20542
dd3165956464
patch 8.2.0825: def_function() may return pointer that was freed
Bram Moolenaar <Bram@vim.org>
parents:
20538
diff
changeset
|
4897 fp = NULL; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4898 goto erret; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4899 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4900 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4901 else |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4902 // overwrite existing dict entry |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4903 clear_tv(&fudi.fd_di->di_tv); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4904 fudi.fd_di->di_tv.v_type = VAR_FUNC; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4905 fudi.fd_di->di_tv.vval.v_string = vim_strsave(name); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4906 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4907 // behave like "dict" was used |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4908 flags |= FC_DICT; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4909 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4910 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4911 fp->uf_args = newargs; |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
4912 fp->uf_def_args = default_args; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4913 fp->uf_ret_type = &t_any; |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
19900
diff
changeset
|
4914 fp->uf_func_type = &t_func_any; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4915 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4916 if (eap->cmdidx == CMD_def) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4917 { |
22643
71b57779177d
patch 8.2.1870: Vim9: no need to keep all script variables
Bram Moolenaar <Bram@vim.org>
parents:
22596
diff
changeset
|
4918 int lnum_save = SOURCING_LNUM; |
71b57779177d
patch 8.2.1870: Vim9: no need to keep all script variables
Bram Moolenaar <Bram@vim.org>
parents:
22596
diff
changeset
|
4919 cstack_T *cstack = eap->cstack; |
19297
84703c85a583
patch 8.2.0207: crash when missing member type on list argument
Bram Moolenaar <Bram@vim.org>
parents:
19285
diff
changeset
|
4920 |
20943
1693ca876049
patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
4921 fp->uf_def_status = UF_TO_BE_COMPILED; |
20528
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
4922 |
19297
84703c85a583
patch 8.2.0207: crash when missing member type on list argument
Bram Moolenaar <Bram@vim.org>
parents:
19285
diff
changeset
|
4923 // error messages are for the first function line |
84703c85a583
patch 8.2.0207: crash when missing member type on list argument
Bram Moolenaar <Bram@vim.org>
parents:
19285
diff
changeset
|
4924 SOURCING_LNUM = sourcing_lnum_top; |
84703c85a583
patch 8.2.0207: crash when missing member type on list argument
Bram Moolenaar <Bram@vim.org>
parents:
19285
diff
changeset
|
4925 |
25358
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
4926 // The function may use script variables from the context. |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
4927 function_using_block_scopes(fp, cstack); |
22596
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22496
diff
changeset
|
4928 |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
4929 if (parse_argument_types(fp, &argtypes, varargs) == FAIL) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4930 { |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
4931 SOURCING_LNUM = lnum_save; |
26566
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4932 free_fp = fp_allocated; |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4933 goto erret; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4934 } |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
4935 varargs = FALSE; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4936 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4937 // parse the return type, if any |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
4938 if (parse_return_type(fp, ret_type) == FAIL) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4939 { |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
4940 SOURCING_LNUM = lnum_save; |
26566
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4941 free_fp = fp_allocated; |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
4942 goto erret; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4943 } |
20339
7587d892c00c
patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20279
diff
changeset
|
4944 SOURCING_LNUM = lnum_save; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4945 } |
20528
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
4946 else |
20943
1693ca876049
patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
4947 fp->uf_def_status = UF_NOT_COMPILED; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4948 |
26566
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4949 if (fp_allocated) |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4950 { |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4951 // insert the new function in the function list |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4952 set_ufunc_name(fp, name); |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4953 if (overwrite) |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4954 { |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4955 hi = hash_find(&func_hashtab, name); |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4956 hi->hi_key = UF2HIKEY(fp); |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4957 } |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4958 else if (hash_add(&func_hashtab, UF2HIKEY(fp)) == FAIL) |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4959 { |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4960 free_fp = TRUE; |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4961 goto erret; |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4962 } |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4963 fp->uf_refcount = 1; |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4964 } |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4965 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4966 fp->uf_lines = newlines; |
26566
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4967 newlines.ga_data = NULL; |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
4968 if ((flags & FC_CLOSURE) != 0) |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
4969 { |
9721
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
4970 if (register_closure(fp) == FAIL) |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
4971 goto erret; |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
4972 } |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
4973 else |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
4974 fp->uf_scoped = NULL; |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
4975 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4976 #ifdef FEAT_PROFILE |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4977 if (prof_def_func()) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4978 func_do_profile(fp); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4979 #endif |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4980 fp->uf_varargs = varargs; |
14323
9df95cf9ea7e
patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
4981 if (sandbox) |
9df95cf9ea7e
patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
4982 flags |= FC_SANDBOX; |
21435
8ec9e2b54ce7
patch 8.2.1268: Vim9: no error for using double quote comment
Bram Moolenaar <Bram@vim.org>
parents:
21401
diff
changeset
|
4983 if (vim9script && !ASCII_ISUPPER(*fp->uf_name)) |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
4984 flags |= FC_VIM9; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4985 fp->uf_flags = flags; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4986 fp->uf_calls = 0; |
19443
6b1a59e71f85
patch 8.2.0279: Vim9: no test for deleted :def function
Bram Moolenaar <Bram@vim.org>
parents:
19421
diff
changeset
|
4987 fp->uf_cleared = FALSE; |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14430
diff
changeset
|
4988 fp->uf_script_ctx = current_sctx; |
21646
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21598
diff
changeset
|
4989 fp->uf_script_ctx_version = current_sctx.sc_version; |
17251
984eef966002
patch 8.1.1625: script line numbers are not exactly right
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
4990 fp->uf_script_ctx.sc_lnum += sourcing_lnum_top; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4991 if (is_export) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4992 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4993 fp->uf_flags |= FC_EXPORT; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4994 // let ex_export() know the export worked. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4995 is_export = FALSE; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4996 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4997 |
20532
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
4998 if (eap->cmdidx == CMD_def) |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
4999 set_function_type(fp); |
20945
0653b9b72091
patch 8.2.1024: Vim9: no error for using "let g:var = val"
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
5000 else if (fp->uf_script_ctx.sc_version == SCRIPT_VERSION_VIM9) |
0653b9b72091
patch 8.2.1024: Vim9: no error for using "let g:var = val"
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
5001 // :func does not use Vim9 script syntax, even in a Vim9 script file |
0653b9b72091
patch 8.2.1024: Vim9: no error for using "let g:var = val"
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
5002 fp->uf_script_ctx.sc_version = SCRIPT_VERSION_MAX; |
20532
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
5003 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5004 goto ret_free; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5005 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5006 erret: |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5007 ga_clear_strings(&newargs); |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
5008 ga_clear_strings(&default_args); |
23925
e979bf909fd8
patch 8.2.2505: Vim9: crash after defining function with invalid return type
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
5009 if (fp != NULL) |
e979bf909fd8
patch 8.2.2505: Vim9: crash after defining function with invalid return type
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
5010 { |
e979bf909fd8
patch 8.2.2505: Vim9: crash after defining function with invalid return type
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
5011 ga_init(&fp->uf_args); |
e979bf909fd8
patch 8.2.2505: Vim9: crash after defining function with invalid return type
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
5012 ga_init(&fp->uf_def_args); |
e979bf909fd8
patch 8.2.2505: Vim9: crash after defining function with invalid return type
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
5013 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5014 errret_2: |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5015 ga_clear_strings(&newlines); |
23925
e979bf909fd8
patch 8.2.2505: Vim9: crash after defining function with invalid return type
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
5016 if (fp != NULL) |
e979bf909fd8
patch 8.2.2505: Vim9: crash after defining function with invalid return type
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
5017 VIM_CLEAR(fp->uf_arg_types); |
26566
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
5018 if (free_fp) |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
5019 { |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
5020 vim_free(fp); |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
5021 fp = NULL; |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
5022 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5023 ret_free: |
19685
d64f403289db
patch 8.2.0399: various memory leaks
Bram Moolenaar <Bram@vim.org>
parents:
19579
diff
changeset
|
5024 ga_clear_strings(&argtypes); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5025 vim_free(fudi.fd_newkey); |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
5026 if (name != name_arg) |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
5027 vim_free(name); |
20015
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
5028 vim_free(ret_type); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5029 did_emsg |= saved_did_emsg; |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
5030 |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
5031 return fp; |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
5032 } |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
5033 |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
5034 /* |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
5035 * ":function" |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
5036 */ |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
5037 void |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
5038 ex_function(exarg_T *eap) |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
5039 { |
27022
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
5040 garray_T lines_to_free; |
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
5041 |
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
5042 ga_init2(&lines_to_free, sizeof(char_u *), 50); |
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
5043 (void)define_function(eap, NULL, &lines_to_free); |
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
5044 ga_clear_strings(&lines_to_free); |
20528
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
5045 } |
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
5046 |
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
5047 /* |
28934
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5048 * Find a function by name, including "<lambda>123". |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5049 * Check for "profile" and "debug" arguments and set"compile_type". |
28940
b02044bc8c20
patch 8.2.4992: compiler warning for possibly uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
28936
diff
changeset
|
5050 * Caller should initialize "compile_type" to CT_NONE. |
28934
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5051 * Return NULL if not found. |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5052 */ |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5053 ufunc_T * |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5054 find_func_by_name(char_u *name, compiletype_T *compile_type) |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5055 { |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5056 char_u *arg = name; |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5057 char_u *fname; |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5058 ufunc_T *ufunc; |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5059 int is_global = FALSE; |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5060 |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5061 if (STRNCMP(arg, "profile", 7) == 0 && VIM_ISWHITE(arg[7])) |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5062 { |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5063 *compile_type = CT_PROFILE; |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5064 arg = skipwhite(arg + 7); |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5065 } |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5066 else if (STRNCMP(arg, "debug", 5) == 0 && VIM_ISWHITE(arg[5])) |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5067 { |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5068 *compile_type = CT_DEBUG; |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5069 arg = skipwhite(arg + 5); |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5070 } |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5071 |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5072 if (STRNCMP(arg, "<lambda>", 8) == 0) |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5073 { |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5074 arg += 8; |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5075 (void)getdigits(&arg); |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5076 fname = vim_strnsave(name, arg - name); |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5077 } |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5078 else |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5079 fname = trans_function_name(&arg, &is_global, FALSE, |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5080 TFN_INT | TFN_QUIET | TFN_NO_AUTOLOAD, NULL, NULL, NULL); |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5081 if (fname == NULL) |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5082 { |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5083 semsg(_(e_invalid_argument_str), name); |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5084 return NULL; |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5085 } |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5086 if (!ends_excmd2(name, arg)) |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5087 { |
28936
5a34620140c0
patch 8.2.4990: memory leak when :defcompile fails
Bram Moolenaar <Bram@vim.org>
parents:
28934
diff
changeset
|
5088 vim_free(fname); |
28934
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5089 emsg(ex_errmsg(e_trailing_characters_str, arg)); |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5090 return NULL; |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5091 } |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5092 |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5093 ufunc = find_func(fname, is_global); |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5094 if (ufunc == NULL) |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5095 { |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5096 char_u *p = untrans_function_name(fname); |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5097 |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5098 if (p != NULL) |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5099 // Try again without making it script-local. |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5100 ufunc = find_func(p, FALSE); |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5101 } |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5102 vim_free(fname); |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5103 if (ufunc == NULL) |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5104 semsg(_(e_cannot_find_function_str), name); |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5105 return ufunc; |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5106 } |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5107 |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5108 /* |
22188
ec0a5ae32d5e
patch 8.2.1643: Vim9: :defcompile compiles dead functions
Bram Moolenaar <Bram@vim.org>
parents:
21983
diff
changeset
|
5109 * :defcompile - compile all :def functions in the current script that need to |
28934
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5110 * be compiled or the one specified by the argument. |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5111 * Skips dead functions. Doesn't do profiling. |
20528
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
5112 */ |
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
5113 void |
28934
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5114 ex_defcompile(exarg_T *eap) |
20528
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
5115 { |
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
5116 ufunc_T *ufunc; |
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
5117 |
28934
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5118 if (*eap->arg != NUL) |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5119 { |
28940
b02044bc8c20
patch 8.2.4992: compiler warning for possibly uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
28936
diff
changeset
|
5120 compiletype_T compile_type = CT_NONE; |
28934
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5121 |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5122 ufunc = find_func_by_name(eap->arg, &compile_type); |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5123 if (ufunc != NULL) |
20528
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
5124 { |
28934
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5125 if (func_needs_compiling(ufunc, compile_type)) |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5126 (void)compile_def_function(ufunc, FALSE, compile_type, NULL); |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5127 else |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5128 smsg(_("Function %s does not need compiling"), eap->arg); |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5129 } |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5130 } |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5131 else |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5132 { |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5133 long todo = (long)func_hashtab.ht_used; |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5134 int changed = func_hashtab.ht_changed; |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5135 hashitem_T *hi; |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5136 |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5137 for (hi = func_hashtab.ht_array; todo > 0 && !got_int; ++hi) |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5138 { |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5139 if (!HASHITEM_EMPTY(hi)) |
20544
e8132bec4b0f
patch 8.2.0826: Vim9: crash in :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
20542
diff
changeset
|
5140 { |
28934
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5141 --todo; |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5142 ufunc = HI2UF(hi); |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5143 if (ufunc->uf_script_ctx.sc_sid == current_sctx.sc_sid |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5144 && ufunc->uf_def_status == UF_TO_BE_COMPILED |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5145 && (ufunc->uf_flags & FC_DEAD) == 0) |
20544
e8132bec4b0f
patch 8.2.0826: Vim9: crash in :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
20542
diff
changeset
|
5146 { |
28934
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5147 (void)compile_def_function(ufunc, FALSE, CT_NONE, NULL); |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5148 |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5149 if (func_hashtab.ht_changed != changed) |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5150 { |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5151 // a function has been added or removed, need to start |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5152 // over |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5153 todo = (long)func_hashtab.ht_used; |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5154 changed = func_hashtab.ht_changed; |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5155 hi = func_hashtab.ht_array; |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5156 --hi; |
a712ea475390
patch 8.2.4989: cannot specify a function name for :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
28850
diff
changeset
|
5157 } |
20544
e8132bec4b0f
patch 8.2.0826: Vim9: crash in :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
20542
diff
changeset
|
5158 } |
e8132bec4b0f
patch 8.2.0826: Vim9: crash in :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
20542
diff
changeset
|
5159 } |
20528
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
5160 } |
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
5161 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5162 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5163 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5164 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5165 * Return 5 if "p" starts with "<SID>" or "<SNR>" (ignoring case). |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5166 * Return 2 if "p" starts with "s:". |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5167 * Return 0 otherwise. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5168 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5169 int |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5170 eval_fname_script(char_u *p) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5171 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5172 // Use MB_STRICMP() because in Turkish comparing the "I" may not work with |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5173 // the standard library function. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5174 if (p[0] == '<' && (MB_STRNICMP(p + 1, "SID>", 4) == 0 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5175 || MB_STRNICMP(p + 1, "SNR>", 4) == 0)) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5176 return 5; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5177 if (p[0] == 's' && p[1] == ':') |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5178 return 2; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5179 return 0; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5180 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5181 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5182 int |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
5183 translated_function_exists(char_u *name, int is_global) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5184 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5185 if (builtin_function(name, -1)) |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
5186 return has_internal_func(name); |
27114
98a01021e465
patch 8.2.4086: "cctx" argument of find_func_even_dead() is unused
Bram Moolenaar <Bram@vim.org>
parents:
27092
diff
changeset
|
5187 return find_func(name, is_global) != NULL; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
5188 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
5189 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
5190 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
5191 * Return TRUE when "ufunc" has old-style "..." varargs |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
5192 * or named varargs "...name: type". |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
5193 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
5194 int |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
5195 has_varargs(ufunc_T *ufunc) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
5196 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
5197 return ufunc->uf_varargs || ufunc->uf_va_name != NULL; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5198 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5199 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5200 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5201 * Return TRUE if a function "name" exists. |
9717
6226de5f8137
commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents:
9688
diff
changeset
|
5202 * If "no_defef" is TRUE, do not dereference a Funcref. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5203 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5204 int |
9717
6226de5f8137
commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents:
9688
diff
changeset
|
5205 function_exists(char_u *name, int no_deref) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5206 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5207 char_u *nm = name; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5208 char_u *p; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5209 int n = FALSE; |
9717
6226de5f8137
commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents:
9688
diff
changeset
|
5210 int flag; |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
5211 int is_global = FALSE; |
9717
6226de5f8137
commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents:
9688
diff
changeset
|
5212 |
6226de5f8137
commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents:
9688
diff
changeset
|
5213 flag = TFN_INT | TFN_QUIET | TFN_NO_AUTOLOAD; |
6226de5f8137
commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents:
9688
diff
changeset
|
5214 if (no_deref) |
6226de5f8137
commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents:
9688
diff
changeset
|
5215 flag |= TFN_NO_DEREF; |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
5216 p = trans_function_name(&nm, &is_global, FALSE, flag, NULL, NULL, NULL); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5217 nm = skipwhite(nm); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5218 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5219 // Only accept "funcname", "funcname ", "funcname (..." and |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5220 // "funcname(...", not "funcname!...". |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5221 if (p != NULL && (*nm == NUL || *nm == '(')) |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
5222 n = translated_function_exists(p, is_global); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5223 vim_free(p); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5224 return n; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5225 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5226 |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
5227 #if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5228 char_u * |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5229 get_expanded_name(char_u *name, int check) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5230 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5231 char_u *nm = name; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5232 char_u *p; |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
5233 int is_global = FALSE; |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
5234 |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
5235 p = trans_function_name(&nm, &is_global, FALSE, |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
5236 TFN_INT|TFN_QUIET, NULL, NULL, NULL); |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
5237 |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
5238 if (p != NULL && *nm == NUL |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
5239 && (!check || translated_function_exists(p, is_global))) |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
5240 return p; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5241 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5242 vim_free(p); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5243 return NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5244 } |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
5245 #endif |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5246 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5247 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5248 * Function given to ExpandGeneric() to obtain the list of user defined |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5249 * function names. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5250 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5251 char_u * |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5252 get_user_func_name(expand_T *xp, int idx) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5253 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5254 static long_u done; |
21319
fb3dcd8ed14d
patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents:
21313
diff
changeset
|
5255 static int changed; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5256 static hashitem_T *hi; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5257 ufunc_T *fp; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5258 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5259 if (idx == 0) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5260 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5261 done = 0; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5262 hi = func_hashtab.ht_array; |
21319
fb3dcd8ed14d
patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents:
21313
diff
changeset
|
5263 changed = func_hashtab.ht_changed; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5264 } |
21319
fb3dcd8ed14d
patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents:
21313
diff
changeset
|
5265 if (changed == func_hashtab.ht_changed && done < func_hashtab.ht_used) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5266 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5267 if (done++ > 0) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5268 ++hi; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5269 while (HASHITEM_EMPTY(hi)) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5270 ++hi; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5271 fp = HI2UF(hi); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5272 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
5273 // don't show dead, dict and lambda functions |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
5274 if ((fp->uf_flags & FC_DEAD) || (fp->uf_flags & FC_DICT) |
9638
af0d98d8836e
commit https://github.com/vim/vim/commit/b49edc11a1872fa99befa9a4a8ea6c8537868038
Christian Brabandt <cb@256bit.org>
parents:
9626
diff
changeset
|
5275 || STRNCMP(fp->uf_name, "<lambda>", 8) == 0) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
5276 return (char_u *)""; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5277 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5278 if (STRLEN(fp->uf_name) + 4 >= IOSIZE) |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5279 return fp->uf_name; // prevents overflow |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5280 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5281 cat_func_name(IObuff, fp); |
25694
ce91372ca07b
patch 8.2.3383: Vim9: completion for :disassemble adds parenthesis
Bram Moolenaar <Bram@vim.org>
parents:
25632
diff
changeset
|
5282 if (xp->xp_context != EXPAND_USER_FUNC |
ce91372ca07b
patch 8.2.3383: Vim9: completion for :disassemble adds parenthesis
Bram Moolenaar <Bram@vim.org>
parents:
25632
diff
changeset
|
5283 && xp->xp_context != EXPAND_DISASSEMBLE) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5284 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5285 STRCAT(IObuff, "("); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
5286 if (!has_varargs(fp) && fp->uf_args.ga_len == 0) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5287 STRCAT(IObuff, ")"); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5288 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5289 return IObuff; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5290 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5291 return NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5292 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5293 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5294 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5295 * ":delfunction {name}" |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5296 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5297 void |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5298 ex_delfunction(exarg_T *eap) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5299 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5300 ufunc_T *fp = NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5301 char_u *p; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5302 char_u *name; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5303 funcdict_T fudi; |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
5304 int is_global = FALSE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5305 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5306 p = eap->arg; |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
5307 name = trans_function_name(&p, &is_global, eap->skip, 0, &fudi, |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
5308 NULL, NULL); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5309 vim_free(fudi.fd_newkey); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5310 if (name == NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5311 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5312 if (fudi.fd_dict != NULL && !eap->skip) |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
5313 emsg(_(e_funcref_required)); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5314 return; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5315 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5316 if (!ends_excmd(*skipwhite(p))) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5317 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5318 vim_free(name); |
26883
7f150a4936f2
patch 8.2.3970: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
5319 semsg(_(e_trailing_characters_str), p); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5320 return; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5321 } |
25521
2063b858cad9
patch 8.2.3297: cannot use all commands inside a {} block
Bram Moolenaar <Bram@vim.org>
parents:
25473
diff
changeset
|
5322 set_nextcmd(eap, p); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5323 if (eap->nextcmd != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5324 *p = NUL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5325 |
26566
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
5326 if (numbered_function(name) && fudi.fd_dict == NULL) |
25745
b916d59f259f
patch 8.2.3408: can delete a numbered function
Bram Moolenaar <Bram@vim.org>
parents:
25737
diff
changeset
|
5327 { |
b916d59f259f
patch 8.2.3408: can delete a numbered function
Bram Moolenaar <Bram@vim.org>
parents:
25737
diff
changeset
|
5328 if (!eap->skip) |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26857
diff
changeset
|
5329 semsg(_(e_invalid_argument_str), eap->arg); |
25745
b916d59f259f
patch 8.2.3408: can delete a numbered function
Bram Moolenaar <Bram@vim.org>
parents:
25737
diff
changeset
|
5330 vim_free(name); |
b916d59f259f
patch 8.2.3408: can delete a numbered function
Bram Moolenaar <Bram@vim.org>
parents:
25737
diff
changeset
|
5331 return; |
b916d59f259f
patch 8.2.3408: can delete a numbered function
Bram Moolenaar <Bram@vim.org>
parents:
25737
diff
changeset
|
5332 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5333 if (!eap->skip) |
27114
98a01021e465
patch 8.2.4086: "cctx" argument of find_func_even_dead() is unused
Bram Moolenaar <Bram@vim.org>
parents:
27092
diff
changeset
|
5334 fp = find_func(name, is_global); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5335 vim_free(name); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5336 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5337 if (!eap->skip) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5338 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5339 if (fp == NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5340 { |
11545
1780e6fecb30
patch 8.0.0655: not easy to make sure a function does not exist
Christian Brabandt <cb@256bit.org>
parents:
11543
diff
changeset
|
5341 if (!eap->forceit) |
26757
3a2b222107a6
patch 8.2.3907: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26747
diff
changeset
|
5342 semsg(_(e_unknown_function_str), eap->arg); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5343 return; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5344 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5345 if (fp->uf_calls > 0) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5346 { |
26757
3a2b222107a6
patch 8.2.3907: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26747
diff
changeset
|
5347 semsg(_(e_cannot_delete_function_str_it_is_in_use), eap->arg); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5348 return; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5349 } |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
5350 if (fp->uf_flags & FC_VIM9) |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
5351 { |
21821
0deb6f96a5a3
patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
21791
diff
changeset
|
5352 semsg(_(e_cannot_delete_vim9_script_function_str), eap->arg); |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
5353 return; |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
5354 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5355 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5356 if (fudi.fd_dict != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5357 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5358 // Delete the dict item that refers to the function, it will |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5359 // invoke func_unref() and possibly delete the function. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5360 dictitem_remove(fudi.fd_dict, fudi.fd_di); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5361 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5362 else |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5363 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5364 // A normal function (not a numbered function or lambda) has a |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5365 // refcount of 1 for the entry in the hashtable. When deleting |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5366 // it and the refcount is more than one, it should be kept. |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5367 // A numbered function and lambda should be kept if the refcount is |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5368 // one or more. |
9733
59565cdd7261
commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents:
9731
diff
changeset
|
5369 if (fp->uf_refcount > (func_name_refcount(fp->uf_name) ? 0 : 1)) |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5370 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5371 // Function is still referenced somewhere. Don't free it but |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5372 // do remove it from the hashtable. |
9733
59565cdd7261
commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents:
9731
diff
changeset
|
5373 if (func_remove(fp)) |
59565cdd7261
commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents:
9731
diff
changeset
|
5374 fp->uf_refcount--; |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5375 } |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5376 else |
10815
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
5377 func_clear_free(fp, FALSE); |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5378 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5379 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5380 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5381 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5382 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5383 * Unreference a Function: decrement the reference count and free it when it |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5384 * becomes zero. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5385 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5386 void |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5387 func_unref(char_u *name) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5388 { |
9655
f1920505bc16
commit https://github.com/vim/vim/commit/97baee80f0906ee2f651ee1215ec033e84f866ad
Christian Brabandt <cb@256bit.org>
parents:
9638
diff
changeset
|
5389 ufunc_T *fp = NULL; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5390 |
9733
59565cdd7261
commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents:
9731
diff
changeset
|
5391 if (name == NULL || !func_name_refcount(name)) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5392 return; |
27114
98a01021e465
patch 8.2.4086: "cctx" argument of find_func_even_dead() is unused
Bram Moolenaar <Bram@vim.org>
parents:
27092
diff
changeset
|
5393 fp = find_func(name, FALSE); |
26566
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
5394 if (fp == NULL && numbered_function(name)) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5395 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5396 #ifdef EXITFREE |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5397 if (!entered_free_all_mem) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5398 #endif |
10359
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5399 internal_error("func_unref()"); |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5400 } |
23699
317018f62643
patch 8.2.2391: memory leak when creating a global function with closure
Bram Moolenaar <Bram@vim.org>
parents:
23644
diff
changeset
|
5401 func_ptr_unref(fp); |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5402 } |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5403 |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5404 /* |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5405 * Unreference a Function: decrement the reference count and free it when it |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5406 * becomes zero. |
23699
317018f62643
patch 8.2.2391: memory leak when creating a global function with closure
Bram Moolenaar <Bram@vim.org>
parents:
23644
diff
changeset
|
5407 * Also when it becomes one and uf_partial points to the function. |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5408 */ |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5409 void |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5410 func_ptr_unref(ufunc_T *fp) |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5411 { |
23699
317018f62643
patch 8.2.2391: memory leak when creating a global function with closure
Bram Moolenaar <Bram@vim.org>
parents:
23644
diff
changeset
|
5412 if (fp != NULL && (--fp->uf_refcount <= 0 |
317018f62643
patch 8.2.2391: memory leak when creating a global function with closure
Bram Moolenaar <Bram@vim.org>
parents:
23644
diff
changeset
|
5413 || (fp->uf_refcount == 1 && fp->uf_partial != NULL |
317018f62643
patch 8.2.2391: memory leak when creating a global function with closure
Bram Moolenaar <Bram@vim.org>
parents:
23644
diff
changeset
|
5414 && fp->uf_partial->pt_refcount <= 1 |
317018f62643
patch 8.2.2391: memory leak when creating a global function with closure
Bram Moolenaar <Bram@vim.org>
parents:
23644
diff
changeset
|
5415 && fp->uf_partial->pt_func == fp))) |
9655
f1920505bc16
commit https://github.com/vim/vim/commit/97baee80f0906ee2f651ee1215ec033e84f866ad
Christian Brabandt <cb@256bit.org>
parents:
9638
diff
changeset
|
5416 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5417 // Only delete it when it's not being used. Otherwise it's done |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5418 // when "uf_calls" becomes zero. |
9655
f1920505bc16
commit https://github.com/vim/vim/commit/97baee80f0906ee2f651ee1215ec033e84f866ad
Christian Brabandt <cb@256bit.org>
parents:
9638
diff
changeset
|
5419 if (fp->uf_calls == 0) |
10815
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
5420 func_clear_free(fp, FALSE); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5421 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5422 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5423 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5424 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5425 * Count a reference to a Function. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5426 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5427 void |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5428 func_ref(char_u *name) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5429 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5430 ufunc_T *fp; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5431 |
9733
59565cdd7261
commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents:
9731
diff
changeset
|
5432 if (name == NULL || !func_name_refcount(name)) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5433 return; |
27114
98a01021e465
patch 8.2.4086: "cctx" argument of find_func_even_dead() is unused
Bram Moolenaar <Bram@vim.org>
parents:
27092
diff
changeset
|
5434 fp = find_func(name, FALSE); |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5435 if (fp != NULL) |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5436 ++fp->uf_refcount; |
26566
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
5437 else if (numbered_function(name)) |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5438 // Only give an error for a numbered function. |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5439 // Fail silently, when named or lambda function isn't found. |
10359
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5440 internal_error("func_ref()"); |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5441 } |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5442 |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5443 /* |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5444 * Count a reference to a Function. |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5445 */ |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5446 void |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5447 func_ptr_ref(ufunc_T *fp) |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5448 { |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5449 if (fp != NULL) |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5450 ++fp->uf_refcount; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5451 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5452 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5453 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5454 * Return TRUE if items in "fc" do not have "copyID". That means they are not |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5455 * referenced from anywhere that is in use. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5456 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5457 static int |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5458 can_free_funccal(funccall_T *fc, int copyID) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5459 { |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
5460 return (fc->fc_l_varlist.lv_copyID != copyID |
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
5461 && fc->fc_l_vars.dv_copyID != copyID |
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
5462 && fc->fc_l_avars.dv_copyID != copyID |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
5463 && fc->fc_copyID != copyID); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5464 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5465 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5466 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5467 * ":return [expr]" |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5468 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5469 void |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5470 ex_return(exarg_T *eap) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5471 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5472 char_u *arg = eap->arg; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5473 typval_T rettv; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5474 int returning = FALSE; |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20945
diff
changeset
|
5475 evalarg_T evalarg; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5476 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5477 if (current_funccal == NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5478 { |
26757
3a2b222107a6
patch 8.2.3907: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26747
diff
changeset
|
5479 emsg(_(e_return_not_inside_function)); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5480 return; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5481 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5482 |
26053
e861c5aaedd8
patch 8.2.3560: using freed memory with lambda
Bram Moolenaar <Bram@vim.org>
parents:
26046
diff
changeset
|
5483 init_evalarg(&evalarg); |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20945
diff
changeset
|
5484 evalarg.eval_flags = eap->skip ? 0 : EVAL_EVALUATE; |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20945
diff
changeset
|
5485 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5486 if (eap->skip) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5487 ++emsg_skip; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5488 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5489 eap->nextcmd = NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5490 if ((*arg != NUL && *arg != '|' && *arg != '\n') |
20996
3af71cbcfdbe
patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
5491 && eval0(arg, &rettv, eap, &evalarg) != FAIL) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5492 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5493 if (!eap->skip) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5494 returning = do_return(eap, FALSE, TRUE, &rettv); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5495 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5496 clear_tv(&rettv); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5497 } |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5498 // It's safer to return also on error. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5499 else if (!eap->skip) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5500 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5501 // In return statement, cause_abort should be force_abort. |
13096
30f9a62f5f51
patch 8.0.1423: error in return not caught by try/catch
Christian Brabandt <cb@256bit.org>
parents:
13004
diff
changeset
|
5502 update_force_abort(); |
30f9a62f5f51
patch 8.0.1423: error in return not caught by try/catch
Christian Brabandt <cb@256bit.org>
parents:
13004
diff
changeset
|
5503 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5504 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5505 * Return unless the expression evaluation has been cancelled due to an |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5506 * aborting error, an interrupt, or an exception. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5507 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5508 if (!aborting()) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5509 returning = do_return(eap, FALSE, TRUE, NULL); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5510 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5511 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5512 // When skipping or the return gets pending, advance to the next command |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5513 // in this line (!returning). Otherwise, ignore the rest of the line. |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5514 // Following lines will be ignored by get_func_line(). |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5515 if (returning) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5516 eap->nextcmd = NULL; |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5517 else if (eap->nextcmd == NULL) // no argument |
25521
2063b858cad9
patch 8.2.3297: cannot use all commands inside a {} block
Bram Moolenaar <Bram@vim.org>
parents:
25473
diff
changeset
|
5518 set_nextcmd(eap, arg); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5519 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5520 if (eap->skip) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5521 --emsg_skip; |
21058
111f877e63d9
patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents:
21046
diff
changeset
|
5522 clear_evalarg(&evalarg, eap); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5523 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5524 |
30065
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5525 static int |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5526 ex_call_inner( |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5527 exarg_T *eap, |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5528 char_u *name, |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5529 char_u **arg, |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5530 char_u *startarg, |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5531 funcexe_T *funcexe_init, |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5532 evalarg_T *evalarg) |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5533 { |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5534 linenr_T lnum; |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5535 int doesrange; |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5536 typval_T rettv; |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5537 int failed = FALSE; |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5538 |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5539 /* |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5540 * When skipping, evaluate the function once, to find the end of the |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5541 * arguments. |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5542 * When the function takes a range, this is discovered after the first |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5543 * call, and the loop is broken. |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5544 */ |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5545 if (eap->skip) |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5546 { |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5547 ++emsg_skip; |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5548 lnum = eap->line2; // do it once, also with an invalid range |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5549 } |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5550 else |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5551 lnum = eap->line1; |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5552 for ( ; lnum <= eap->line2; ++lnum) |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5553 { |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5554 funcexe_T funcexe; |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5555 |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5556 if (!eap->skip && eap->addr_count > 0) |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5557 { |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5558 if (lnum > curbuf->b_ml.ml_line_count) |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5559 { |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5560 // If the function deleted lines or switched to another buffer |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5561 // the line number may become invalid. |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5562 emsg(_(e_invalid_range)); |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5563 break; |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5564 } |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5565 curwin->w_cursor.lnum = lnum; |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5566 curwin->w_cursor.col = 0; |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5567 curwin->w_cursor.coladd = 0; |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5568 } |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5569 *arg = startarg; |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5570 |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5571 funcexe = *funcexe_init; |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5572 funcexe.fe_doesrange = &doesrange; |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5573 rettv.v_type = VAR_UNKNOWN; // clear_tv() uses this |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5574 if (get_func_tv(name, -1, &rettv, arg, evalarg, &funcexe) == FAIL) |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5575 { |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5576 failed = TRUE; |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5577 break; |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5578 } |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5579 if (has_watchexpr()) |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5580 dbg_check_breakpoint(eap); |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5581 |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5582 // Handle a function returning a Funcref, Dictionary or List. |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5583 if (handle_subscript(arg, NULL, &rettv, |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5584 eap->skip ? NULL : &EVALARG_EVALUATE, TRUE) == FAIL) |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5585 { |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5586 failed = TRUE; |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5587 break; |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5588 } |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5589 |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5590 clear_tv(&rettv); |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5591 if (doesrange || eap->skip) |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5592 break; |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5593 |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5594 // Stop when immediately aborting on error, or when an interrupt |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5595 // occurred or an exception was thrown but not caught. |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5596 // get_func_tv() returned OK, so that the check for trailing |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5597 // characters below is executed. |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5598 if (aborting()) |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5599 break; |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5600 } |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5601 if (eap->skip) |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5602 --emsg_skip; |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5603 return failed; |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5604 } |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5605 |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5606 /* |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5607 * Core part of ":defer func(arg)". "arg" points to the "(" and is advanced. |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5608 * Returns FAIL or OK. |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5609 */ |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5610 static int |
30108
0352577f1ba5
patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
5611 ex_defer_inner( |
0352577f1ba5
patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
5612 char_u *name, |
0352577f1ba5
patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
5613 char_u **arg, |
30166
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30150
diff
changeset
|
5614 type_T *type, |
30108
0352577f1ba5
patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
5615 partial_T *partial, |
0352577f1ba5
patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
5616 evalarg_T *evalarg) |
30065
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5617 { |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5618 typval_T argvars[MAX_FUNC_ARGS + 1]; // vars for arguments |
30108
0352577f1ba5
patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
5619 int partial_argc = 0; // number of partial arguments |
30065
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5620 int argcount = 0; // number of arguments found |
30108
0352577f1ba5
patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
5621 int r; |
30065
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5622 |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5623 if (current_funccal == NULL) |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5624 { |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5625 semsg(_(e_str_not_inside_function), "defer"); |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5626 return FAIL; |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5627 } |
30108
0352577f1ba5
patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
5628 if (partial != NULL) |
0352577f1ba5
patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
5629 { |
0352577f1ba5
patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
5630 if (partial->pt_dict != NULL) |
0352577f1ba5
patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
5631 { |
0352577f1ba5
patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
5632 emsg(_(e_cannot_use_partial_with_dictionary_for_defer)); |
0352577f1ba5
patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
5633 return FAIL; |
0352577f1ba5
patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
5634 } |
0352577f1ba5
patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
5635 if (partial->pt_argc > 0) |
0352577f1ba5
patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
5636 { |
0352577f1ba5
patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
5637 int i; |
0352577f1ba5
patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
5638 |
0352577f1ba5
patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
5639 partial_argc = partial->pt_argc; |
0352577f1ba5
patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
5640 for (i = 0; i < partial_argc; ++i) |
0352577f1ba5
patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
5641 copy_tv(&partial->pt_argv[i], &argvars[i]); |
0352577f1ba5
patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
5642 } |
0352577f1ba5
patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
5643 } |
0352577f1ba5
patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
5644 r = get_func_arguments(arg, evalarg, FALSE, |
0352577f1ba5
patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
5645 argvars + partial_argc, &argcount); |
0352577f1ba5
patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
5646 argcount += partial_argc; |
30166
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30150
diff
changeset
|
5647 |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30150
diff
changeset
|
5648 if (r == OK) |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30150
diff
changeset
|
5649 { |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30150
diff
changeset
|
5650 if (type != NULL) |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30150
diff
changeset
|
5651 { |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30150
diff
changeset
|
5652 // Check that the arguments are OK for the types of the funcref. |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30150
diff
changeset
|
5653 r = check_argument_types(type, argvars, argcount, NULL, name); |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30150
diff
changeset
|
5654 } |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30150
diff
changeset
|
5655 else if (builtin_function(name, -1)) |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30150
diff
changeset
|
5656 { |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30150
diff
changeset
|
5657 int idx = find_internal_func(name); |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30150
diff
changeset
|
5658 |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30150
diff
changeset
|
5659 if (idx < 0) |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30150
diff
changeset
|
5660 { |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30150
diff
changeset
|
5661 emsg_funcname(e_unknown_function_str, name); |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30150
diff
changeset
|
5662 r = FAIL; |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30150
diff
changeset
|
5663 } |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30150
diff
changeset
|
5664 else if (check_internal_func(idx, argcount) == -1) |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30150
diff
changeset
|
5665 r = FAIL; |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30150
diff
changeset
|
5666 } |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30150
diff
changeset
|
5667 else |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30150
diff
changeset
|
5668 { |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30150
diff
changeset
|
5669 ufunc_T *ufunc = find_func(name, FALSE); |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30150
diff
changeset
|
5670 |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30150
diff
changeset
|
5671 // we tolerate an unknown function here, it might be defined later |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30150
diff
changeset
|
5672 if (ufunc != NULL) |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30150
diff
changeset
|
5673 { |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30150
diff
changeset
|
5674 int error = check_user_func_argcount(ufunc, argcount); |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30150
diff
changeset
|
5675 |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30150
diff
changeset
|
5676 if (error != FCERR_UNKNOWN) |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30150
diff
changeset
|
5677 { |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30150
diff
changeset
|
5678 user_func_error(error, name, NULL); |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30150
diff
changeset
|
5679 r = FAIL; |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30150
diff
changeset
|
5680 } |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30150
diff
changeset
|
5681 } |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30150
diff
changeset
|
5682 } |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30150
diff
changeset
|
5683 } |
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30150
diff
changeset
|
5684 |
30108
0352577f1ba5
patch 9.0.0390: cannot use a partial with :defer
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
5685 if (r == FAIL) |
30083
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30079
diff
changeset
|
5686 { |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30079
diff
changeset
|
5687 while (--argcount >= 0) |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30079
diff
changeset
|
5688 clear_tv(&argvars[argcount]); |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30079
diff
changeset
|
5689 return FAIL; |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30079
diff
changeset
|
5690 } |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30079
diff
changeset
|
5691 return add_defer(name, argcount, argvars); |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30079
diff
changeset
|
5692 } |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30079
diff
changeset
|
5693 |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30079
diff
changeset
|
5694 /* |
30150
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30140
diff
changeset
|
5695 * Return TRUE if currently inside a function call. |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30140
diff
changeset
|
5696 * Give an error message and return FALSE when not. |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30140
diff
changeset
|
5697 */ |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30140
diff
changeset
|
5698 int |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30140
diff
changeset
|
5699 can_add_defer(void) |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30140
diff
changeset
|
5700 { |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30140
diff
changeset
|
5701 if (!in_def_function() && get_current_funccal() == NULL) |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30140
diff
changeset
|
5702 { |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30140
diff
changeset
|
5703 semsg(_(e_str_not_inside_function), "defer"); |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30140
diff
changeset
|
5704 return FALSE; |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30140
diff
changeset
|
5705 } |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30140
diff
changeset
|
5706 return TRUE; |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30140
diff
changeset
|
5707 } |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30140
diff
changeset
|
5708 |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30140
diff
changeset
|
5709 /* |
30083
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30079
diff
changeset
|
5710 * Add a deferred call for "name" with arguments "argvars[argcount]". |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30079
diff
changeset
|
5711 * Consumes "argvars[]". |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30079
diff
changeset
|
5712 * Caller must check that in_def_function() returns TRUE or current_funccal is |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30079
diff
changeset
|
5713 * not NULL. |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30079
diff
changeset
|
5714 * Returns OK or FAIL. |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30079
diff
changeset
|
5715 */ |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30079
diff
changeset
|
5716 int |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30079
diff
changeset
|
5717 add_defer(char_u *name, int argcount_arg, typval_T *argvars) |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30079
diff
changeset
|
5718 { |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30079
diff
changeset
|
5719 char_u *saved_name = vim_strsave(name); |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30079
diff
changeset
|
5720 int argcount = argcount_arg; |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30079
diff
changeset
|
5721 defer_T *dr; |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30079
diff
changeset
|
5722 int ret = FAIL; |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30079
diff
changeset
|
5723 |
30065
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5724 if (saved_name == NULL) |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5725 goto theend; |
30083
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30079
diff
changeset
|
5726 if (in_def_function()) |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30079
diff
changeset
|
5727 { |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30079
diff
changeset
|
5728 if (add_defer_function(saved_name, argcount, argvars) == OK) |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30079
diff
changeset
|
5729 argcount = 0; |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30079
diff
changeset
|
5730 } |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30079
diff
changeset
|
5731 else |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30079
diff
changeset
|
5732 { |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30079
diff
changeset
|
5733 if (current_funccal->fc_defer.ga_itemsize == 0) |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30079
diff
changeset
|
5734 ga_init2(¤t_funccal->fc_defer, sizeof(defer_T), 10); |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30079
diff
changeset
|
5735 if (ga_grow(¤t_funccal->fc_defer, 1) == FAIL) |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30079
diff
changeset
|
5736 goto theend; |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30079
diff
changeset
|
5737 dr = ((defer_T *)current_funccal->fc_defer.ga_data) |
30065
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5738 + current_funccal->fc_defer.ga_len++; |
30083
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30079
diff
changeset
|
5739 dr->dr_name = saved_name; |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30079
diff
changeset
|
5740 dr->dr_argcount = argcount; |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30079
diff
changeset
|
5741 while (argcount > 0) |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30079
diff
changeset
|
5742 { |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30079
diff
changeset
|
5743 --argcount; |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30079
diff
changeset
|
5744 dr->dr_argvars[argcount] = argvars[argcount]; |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30079
diff
changeset
|
5745 } |
30065
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5746 } |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5747 ret = OK; |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5748 |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5749 theend: |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5750 while (--argcount >= 0) |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5751 clear_tv(&argvars[argcount]); |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5752 return ret; |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5753 } |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5754 |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5755 /* |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5756 * Invoked after a functions has finished: invoke ":defer" functions. |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5757 */ |
30122
458162398682
patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents:
30108
diff
changeset
|
5758 static void |
458162398682
patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents:
30108
diff
changeset
|
5759 handle_defer_one(funccall_T *funccal) |
30065
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5760 { |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5761 int idx; |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5762 |
30122
458162398682
patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents:
30108
diff
changeset
|
5763 for (idx = funccal->fc_defer.ga_len - 1; idx >= 0; --idx) |
30065
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5764 { |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5765 funcexe_T funcexe; |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5766 typval_T rettv; |
30122
458162398682
patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents:
30108
diff
changeset
|
5767 defer_T *dr = ((defer_T *)funccal->fc_defer.ga_data) + idx; |
30065
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5768 int i; |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5769 |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5770 CLEAR_FIELD(funcexe); |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5771 funcexe.fe_evaluate = TRUE; |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5772 |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5773 rettv.v_type = VAR_UNKNOWN; // clear_tv() uses this |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5774 call_func(dr->dr_name, -1, &rettv, |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5775 dr->dr_argcount, dr->dr_argvars, &funcexe); |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5776 clear_tv(&rettv); |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5777 vim_free(dr->dr_name); |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5778 for (i = dr->dr_argcount - 1; i >= 0; --i) |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5779 clear_tv(&dr->dr_argvars[i]); |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5780 } |
30122
458162398682
patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents:
30108
diff
changeset
|
5781 ga_clear(&funccal->fc_defer); |
458162398682
patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents:
30108
diff
changeset
|
5782 } |
458162398682
patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents:
30108
diff
changeset
|
5783 |
458162398682
patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents:
30108
diff
changeset
|
5784 /* |
458162398682
patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents:
30108
diff
changeset
|
5785 * Called when exiting: call all defer functions. |
458162398682
patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents:
30108
diff
changeset
|
5786 */ |
458162398682
patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents:
30108
diff
changeset
|
5787 void |
458162398682
patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents:
30108
diff
changeset
|
5788 invoke_all_defer(void) |
458162398682
patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents:
30108
diff
changeset
|
5789 { |
458162398682
patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents:
30108
diff
changeset
|
5790 funccall_T *funccal; |
458162398682
patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents:
30108
diff
changeset
|
5791 |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
5792 for (funccal = current_funccal; funccal != NULL; |
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
5793 funccal = funccal->fc_caller) |
30122
458162398682
patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents:
30108
diff
changeset
|
5794 if (funccal->fc_ectx != NULL) |
458162398682
patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents:
30108
diff
changeset
|
5795 { |
458162398682
patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents:
30108
diff
changeset
|
5796 // :def function |
458162398682
patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents:
30108
diff
changeset
|
5797 unwind_def_callstack(funccal->fc_ectx); |
458162398682
patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents:
30108
diff
changeset
|
5798 may_invoke_defer_funcs(funccal->fc_ectx); |
458162398682
patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents:
30108
diff
changeset
|
5799 } |
458162398682
patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents:
30108
diff
changeset
|
5800 else |
458162398682
patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents:
30108
diff
changeset
|
5801 { |
458162398682
patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents:
30108
diff
changeset
|
5802 // legacy function |
458162398682
patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents:
30108
diff
changeset
|
5803 handle_defer_one(funccal); |
458162398682
patch 9.0.0397: :defer not tested with exceptions and ":qa!"
Bram Moolenaar <Bram@vim.org>
parents:
30108
diff
changeset
|
5804 } |
30065
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5805 } |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5806 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5807 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5808 * ":1,25call func(arg1, arg2)" function call. |
30065
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5809 * ":defer func(arg1, arg2)" deferred function call. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5810 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5811 void |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5812 ex_call(exarg_T *eap) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5813 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5814 char_u *arg = eap->arg; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5815 char_u *startarg; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5816 char_u *name; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5817 char_u *tofree; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5818 int len; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5819 int failed = FALSE; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5820 funcdict_T fudi; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5821 partial_T *partial = NULL; |
21118
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21066
diff
changeset
|
5822 evalarg_T evalarg; |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
5823 type_T *type = NULL; |
26506
4a1d2abc2016
patch 8.2.3783: confusing error for using a variable as a function
Bram Moolenaar <Bram@vim.org>
parents:
26504
diff
changeset
|
5824 int found_var = FALSE; |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
5825 int vim9script = in_vim9script(); |
21118
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21066
diff
changeset
|
5826 |
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21066
diff
changeset
|
5827 fill_evalarg_from_eap(&evalarg, eap, eap->skip); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5828 if (eap->skip) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5829 { |
30065
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5830 typval_T rettv; |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5831 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5832 // trans_function_name() doesn't work well when skipping, use eval0() |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5833 // instead to skip to any following command, e.g. for: |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5834 // :if 0 | call dict.foo().bar() | endif |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5835 ++emsg_skip; |
21118
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21066
diff
changeset
|
5836 if (eval0(eap->arg, &rettv, eap, &evalarg) != FAIL) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5837 clear_tv(&rettv); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5838 --emsg_skip; |
21118
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21066
diff
changeset
|
5839 clear_evalarg(&evalarg, eap); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5840 return; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5841 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5842 |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
5843 tofree = trans_function_name(&arg, NULL, eap->skip, TFN_INT, |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
5844 &fudi, &partial, vim9script ? &type : NULL); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5845 if (fudi.fd_newkey != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5846 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5847 // Still need to give an error message for missing key. |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
5848 semsg(_(e_key_not_present_in_dictionary), fudi.fd_newkey); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5849 vim_free(fudi.fd_newkey); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5850 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5851 if (tofree == NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5852 return; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5853 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5854 // Increase refcount on dictionary, it could get deleted when evaluating |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5855 // the arguments. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5856 if (fudi.fd_dict != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5857 ++fudi.fd_dict->dv_refcount; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5858 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5859 // If it is the name of a variable of type VAR_FUNC or VAR_PARTIAL use its |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5860 // contents. For VAR_PARTIAL get its partial, unless we already have one |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5861 // from trans_function_name(). |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5862 len = (int)STRLEN(tofree); |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
5863 name = deref_func_name(tofree, &len, partial != NULL ? NULL : &partial, |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
5864 vim9script && type == NULL ? &type : NULL, |
27233
73232ed49cf2
patch 8.2.4145: confusing error when using name of import for a function
Bram Moolenaar <Bram@vim.org>
parents:
27189
diff
changeset
|
5865 FALSE, FALSE, &found_var); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5866 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5867 // Skip white space to allow ":call func ()". Not good, but required for |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5868 // backward compatibility. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5869 startarg = skipwhite(arg); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5870 if (*startarg != '(') |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5871 { |
26602
fac6673086df
patch 8.2.3830: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26574
diff
changeset
|
5872 semsg(_(e_missing_parenthesis_str), eap->arg); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5873 goto end; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5874 } |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
5875 if (vim9script && startarg > arg) |
25737
d923be9d752d
patch 8.2.3404: Vim9: no error for white space before "("
Bram Moolenaar <Bram@vim.org>
parents:
25694
diff
changeset
|
5876 { |
d923be9d752d
patch 8.2.3404: Vim9: no error for white space before "("
Bram Moolenaar <Bram@vim.org>
parents:
25694
diff
changeset
|
5877 semsg(_(e_no_white_space_allowed_before_str_str), "(", eap->arg); |
d923be9d752d
patch 8.2.3404: Vim9: no error for white space before "("
Bram Moolenaar <Bram@vim.org>
parents:
25694
diff
changeset
|
5878 goto end; |
d923be9d752d
patch 8.2.3404: Vim9: no error for white space before "("
Bram Moolenaar <Bram@vim.org>
parents:
25694
diff
changeset
|
5879 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5880 |
30065
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5881 if (eap->cmdidx == CMD_defer) |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5882 { |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5883 arg = startarg; |
30166
d1c04b4dc60d
patch 9.0.0419: the :defer command does not check the function arguments
Bram Moolenaar <Bram@vim.org>
parents:
30150
diff
changeset
|
5884 failed = ex_defer_inner(name, &arg, type, partial, &evalarg) == FAIL; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5885 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5886 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5887 { |
17606
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17462
diff
changeset
|
5888 funcexe_T funcexe; |
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17462
diff
changeset
|
5889 |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
5890 CLEAR_FIELD(funcexe); |
30065
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5891 funcexe.fe_check_type = type; |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5892 funcexe.fe_partial = partial; |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5893 funcexe.fe_selfdict = fudi.fd_dict; |
26534
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
5894 funcexe.fe_firstline = eap->line1; |
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
5895 funcexe.fe_lastline = eap->line2; |
30065
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5896 funcexe.fe_found_var = found_var; |
26534
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
5897 funcexe.fe_evaluate = !eap->skip; |
30065
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5898 failed = ex_call_inner(eap, name, &arg, startarg, &funcexe, &evalarg); |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5899 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5900 |
25826
5040fae521f6
patch 8.2.3448: :endtry after function call that throws not found
Bram Moolenaar <Bram@vim.org>
parents:
25761
diff
changeset
|
5901 // When inside :try we need to check for following "| catch" or "| endtry". |
5040fae521f6
patch 8.2.3448: :endtry after function call that throws not found
Bram Moolenaar <Bram@vim.org>
parents:
25761
diff
changeset
|
5902 // Not when there was an error, but do check if an exception was thrown. |
30065
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
29930
diff
changeset
|
5903 if ((!aborting() || did_throw) && (!failed || eap->cstack->cs_trylevel > 0)) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5904 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5905 // Check for trailing illegal characters and a following command. |
21737
a849c984b485
patch 8.2.1418: Vim9: invalid error for missing white space
Bram Moolenaar <Bram@vim.org>
parents:
21699
diff
changeset
|
5906 arg = skipwhite(arg); |
20138
d0a9766167ab
patch 8.2.0624: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20081
diff
changeset
|
5907 if (!ends_excmd2(eap->arg, arg)) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5908 { |
25826
5040fae521f6
patch 8.2.3448: :endtry after function call that throws not found
Bram Moolenaar <Bram@vim.org>
parents:
25761
diff
changeset
|
5909 if (!failed && !aborting()) |
19421
208644ebdff8
patch 8.2.0268: trycatch test fails
Bram Moolenaar <Bram@vim.org>
parents:
19419
diff
changeset
|
5910 { |
208644ebdff8
patch 8.2.0268: trycatch test fails
Bram Moolenaar <Bram@vim.org>
parents:
19419
diff
changeset
|
5911 emsg_severe = TRUE; |
26883
7f150a4936f2
patch 8.2.3970: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
5912 semsg(_(e_trailing_characters_str), arg); |
19421
208644ebdff8
patch 8.2.0268: trycatch test fails
Bram Moolenaar <Bram@vim.org>
parents:
19419
diff
changeset
|
5913 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5914 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5915 else |
25521
2063b858cad9
patch 8.2.3297: cannot use all commands inside a {} block
Bram Moolenaar <Bram@vim.org>
parents:
25473
diff
changeset
|
5916 set_nextcmd(eap, arg); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5917 } |
28515
c6aadb2c4cd7
patch 8.2.4782: accessing freed memory
Bram Moolenaar <Bram@vim.org>
parents:
28491
diff
changeset
|
5918 // Must be after using "arg", it may point into memory cleared here. |
c6aadb2c4cd7
patch 8.2.4782: accessing freed memory
Bram Moolenaar <Bram@vim.org>
parents:
28491
diff
changeset
|
5919 clear_evalarg(&evalarg, eap); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5920 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5921 end: |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5922 dict_unref(fudi.fd_dict); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5923 vim_free(tofree); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5924 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5925 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5926 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5927 * Return from a function. Possibly makes the return pending. Also called |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5928 * for a pending return at the ":endtry" or after returning from an extra |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5929 * do_cmdline(). "reanimate" is used in the latter case. "is_cmd" is set |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5930 * when called due to a ":return" command. "rettv" may point to a typval_T |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5931 * with the return rettv. Returns TRUE when the return can be carried out, |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5932 * FALSE when the return gets pending. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5933 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5934 int |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5935 do_return( |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5936 exarg_T *eap, |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5937 int reanimate, |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5938 int is_cmd, |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5939 void *rettv) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5940 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5941 int idx; |
18904
2bdc2e1f6e1f
patch 8.2.0013: not using a typedef for condstack
Bram Moolenaar <Bram@vim.org>
parents:
18816
diff
changeset
|
5942 cstack_T *cstack = eap->cstack; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5943 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5944 if (reanimate) |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5945 // Undo the return. |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
5946 current_funccal->fc_returned = FALSE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5947 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5948 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5949 * Cleanup (and inactivate) conditionals, but stop when a try conditional |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5950 * not in its finally clause (which then is to be executed next) is found. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5951 * In this case, make the ":return" pending for execution at the ":endtry". |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5952 * Otherwise, return normally. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5953 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5954 idx = cleanup_conditionals(eap->cstack, 0, TRUE); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5955 if (idx >= 0) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5956 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5957 cstack->cs_pending[idx] = CSTP_RETURN; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5958 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5959 if (!is_cmd && !reanimate) |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5960 // A pending return again gets pending. "rettv" points to an |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5961 // allocated variable with the rettv of the original ":return"'s |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5962 // argument if present or is NULL else. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5963 cstack->cs_rettv[idx] = rettv; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5964 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5965 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5966 // When undoing a return in order to make it pending, get the stored |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5967 // return rettv. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5968 if (reanimate) |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
5969 rettv = current_funccal->fc_rettv; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5970 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5971 if (rettv != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5972 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5973 // Store the value of the pending return. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5974 if ((cstack->cs_rettv[idx] = alloc_tv()) != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5975 *(typval_T *)cstack->cs_rettv[idx] = *(typval_T *)rettv; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5976 else |
25306
078edc1821bf
patch 8.2.3190: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
25296
diff
changeset
|
5977 emsg(_(e_out_of_memory)); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5978 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5979 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5980 cstack->cs_rettv[idx] = NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5981 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5982 if (reanimate) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5983 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5984 // The pending return value could be overwritten by a ":return" |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5985 // without argument in a finally clause; reset the default |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5986 // return value. |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
5987 current_funccal->fc_rettv->v_type = VAR_NUMBER; |
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
5988 current_funccal->fc_rettv->vval.v_number = 0; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5989 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5990 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5991 report_make_pending(CSTP_RETURN, rettv); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5992 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5993 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5994 { |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
5995 current_funccal->fc_returned = TRUE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5996 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5997 // If the return is carried out now, store the return value. For |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5998 // a return immediately after reanimation, the value is already |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5999 // there. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6000 if (!reanimate && rettv != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6001 { |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6002 clear_tv(current_funccal->fc_rettv); |
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6003 *current_funccal->fc_rettv = *(typval_T *)rettv; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6004 if (!is_cmd) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6005 vim_free(rettv); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6006 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6007 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6008 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6009 return idx < 0; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6010 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6011 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6012 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6013 * Free the variable with a pending return value. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6014 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6015 void |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6016 discard_pending_return(void *rettv) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6017 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6018 free_tv((typval_T *)rettv); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6019 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6020 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6021 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6022 * Generate a return command for producing the value of "rettv". The result |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6023 * is an allocated string. Used by report_pending() for verbose messages. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6024 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6025 char_u * |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6026 get_return_cmd(void *rettv) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6027 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6028 char_u *s = NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6029 char_u *tofree = NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6030 char_u numbuf[NUMBUFLEN]; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6031 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6032 if (rettv != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6033 s = echo_string((typval_T *)rettv, &tofree, numbuf, 0); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6034 if (s == NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6035 s = (char_u *)""; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6036 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6037 STRCPY(IObuff, ":return "); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6038 STRNCPY(IObuff + 8, s, IOSIZE - 8); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6039 if (STRLEN(s) + 8 >= IOSIZE) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6040 STRCPY(IObuff + IOSIZE - 4, "..."); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6041 vim_free(tofree); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6042 return vim_strsave(IObuff); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6043 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6044 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6045 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6046 * Get next function line. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6047 * Called by do_cmdline() to get the next line. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6048 * Returns allocated string, or NULL for end of function. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6049 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6050 char_u * |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6051 get_func_line( |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6052 int c UNUSED, |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6053 void *cookie, |
17178
40c4cb095d53
patch 8.1.1588: in :let-heredoc line continuation is recognized
Bram Moolenaar <Bram@vim.org>
parents:
17168
diff
changeset
|
6054 int indent UNUSED, |
21883
a427f5f26419
patch 8.2.1491: Vim9: crash when compiling heredoc lines start with comment
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
6055 getline_opt_T options UNUSED) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6056 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6057 funccall_T *fcp = (funccall_T *)cookie; |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6058 ufunc_T *fp = fcp->fc_func; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6059 char_u *retval; |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
6060 garray_T *gap; // growarray with function lines |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
6061 |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
6062 // If breakpoints have been added/deleted need to check for it. |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6063 if (fcp->fc_dbg_tick != debug_tick) |
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6064 { |
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6065 fcp->fc_breakpoint = dbg_find_breakpoint(FALSE, fp->uf_name, |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
6066 SOURCING_LNUM); |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6067 fcp->fc_dbg_tick = debug_tick; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6068 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6069 #ifdef FEAT_PROFILE |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6070 if (do_profiling == PROF_YES) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6071 func_line_end(cookie); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6072 #endif |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6073 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6074 gap = &fp->uf_lines; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6075 if (((fp->uf_flags & FC_ABORT) && did_emsg && !aborted_in_try()) |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6076 || fcp->fc_returned) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6077 retval = NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6078 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6079 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
6080 // Skip NULL lines (continuation lines). |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6081 while (fcp->fc_linenr < gap->ga_len |
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6082 && ((char_u **)(gap->ga_data))[fcp->fc_linenr] == NULL) |
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6083 ++fcp->fc_linenr; |
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6084 if (fcp->fc_linenr >= gap->ga_len) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6085 retval = NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6086 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6087 { |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6088 retval = vim_strsave(((char_u **)(gap->ga_data))[fcp->fc_linenr++]); |
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6089 SOURCING_LNUM = fcp->fc_linenr; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6090 #ifdef FEAT_PROFILE |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6091 if (do_profiling == PROF_YES) |
23717
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23699
diff
changeset
|
6092 func_line_start(cookie, SOURCING_LNUM); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6093 #endif |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6094 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6095 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6096 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
6097 // Did we encounter a breakpoint? |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6098 if (fcp->fc_breakpoint != 0 && fcp->fc_breakpoint <= SOURCING_LNUM) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6099 { |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
6100 dbg_breakpoint(fp->uf_name, SOURCING_LNUM); |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
6101 // Find next breakpoint. |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6102 fcp->fc_breakpoint = dbg_find_breakpoint(FALSE, fp->uf_name, |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
6103 SOURCING_LNUM); |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6104 fcp->fc_dbg_tick = debug_tick; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6105 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6106 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6107 return retval; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6108 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6109 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6110 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6111 * Return TRUE if the currently active function should be ended, because a |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6112 * return was encountered or an error occurred. Used inside a ":while". |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6113 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6114 int |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6115 func_has_ended(void *cookie) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6116 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6117 funccall_T *fcp = (funccall_T *)cookie; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6118 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
6119 // Ignore the "abort" flag if the abortion behavior has been changed due to |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
6120 // an error inside a try conditional. |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6121 return (((fcp->fc_func->uf_flags & FC_ABORT) |
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6122 && did_emsg && !aborted_in_try()) |
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6123 || fcp->fc_returned); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6124 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6125 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6126 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6127 * return TRUE if cookie indicates a function which "abort"s on errors. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6128 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6129 int |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6130 func_has_abort( |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6131 void *cookie) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6132 { |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6133 return ((funccall_T *)cookie)->fc_func->uf_flags & FC_ABORT; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6134 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6135 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6136 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6137 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6138 * Turn "dict.Func" into a partial for "Func" bound to "dict". |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6139 * Don't do this when "Func" is already a partial that was bound |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6140 * explicitly (pt_auto is FALSE). |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6141 * Changes "rettv" in-place. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6142 * Returns the updated "selfdict_in". |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6143 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6144 dict_T * |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6145 make_partial(dict_T *selfdict_in, typval_T *rettv) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6146 { |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
6147 char_u *fname; |
28008
cc7d54a134e4
patch 8.2.4529: Vim9: comparing partial with function fails
Bram Moolenaar <Bram@vim.org>
parents:
28006
diff
changeset
|
6148 ufunc_T *fp = NULL; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6149 char_u fname_buf[FLEN_FIXED + 1]; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6150 int error; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6151 dict_T *selfdict = selfdict_in; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6152 |
28008
cc7d54a134e4
patch 8.2.4529: Vim9: comparing partial with function fails
Bram Moolenaar <Bram@vim.org>
parents:
28006
diff
changeset
|
6153 if (rettv->v_type == VAR_PARTIAL && rettv->vval.v_partial != NULL |
cc7d54a134e4
patch 8.2.4529: Vim9: comparing partial with function fails
Bram Moolenaar <Bram@vim.org>
parents:
28006
diff
changeset
|
6154 && rettv->vval.v_partial->pt_func != NULL) |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
6155 fp = rettv->vval.v_partial->pt_func; |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
6156 else |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
6157 { |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
6158 fname = rettv->v_type == VAR_FUNC ? rettv->vval.v_string |
28008
cc7d54a134e4
patch 8.2.4529: Vim9: comparing partial with function fails
Bram Moolenaar <Bram@vim.org>
parents:
28006
diff
changeset
|
6159 : rettv->vval.v_partial == NULL ? NULL |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
6160 : rettv->vval.v_partial->pt_name; |
28008
cc7d54a134e4
patch 8.2.4529: Vim9: comparing partial with function fails
Bram Moolenaar <Bram@vim.org>
parents:
28006
diff
changeset
|
6161 if (fname == NULL) |
cc7d54a134e4
patch 8.2.4529: Vim9: comparing partial with function fails
Bram Moolenaar <Bram@vim.org>
parents:
28006
diff
changeset
|
6162 { |
cc7d54a134e4
patch 8.2.4529: Vim9: comparing partial with function fails
Bram Moolenaar <Bram@vim.org>
parents:
28006
diff
changeset
|
6163 // There is no point binding a dict to a NULL function, just create |
cc7d54a134e4
patch 8.2.4529: Vim9: comparing partial with function fails
Bram Moolenaar <Bram@vim.org>
parents:
28006
diff
changeset
|
6164 // a function reference. |
cc7d54a134e4
patch 8.2.4529: Vim9: comparing partial with function fails
Bram Moolenaar <Bram@vim.org>
parents:
28006
diff
changeset
|
6165 rettv->v_type = VAR_FUNC; |
cc7d54a134e4
patch 8.2.4529: Vim9: comparing partial with function fails
Bram Moolenaar <Bram@vim.org>
parents:
28006
diff
changeset
|
6166 rettv->vval.v_string = NULL; |
cc7d54a134e4
patch 8.2.4529: Vim9: comparing partial with function fails
Bram Moolenaar <Bram@vim.org>
parents:
28006
diff
changeset
|
6167 } |
cc7d54a134e4
patch 8.2.4529: Vim9: comparing partial with function fails
Bram Moolenaar <Bram@vim.org>
parents:
28006
diff
changeset
|
6168 else |
28006
02f787034998
patch 8.2.4528: crash when using null_function for a partial
Bram Moolenaar <Bram@vim.org>
parents:
27978
diff
changeset
|
6169 { |
02f787034998
patch 8.2.4528: crash when using null_function for a partial
Bram Moolenaar <Bram@vim.org>
parents:
27978
diff
changeset
|
6170 char_u *tofree = NULL; |
02f787034998
patch 8.2.4528: crash when using null_function for a partial
Bram Moolenaar <Bram@vim.org>
parents:
27978
diff
changeset
|
6171 |
02f787034998
patch 8.2.4528: crash when using null_function for a partial
Bram Moolenaar <Bram@vim.org>
parents:
27978
diff
changeset
|
6172 // Translate "s:func" to the stored function name. |
02f787034998
patch 8.2.4528: crash when using null_function for a partial
Bram Moolenaar <Bram@vim.org>
parents:
27978
diff
changeset
|
6173 fname = fname_trans_sid(fname, fname_buf, &tofree, &error); |
02f787034998
patch 8.2.4528: crash when using null_function for a partial
Bram Moolenaar <Bram@vim.org>
parents:
27978
diff
changeset
|
6174 fp = find_func(fname, FALSE); |
02f787034998
patch 8.2.4528: crash when using null_function for a partial
Bram Moolenaar <Bram@vim.org>
parents:
27978
diff
changeset
|
6175 vim_free(tofree); |
02f787034998
patch 8.2.4528: crash when using null_function for a partial
Bram Moolenaar <Bram@vim.org>
parents:
27978
diff
changeset
|
6176 } |
02f787034998
patch 8.2.4528: crash when using null_function for a partial
Bram Moolenaar <Bram@vim.org>
parents:
27978
diff
changeset
|
6177 } |
02f787034998
patch 8.2.4528: crash when using null_function for a partial
Bram Moolenaar <Bram@vim.org>
parents:
27978
diff
changeset
|
6178 |
28008
cc7d54a134e4
patch 8.2.4529: Vim9: comparing partial with function fails
Bram Moolenaar <Bram@vim.org>
parents:
28006
diff
changeset
|
6179 if (fp != NULL && (fp->uf_flags & FC_DICT)) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6180 { |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
6181 partial_T *pt = ALLOC_CLEAR_ONE(partial_T); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6182 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6183 if (pt != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6184 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6185 pt->pt_refcount = 1; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6186 pt->pt_dict = selfdict; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6187 pt->pt_auto = TRUE; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6188 selfdict = NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6189 if (rettv->v_type == VAR_FUNC) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6190 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
6191 // Just a function: Take over the function name and use |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
6192 // selfdict. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6193 pt->pt_name = rettv->vval.v_string; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6194 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6195 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6196 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6197 partial_T *ret_pt = rettv->vval.v_partial; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6198 int i; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6199 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
6200 // Partial: copy the function name, use selfdict and copy |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
6201 // args. Can't take over name or args, the partial might |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
6202 // be referenced elsewhere. |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
6203 if (ret_pt->pt_name != NULL) |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
6204 { |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
6205 pt->pt_name = vim_strsave(ret_pt->pt_name); |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
6206 func_ref(pt->pt_name); |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
6207 } |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
6208 else |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
6209 { |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
6210 pt->pt_func = ret_pt->pt_func; |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
6211 func_ptr_ref(pt->pt_func); |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
6212 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6213 if (ret_pt->pt_argc > 0) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6214 { |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
6215 pt->pt_argv = ALLOC_MULT(typval_T, ret_pt->pt_argc); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6216 if (pt->pt_argv == NULL) |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
6217 // out of memory: drop the arguments |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6218 pt->pt_argc = 0; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6219 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6220 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6221 pt->pt_argc = ret_pt->pt_argc; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6222 for (i = 0; i < pt->pt_argc; i++) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6223 copy_tv(&ret_pt->pt_argv[i], &pt->pt_argv[i]); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6224 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6225 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6226 partial_unref(ret_pt); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6227 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6228 rettv->v_type = VAR_PARTIAL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6229 rettv->vval.v_partial = pt; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6230 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6231 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6232 return selfdict; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6233 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6234 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6235 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6236 * Return the name of the executed function. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6237 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6238 char_u * |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6239 func_name(void *cookie) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6240 { |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6241 return ((funccall_T *)cookie)->fc_func->uf_name; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6242 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6243 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6244 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6245 * Return the address holding the next breakpoint line for a funccall cookie. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6246 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6247 linenr_T * |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6248 func_breakpoint(void *cookie) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6249 { |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6250 return &((funccall_T *)cookie)->fc_breakpoint; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6251 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6252 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6253 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6254 * Return the address holding the debug tick for a funccall cookie. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6255 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6256 int * |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6257 func_dbg_tick(void *cookie) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6258 { |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6259 return &((funccall_T *)cookie)->fc_dbg_tick; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6260 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6261 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6262 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6263 * Return the nesting level for a funccall cookie. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6264 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6265 int |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6266 func_level(void *cookie) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6267 { |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6268 return ((funccall_T *)cookie)->fc_level; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6269 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6270 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6271 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6272 * Return TRUE when a function was ended by a ":return" command. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6273 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6274 int |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6275 current_func_returned(void) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6276 { |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6277 return current_funccal->fc_returned; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6278 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6279 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6280 int |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6281 free_unref_funccal(int copyID, int testing) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6282 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6283 int did_free = FALSE; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6284 int did_free_funccal = FALSE; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6285 funccall_T *fc, **pfc; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6286 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6287 for (pfc = &previous_funccal; *pfc != NULL; ) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6288 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6289 if (can_free_funccal(*pfc, copyID)) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6290 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6291 fc = *pfc; |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6292 *pfc = fc->fc_caller; |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
6293 free_funccal_contents(fc); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6294 did_free = TRUE; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6295 did_free_funccal = TRUE; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6296 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6297 else |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6298 pfc = &(*pfc)->fc_caller; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6299 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6300 if (did_free_funccal) |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
6301 // When a funccal was freed some more items might be garbage |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
6302 // collected, so run again. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6303 (void)garbage_collect(testing); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6304 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6305 return did_free; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6306 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6307 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6308 /* |
9951
d990a4394c9d
commit https://github.com/vim/vim/commit/ba2099034f92a2814494f37bddb0c57d034401b4
Christian Brabandt <cb@256bit.org>
parents:
9844
diff
changeset
|
6309 * Get function call environment based on backtrace debug level |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6310 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6311 static funccall_T * |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6312 get_funccal(void) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6313 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6314 int i; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6315 funccall_T *funccal; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6316 funccall_T *temp_funccal; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6317 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6318 funccal = current_funccal; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6319 if (debug_backtrace_level > 0) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6320 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6321 for (i = 0; i < debug_backtrace_level; i++) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6322 { |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6323 temp_funccal = funccal->fc_caller; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6324 if (temp_funccal) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6325 funccal = temp_funccal; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6326 else |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
6327 // backtrace level overflow. reset to max |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6328 debug_backtrace_level = i; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6329 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6330 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6331 return funccal; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6332 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6333 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6334 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6335 * Return the hashtable used for local variables in the current funccal. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6336 * Return NULL if there is no current funccal. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6337 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6338 hashtab_T * |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6339 get_funccal_local_ht() |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6340 { |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6341 if (current_funccal == NULL || current_funccal->fc_l_vars.dv_refcount == 0) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6342 return NULL; |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6343 return &get_funccal()->fc_l_vars.dv_hashtab; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6344 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6345 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6346 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6347 * Return the l: scope variable. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6348 * Return NULL if there is no current funccal. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6349 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6350 dictitem_T * |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6351 get_funccal_local_var() |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6352 { |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6353 if (current_funccal == NULL || current_funccal->fc_l_vars.dv_refcount == 0) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6354 return NULL; |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6355 return &get_funccal()->fc_l_vars_var; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6356 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6357 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6358 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6359 * Return the hashtable used for argument in the current funccal. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6360 * Return NULL if there is no current funccal. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6361 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6362 hashtab_T * |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6363 get_funccal_args_ht() |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6364 { |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6365 if (current_funccal == NULL || current_funccal->fc_l_vars.dv_refcount == 0) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6366 return NULL; |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6367 return &get_funccal()->fc_l_avars.dv_hashtab; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6368 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6369 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6370 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6371 * Return the a: scope variable. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6372 * Return NULL if there is no current funccal. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6373 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6374 dictitem_T * |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6375 get_funccal_args_var() |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6376 { |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6377 if (current_funccal == NULL || current_funccal->fc_l_vars.dv_refcount == 0) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6378 return NULL; |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6379 return &get_funccal()->fc_l_avars_var; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6380 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6381 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6382 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6383 * List function variables, if there is a function. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6384 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6385 void |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6386 list_func_vars(int *first) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6387 { |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6388 if (current_funccal != NULL && current_funccal->fc_l_vars.dv_refcount > 0) |
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6389 list_hashtable_vars(¤t_funccal->fc_l_vars.dv_hashtab, |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6390 "l:", FALSE, first); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6391 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6392 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6393 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6394 * If "ht" is the hashtable for local variables in the current funccal, return |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6395 * the dict that contains it. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6396 * Otherwise return NULL. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6397 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6398 dict_T * |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6399 get_current_funccal_dict(hashtab_T *ht) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6400 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6401 if (current_funccal != NULL |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6402 && ht == ¤t_funccal->fc_l_vars.dv_hashtab) |
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6403 return ¤t_funccal->fc_l_vars; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6404 return NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6405 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6406 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6407 /* |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
6408 * Search hashitem in parent scope. |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
6409 */ |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
6410 hashitem_T * |
9731
f85d94eee05b
commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
6411 find_hi_in_scoped_ht(char_u *name, hashtab_T **pht) |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
6412 { |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
6413 funccall_T *old_current_funccal = current_funccal; |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
6414 hashtab_T *ht; |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
6415 hashitem_T *hi = NULL; |
9731
f85d94eee05b
commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
6416 char_u *varname; |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
6417 |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6418 if (current_funccal == NULL || current_funccal->fc_func->uf_scoped == NULL) |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
6419 return NULL; |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
6420 |
20433
5950284a517f
patch 8.2.0771: Vim9: cannot call a compiled closure from not compiled code
Bram Moolenaar <Bram@vim.org>
parents:
20397
diff
changeset
|
6421 // Search in parent scope, which can be referenced from a lambda. |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6422 current_funccal = current_funccal->fc_func->uf_scoped; |
9721
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
6423 while (current_funccal != NULL) |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
6424 { |
9731
f85d94eee05b
commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
6425 ht = find_var_ht(name, &varname); |
f85d94eee05b
commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
6426 if (ht != NULL && *varname != NUL) |
9721
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
6427 { |
9731
f85d94eee05b
commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
6428 hi = hash_find(ht, varname); |
9721
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
6429 if (!HASHITEM_EMPTY(hi)) |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
6430 { |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
6431 *pht = ht; |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
6432 break; |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
6433 } |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
6434 } |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6435 if (current_funccal == current_funccal->fc_func->uf_scoped) |
9721
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
6436 break; |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6437 current_funccal = current_funccal->fc_func->uf_scoped; |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
6438 } |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
6439 current_funccal = old_current_funccal; |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
6440 |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
6441 return hi; |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
6442 } |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
6443 |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
6444 /* |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6445 * Search variable in parent scope. |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6446 */ |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6447 dictitem_T * |
9731
f85d94eee05b
commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
6448 find_var_in_scoped_ht(char_u *name, int no_autoload) |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6449 { |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6450 dictitem_T *v = NULL; |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6451 funccall_T *old_current_funccal = current_funccal; |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6452 hashtab_T *ht; |
9731
f85d94eee05b
commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
6453 char_u *varname; |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6454 |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6455 if (current_funccal == NULL || current_funccal->fc_func->uf_scoped == NULL) |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6456 return NULL; |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6457 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
6458 // Search in parent scope which is possible to reference from lambda |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6459 current_funccal = current_funccal->fc_func->uf_scoped; |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6460 while (current_funccal) |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6461 { |
9731
f85d94eee05b
commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
6462 ht = find_var_ht(name, &varname); |
f85d94eee05b
commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
6463 if (ht != NULL && *varname != NUL) |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6464 { |
9731
f85d94eee05b
commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
6465 v = find_var_in_ht(ht, *name, varname, no_autoload); |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6466 if (v != NULL) |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6467 break; |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6468 } |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6469 if (current_funccal == current_funccal->fc_func->uf_scoped) |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6470 break; |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6471 current_funccal = current_funccal->fc_func->uf_scoped; |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6472 } |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6473 current_funccal = old_current_funccal; |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6474 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6475 return v; |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6476 } |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6477 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6478 /* |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6479 * Set "copyID + 1" in previous_funccal and callers. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6480 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6481 int |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6482 set_ref_in_previous_funccal(int copyID) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6483 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6484 funccall_T *fc; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6485 |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6486 for (fc = previous_funccal; fc != NULL; fc = fc->fc_caller) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6487 { |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6488 fc->fc_copyID = copyID + 1; |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6489 if (set_ref_in_ht(&fc->fc_l_vars.dv_hashtab, copyID + 1, NULL) |
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6490 || set_ref_in_ht(&fc->fc_l_avars.dv_hashtab, copyID + 1, NULL) |
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6491 || set_ref_in_list_items(&fc->fc_l_varlist, copyID + 1, NULL)) |
25104
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6492 return TRUE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6493 } |
25104
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6494 return FALSE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6495 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6496 |
9735
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6497 static int |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6498 set_ref_in_funccal(funccall_T *fc, int copyID) |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6499 { |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6500 if (fc->fc_copyID != copyID) |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6501 { |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6502 fc->fc_copyID = copyID; |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6503 if (set_ref_in_ht(&fc->fc_l_vars.dv_hashtab, copyID, NULL) |
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6504 || set_ref_in_ht(&fc->fc_l_avars.dv_hashtab, copyID, NULL) |
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6505 || set_ref_in_list_items(&fc->fc_l_varlist, copyID, NULL) |
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6506 || set_ref_in_func(NULL, fc->fc_func, copyID)) |
25104
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6507 return TRUE; |
9735
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6508 } |
25104
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6509 return FALSE; |
9735
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6510 } |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6511 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6512 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6513 * Set "copyID" in all local vars and arguments in the call stack. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6514 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6515 int |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6516 set_ref_in_call_stack(int copyID) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6517 { |
16969
8c794a694d66
patch 8.1.1485: double free when garbage_collect() is used in autocommand
Bram Moolenaar <Bram@vim.org>
parents:
16872
diff
changeset
|
6518 funccall_T *fc; |
8c794a694d66
patch 8.1.1485: double free when garbage_collect() is used in autocommand
Bram Moolenaar <Bram@vim.org>
parents:
16872
diff
changeset
|
6519 funccal_entry_T *entry; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6520 |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6521 for (fc = current_funccal; fc != NULL; fc = fc->fc_caller) |
25104
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6522 if (set_ref_in_funccal(fc, copyID)) |
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6523 return TRUE; |
16969
8c794a694d66
patch 8.1.1485: double free when garbage_collect() is used in autocommand
Bram Moolenaar <Bram@vim.org>
parents:
16872
diff
changeset
|
6524 |
8c794a694d66
patch 8.1.1485: double free when garbage_collect() is used in autocommand
Bram Moolenaar <Bram@vim.org>
parents:
16872
diff
changeset
|
6525 // Also go through the funccal_stack. |
25104
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6526 for (entry = funccal_stack; entry != NULL; entry = entry->next) |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6527 for (fc = entry->top_funccal; fc != NULL; fc = fc->fc_caller) |
25104
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6528 if (set_ref_in_funccal(fc, copyID)) |
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6529 return TRUE; |
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6530 return FALSE; |
9735
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6531 } |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6532 |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6533 /* |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6534 * Set "copyID" in all functions available by name. |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6535 */ |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6536 int |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6537 set_ref_in_functions(int copyID) |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6538 { |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6539 int todo; |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6540 hashitem_T *hi = NULL; |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6541 ufunc_T *fp; |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6542 |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6543 todo = (int)func_hashtab.ht_used; |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6544 for (hi = func_hashtab.ht_array; todo > 0 && !got_int; ++hi) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6545 { |
9735
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6546 if (!HASHITEM_EMPTY(hi)) |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6547 { |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6548 --todo; |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6549 fp = HI2UF(hi); |
25104
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6550 if (!func_name_refcount(fp->uf_name) |
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6551 && set_ref_in_func(NULL, fp, copyID)) |
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6552 return TRUE; |
9735
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6553 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6554 } |
25104
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6555 return FALSE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6556 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6557 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6558 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6559 * Set "copyID" in all function arguments. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6560 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6561 int |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6562 set_ref_in_func_args(int copyID) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6563 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6564 int i; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6565 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6566 for (i = 0; i < funcargs.ga_len; ++i) |
25104
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6567 if (set_ref_in_item(((typval_T **)funcargs.ga_data)[i], |
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6568 copyID, NULL, NULL)) |
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6569 return TRUE; |
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6570 return FALSE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6571 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6572 |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6573 /* |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6574 * Mark all lists and dicts referenced through function "name" with "copyID". |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6575 * Returns TRUE if setting references failed somehow. |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6576 */ |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6577 int |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
6578 set_ref_in_func(char_u *name, ufunc_T *fp_in, int copyID) |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6579 { |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
6580 ufunc_T *fp = fp_in; |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6581 funccall_T *fc; |
19013
dd9ab0674eec
patch 8.2.0067: ERROR_UNKNOWN clashes on some systems
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
6582 int error = FCERR_NONE; |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6583 char_u fname_buf[FLEN_FIXED + 1]; |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6584 char_u *tofree = NULL; |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6585 char_u *fname; |
9735
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6586 int abort = FALSE; |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6587 |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
6588 if (name == NULL && fp_in == NULL) |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6589 return FALSE; |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6590 |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
6591 if (fp_in == NULL) |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
6592 { |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
6593 fname = fname_trans_sid(name, fname_buf, &tofree, &error); |
27114
98a01021e465
patch 8.2.4086: "cctx" argument of find_func_even_dead() is unused
Bram Moolenaar <Bram@vim.org>
parents:
27092
diff
changeset
|
6594 fp = find_func(fname, FALSE); |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
6595 } |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6596 if (fp != NULL) |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6597 { |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30122
diff
changeset
|
6598 for (fc = fp->uf_scoped; fc != NULL; fc = fc->fc_func->uf_scoped) |
9735
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6599 abort = abort || set_ref_in_funccal(fc, copyID); |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6600 } |
20255
aac52c32a91f
patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents:
20244
diff
changeset
|
6601 |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6602 vim_free(tofree); |
9735
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6603 return abort; |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6604 } |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6605 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
6606 #endif // FEAT_EVAL |