Mercurial > vim
annotate src/vim9compile.c @ 32040:4c2973999f32
Added tag v9.0.1351 for changeset f08ee1b65dbfe56f507d23746d3dbadaea3ca4d2
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 24 Feb 2023 17:15:06 +0100 |
parents | b4e5d28b788c |
children | bea4ebf594c6 |
rev | line source |
---|---|
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2 * |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3 * VIM - Vi IMproved by Bram Moolenaar |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4 * |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5 * Do ":help uganda" in Vim to read copying and usage conditions. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6 * Do ":help credits" in Vim to see a list of people who contributed. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7 * See README.txt for an overview of the Vim source code. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
8 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
9 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
10 /* |
26662
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
11 * vim9compile.c: compiling a :def function |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
12 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
13 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
14 #define USING_FLOAT_STUFF |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
15 #include "vim.h" |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
16 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
17 #if defined(FEAT_EVAL) || defined(PROTO) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
18 |
26662
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
19 // When not generating protos this is included in proto.h |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
20 #ifdef PROTO |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
21 # include "vim9.h" |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
22 #endif |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
23 |
26662
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
24 // Functions defined with :def are stored in this growarray. |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
25 // They are never removed, so that they can be found by index. |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
26 // Deleted functions have the df_deleted flag set. |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
27 garray_T def_functions = {0, 0, sizeof(dfunc_T), 50, NULL}; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
28 |
23360
eb7d8f39363c
patch 8.2.2223: Vim9: Reloading marks a :def function as deleted
Bram Moolenaar <Bram@vim.org>
parents:
23352
diff
changeset
|
29 static void delete_def_function_contents(dfunc_T *dfunc, int mark_deleted); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
30 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
31 /* |
23171
bb7531f77529
patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents:
23156
diff
changeset
|
32 * Lookup variable "name" in the local scope and return it in "lvar". |
23557
f50ee1ae4d9b
patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents:
23553
diff
changeset
|
33 * "lvar->lv_from_outer" is incremented accordingly. |
23171
bb7531f77529
patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents:
23156
diff
changeset
|
34 * If "lvar" is NULL only check if the variable can be found. |
bb7531f77529
patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents:
23156
diff
changeset
|
35 * Return FAIL if not found. |
bb7531f77529
patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents:
23156
diff
changeset
|
36 */ |
26662
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
37 int |
23171
bb7531f77529
patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents:
23156
diff
changeset
|
38 lookup_local(char_u *name, size_t len, lvar_T *lvar, cctx_T *cctx) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
39 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
40 int idx; |
23171
bb7531f77529
patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents:
23156
diff
changeset
|
41 lvar_T *lvp; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
42 |
19392
5b6f420e7352
patch 8.2.0254: compiler warning for checking size_t to be negative
Bram Moolenaar <Bram@vim.org>
parents:
19388
diff
changeset
|
43 if (len == 0) |
23171
bb7531f77529
patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents:
23156
diff
changeset
|
44 return FAIL; |
20244
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
45 |
31692
2f1af1b2f82d
patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
46 if (((len == 4 && STRNCMP(name, "this", 4) == 0) |
2f1af1b2f82d
patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
47 || (len == 5 && STRNCMP(name, "super", 5) == 0)) |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
48 && cctx->ctx_ufunc != NULL |
31616
0eb51cec2154
patch 9.0.1140: cannot call an object method in a compiled function
Bram Moolenaar <Bram@vim.org>
parents:
31602
diff
changeset
|
49 && (cctx->ctx_ufunc->uf_flags & (FC_OBJECT|FC_NEW))) |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
50 { |
31692
2f1af1b2f82d
patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
51 int is_super = *name == 's'; |
31694
2f61e308b997
patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents:
31692
diff
changeset
|
52 if (is_super) |
2f61e308b997
patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents:
31692
diff
changeset
|
53 { |
2f61e308b997
patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents:
31692
diff
changeset
|
54 if (name[5] != '.') |
2f61e308b997
patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents:
31692
diff
changeset
|
55 { |
2f61e308b997
patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents:
31692
diff
changeset
|
56 emsg(_(e_super_must_be_followed_by_dot)); |
2f61e308b997
patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents:
31692
diff
changeset
|
57 return FAIL; |
2f61e308b997
patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents:
31692
diff
changeset
|
58 } |
2f61e308b997
patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents:
31692
diff
changeset
|
59 if (cctx->ctx_ufunc->uf_class != NULL |
2f61e308b997
patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents:
31692
diff
changeset
|
60 && cctx->ctx_ufunc->uf_class->class_extends == NULL) |
2f61e308b997
patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents:
31692
diff
changeset
|
61 { |
2f61e308b997
patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents:
31692
diff
changeset
|
62 emsg(_(e_using_super_not_in_child_class)); |
2f61e308b997
patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents:
31692
diff
changeset
|
63 return FAIL; |
2f61e308b997
patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents:
31692
diff
changeset
|
64 } |
2f61e308b997
patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents:
31692
diff
changeset
|
65 } |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
66 if (lvar != NULL) |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
67 { |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
68 CLEAR_POINTER(lvar); |
31770
8d2bfc85e3c5
patch 9.0.1217: using an object member in a closure doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
31758
diff
changeset
|
69 lvar->lv_loop_depth = -1; |
31692
2f1af1b2f82d
patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
70 lvar->lv_name = (char_u *)(is_super ? "super" : "this"); |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
71 if (cctx->ctx_ufunc->uf_class != NULL) |
31692
2f1af1b2f82d
patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
72 { |
31416
f088f1d97eee
patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
73 lvar->lv_type = &cctx->ctx_ufunc->uf_class->class_object_type; |
31692
2f1af1b2f82d
patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
74 if (is_super) |
2f1af1b2f82d
patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
75 { |
2f1af1b2f82d
patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
76 type_T *type = get_type_ptr(cctx->ctx_type_list); |
2f1af1b2f82d
patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
77 |
2f1af1b2f82d
patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
78 if (type != NULL) |
2f1af1b2f82d
patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
79 { |
2f1af1b2f82d
patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
80 *type = *lvar->lv_type; |
2f1af1b2f82d
patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
81 lvar->lv_type = type; |
2f1af1b2f82d
patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
82 type->tt_flags |= TTFLAG_SUPER; |
2f1af1b2f82d
patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
83 } |
2f1af1b2f82d
patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
84 } |
2f1af1b2f82d
patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents:
31635
diff
changeset
|
85 } |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
86 } |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
87 return OK; |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
88 } |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
89 |
20244
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
90 // Find local in current function scope. |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
91 for (idx = 0; idx < cctx->ctx_locals.ga_len; ++idx) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
92 { |
23171
bb7531f77529
patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents:
23156
diff
changeset
|
93 lvp = ((lvar_T *)cctx->ctx_locals.ga_data) + idx; |
30779
9d2c4d49b006
patch 9.0.0724: closure in compiled function gets same variable in block
Bram Moolenaar <Bram@vim.org>
parents:
30709
diff
changeset
|
94 if (lvp->lv_name != NULL |
9d2c4d49b006
patch 9.0.0724: closure in compiled function gets same variable in block
Bram Moolenaar <Bram@vim.org>
parents:
30709
diff
changeset
|
95 && STRNCMP(name, lvp->lv_name, len) == 0 |
23171
bb7531f77529
patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents:
23156
diff
changeset
|
96 && STRLEN(lvp->lv_name) == len) |
bb7531f77529
patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents:
23156
diff
changeset
|
97 { |
bb7531f77529
patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents:
23156
diff
changeset
|
98 if (lvar != NULL) |
bb7531f77529
patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents:
23156
diff
changeset
|
99 { |
bb7531f77529
patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents:
23156
diff
changeset
|
100 *lvar = *lvp; |
23557
f50ee1ae4d9b
patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents:
23553
diff
changeset
|
101 lvar->lv_from_outer = 0; |
30335
bff0506a0911
patch 9.0.0503: build failure
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
102 // If the variable was declared inside a loop set |
bff0506a0911
patch 9.0.0503: build failure
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
103 // lvar->lv_loop_idx and lvar->lv_loop_depth. |
bff0506a0911
patch 9.0.0503: build failure
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
104 get_loop_var_idx(cctx, idx, lvar); |
23171
bb7531f77529
patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents:
23156
diff
changeset
|
105 } |
bb7531f77529
patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents:
23156
diff
changeset
|
106 return OK; |
20244
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
107 } |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
108 } |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
109 |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
110 // Find local in outer function scope. |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
111 if (cctx->ctx_outer != NULL) |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
112 { |
23171
bb7531f77529
patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents:
23156
diff
changeset
|
113 if (lookup_local(name, len, lvar, cctx->ctx_outer) == OK) |
bb7531f77529
patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents:
23156
diff
changeset
|
114 { |
bb7531f77529
patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents:
23156
diff
changeset
|
115 if (lvar != NULL) |
bb7531f77529
patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents:
23156
diff
changeset
|
116 { |
bb7531f77529
patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents:
23156
diff
changeset
|
117 cctx->ctx_outer_used = TRUE; |
23557
f50ee1ae4d9b
patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents:
23553
diff
changeset
|
118 ++lvar->lv_from_outer; |
23171
bb7531f77529
patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents:
23156
diff
changeset
|
119 } |
bb7531f77529
patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents:
23156
diff
changeset
|
120 return OK; |
bb7531f77529
patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents:
23156
diff
changeset
|
121 } |
bb7531f77529
patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents:
23156
diff
changeset
|
122 } |
bb7531f77529
patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents:
23156
diff
changeset
|
123 |
bb7531f77529
patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents:
23156
diff
changeset
|
124 return FAIL; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
125 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
126 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
127 /* |
20275
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
128 * Lookup an argument in the current function and an enclosing function. |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
129 * Returns the argument index in "idxp" |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
130 * Returns the argument type in "type" |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
131 * Sets "gen_load_outer" to TRUE if found in outer scope. |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
132 * Returns OK when found, FAIL otherwise. |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
133 */ |
26662
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
134 int |
22596
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
135 arg_exists( |
20275
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
136 char_u *name, |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
137 size_t len, |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
138 int *idxp, |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
139 type_T **type, |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
140 int *gen_load_outer, |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
141 cctx_T *cctx) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
142 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
143 int idx; |
20275
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
144 char_u *va_name; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
145 |
19392
5b6f420e7352
patch 8.2.0254: compiler warning for checking size_t to be negative
Bram Moolenaar <Bram@vim.org>
parents:
19388
diff
changeset
|
146 if (len == 0) |
20275
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
147 return FAIL; |
25108
de29f9a76233
patch 8.2.3091: Vim9: default argument expr. cannot use previous argument
Bram Moolenaar <Bram@vim.org>
parents:
25098
diff
changeset
|
148 for (idx = 0; idx < cctx->ctx_ufunc->uf_args_visible; ++idx) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
149 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
150 char_u *arg = FUNCARG(cctx->ctx_ufunc, idx); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
151 |
20275
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
152 if (STRNCMP(name, arg, len) == 0 && arg[len] == NUL) |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
153 { |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
154 if (idxp != NULL) |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
155 { |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
156 // Arguments are located above the frame pointer. One further |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
157 // if there is a vararg argument |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
158 *idxp = idx - (cctx->ctx_ufunc->uf_args.ga_len |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
159 + STACK_FRAME_SIZE) |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
160 + (cctx->ctx_ufunc->uf_va_name != NULL ? -1 : 0); |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
161 |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
162 if (cctx->ctx_ufunc->uf_arg_types != NULL) |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
163 *type = cctx->ctx_ufunc->uf_arg_types[idx]; |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
164 else |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
165 *type = &t_any; |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
166 } |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
167 return OK; |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
168 } |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
169 } |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
170 |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
171 va_name = cctx->ctx_ufunc->uf_va_name; |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
172 if (va_name != NULL |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
173 && STRNCMP(name, va_name, len) == 0 && va_name[len] == NUL) |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
174 { |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
175 if (idxp != NULL) |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
176 { |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
177 // varargs is always the last argument |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
178 *idxp = -STACK_FRAME_SIZE - 1; |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
179 *type = cctx->ctx_ufunc->uf_va_type; |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
180 } |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
181 return OK; |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
182 } |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
183 |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
184 if (cctx->ctx_outer != NULL) |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
185 { |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
186 // Lookup the name for an argument of the outer function. |
22596
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
187 if (arg_exists(name, len, idxp, type, gen_load_outer, cctx->ctx_outer) |
20275
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
188 == OK) |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
189 { |
23923
be36288235af
patch 8.2.2504: Vim9: crash when using an argument from a closure
Bram Moolenaar <Bram@vim.org>
parents:
23917
diff
changeset
|
190 if (gen_load_outer != NULL) |
be36288235af
patch 8.2.2504: Vim9: crash when using an argument from a closure
Bram Moolenaar <Bram@vim.org>
parents:
23917
diff
changeset
|
191 ++*gen_load_outer; |
20275
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
192 return OK; |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
193 } |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
194 } |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
195 |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
196 return FAIL; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
197 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
198 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
199 /* |
22596
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
200 * Lookup a script-local variable in the current script, possibly defined in a |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
201 * block that contains the function "cctx->ctx_ufunc". |
27714
072c7ae27b06
patch 8.2.4383: Vim9: unused code lines
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
202 * "cctx" is NULL at the script level, "cstack" is NULL in a function. |
24061
d6489b4eb14e
patch 8.2.2572: Vim9: crash when getting the types for a legacy function
Bram Moolenaar <Bram@vim.org>
parents:
24033
diff
changeset
|
203 * If "len" is <= 0 "name" must be NUL terminated. |
22596
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
204 * Return NULL when not found. |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
205 */ |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
206 static sallvar_T * |
27611
e311a80f8cbe
patch 8.2.4332: Vim9: incomplete test for existing script variable in block
Bram Moolenaar <Bram@vim.org>
parents:
27595
diff
changeset
|
207 find_script_var(char_u *name, size_t len, cctx_T *cctx, cstack_T *cstack) |
22596
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
208 { |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
209 scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid); |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
210 hashitem_T *hi; |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
211 int cc; |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
212 sallvar_T *sav; |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
213 ufunc_T *ufunc; |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
214 |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
215 // Find the list of all script variables with the right name. |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
216 if (len > 0) |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
217 { |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
218 cc = name[len]; |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
219 name[len] = NUL; |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
220 } |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
221 hi = hash_find(&si->sn_all_vars.dv_hashtab, name); |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
222 if (len > 0) |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
223 name[len] = cc; |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
224 if (HASHITEM_EMPTY(hi)) |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
225 return NULL; |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
226 |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
227 sav = HI2SAV(hi); |
25370
d52504ef26ed
patch 8.2.3222: Vim9: cannot used loop variable later as lambda argument
Bram Moolenaar <Bram@vim.org>
parents:
25346
diff
changeset
|
228 if (sav->sav_block_id == 0) |
d52504ef26ed
patch 8.2.3222: Vim9: cannot used loop variable later as lambda argument
Bram Moolenaar <Bram@vim.org>
parents:
25346
diff
changeset
|
229 // variable defined in the top script scope is always visible |
22596
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
230 return sav; |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
231 |
25370
d52504ef26ed
patch 8.2.3222: Vim9: cannot used loop variable later as lambda argument
Bram Moolenaar <Bram@vim.org>
parents:
25346
diff
changeset
|
232 if (cctx == NULL) |
d52504ef26ed
patch 8.2.3222: Vim9: cannot used loop variable later as lambda argument
Bram Moolenaar <Bram@vim.org>
parents:
25346
diff
changeset
|
233 { |
30249
c0f0118b6790
patch 9.0.0460: loop variable can't be found
Bram Moolenaar <Bram@vim.org>
parents:
30065
diff
changeset
|
234 if (cstack == NULL) |
c0f0118b6790
patch 9.0.0460: loop variable can't be found
Bram Moolenaar <Bram@vim.org>
parents:
30065
diff
changeset
|
235 return NULL; |
c0f0118b6790
patch 9.0.0460: loop variable can't be found
Bram Moolenaar <Bram@vim.org>
parents:
30065
diff
changeset
|
236 |
27611
e311a80f8cbe
patch 8.2.4332: Vim9: incomplete test for existing script variable in block
Bram Moolenaar <Bram@vim.org>
parents:
27595
diff
changeset
|
237 // Not in a function scope, find variable with block ID equal to or |
27714
072c7ae27b06
patch 8.2.4383: Vim9: unused code lines
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
238 // smaller than the current block id. Use "cstack" to go up the block |
072c7ae27b06
patch 8.2.4383: Vim9: unused code lines
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
239 // scopes. |
25370
d52504ef26ed
patch 8.2.3222: Vim9: cannot used loop variable later as lambda argument
Bram Moolenaar <Bram@vim.org>
parents:
25346
diff
changeset
|
240 while (sav != NULL) |
d52504ef26ed
patch 8.2.3222: Vim9: cannot used loop variable later as lambda argument
Bram Moolenaar <Bram@vim.org>
parents:
25346
diff
changeset
|
241 { |
27714
072c7ae27b06
patch 8.2.4383: Vim9: unused code lines
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
242 int idx; |
072c7ae27b06
patch 8.2.4383: Vim9: unused code lines
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
243 |
072c7ae27b06
patch 8.2.4383: Vim9: unused code lines
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
244 for (idx = cstack->cs_idx; idx >= 0; --idx) |
072c7ae27b06
patch 8.2.4383: Vim9: unused code lines
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
245 if (cstack->cs_block_id[idx] == sav->sav_block_id) |
27611
e311a80f8cbe
patch 8.2.4332: Vim9: incomplete test for existing script variable in block
Bram Moolenaar <Bram@vim.org>
parents:
27595
diff
changeset
|
246 break; |
27714
072c7ae27b06
patch 8.2.4383: Vim9: unused code lines
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
247 if (idx >= 0) |
25370
d52504ef26ed
patch 8.2.3222: Vim9: cannot used loop variable later as lambda argument
Bram Moolenaar <Bram@vim.org>
parents:
25346
diff
changeset
|
248 break; |
d52504ef26ed
patch 8.2.3222: Vim9: cannot used loop variable later as lambda argument
Bram Moolenaar <Bram@vim.org>
parents:
25346
diff
changeset
|
249 sav = sav->sav_next; |
d52504ef26ed
patch 8.2.3222: Vim9: cannot used loop variable later as lambda argument
Bram Moolenaar <Bram@vim.org>
parents:
25346
diff
changeset
|
250 } |
d52504ef26ed
patch 8.2.3222: Vim9: cannot used loop variable later as lambda argument
Bram Moolenaar <Bram@vim.org>
parents:
25346
diff
changeset
|
251 return sav; |
d52504ef26ed
patch 8.2.3222: Vim9: cannot used loop variable later as lambda argument
Bram Moolenaar <Bram@vim.org>
parents:
25346
diff
changeset
|
252 } |
d52504ef26ed
patch 8.2.3222: Vim9: cannot used loop variable later as lambda argument
Bram Moolenaar <Bram@vim.org>
parents:
25346
diff
changeset
|
253 |
22596
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
254 // Go over the variables with this name and find one that was visible |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
255 // from the function. |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
256 ufunc = cctx->ctx_ufunc; |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
257 while (sav != NULL) |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
258 { |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
259 int idx; |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
260 |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
261 // Go over the blocks that this function was defined in. If the |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
262 // variable block ID matches it was visible to the function. |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
263 for (idx = 0; idx < ufunc->uf_block_depth; ++idx) |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
264 if (ufunc->uf_block_ids[idx] == sav->sav_block_id) |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
265 return sav; |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
266 sav = sav->sav_next; |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
267 } |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
268 |
26974
fceb494e22de
patch 8.2.4016: Vim9: incorrect error for argument that is shadowing var
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
269 // Not found, variable was not visible. |
fceb494e22de
patch 8.2.4016: Vim9: incorrect error for argument that is shadowing var
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
270 return NULL; |
22596
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
271 } |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
272 |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
273 /* |
30249
c0f0118b6790
patch 9.0.0460: loop variable can't be found
Bram Moolenaar <Bram@vim.org>
parents:
30065
diff
changeset
|
274 * If "name" can be found in the current script set it's "block_id". |
c0f0118b6790
patch 9.0.0460: loop variable can't be found
Bram Moolenaar <Bram@vim.org>
parents:
30065
diff
changeset
|
275 */ |
c0f0118b6790
patch 9.0.0460: loop variable can't be found
Bram Moolenaar <Bram@vim.org>
parents:
30065
diff
changeset
|
276 void |
c0f0118b6790
patch 9.0.0460: loop variable can't be found
Bram Moolenaar <Bram@vim.org>
parents:
30065
diff
changeset
|
277 update_script_var_block_id(char_u *name, int block_id) |
c0f0118b6790
patch 9.0.0460: loop variable can't be found
Bram Moolenaar <Bram@vim.org>
parents:
30065
diff
changeset
|
278 { |
c0f0118b6790
patch 9.0.0460: loop variable can't be found
Bram Moolenaar <Bram@vim.org>
parents:
30065
diff
changeset
|
279 scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid); |
c0f0118b6790
patch 9.0.0460: loop variable can't be found
Bram Moolenaar <Bram@vim.org>
parents:
30065
diff
changeset
|
280 hashitem_T *hi; |
c0f0118b6790
patch 9.0.0460: loop variable can't be found
Bram Moolenaar <Bram@vim.org>
parents:
30065
diff
changeset
|
281 sallvar_T *sav; |
c0f0118b6790
patch 9.0.0460: loop variable can't be found
Bram Moolenaar <Bram@vim.org>
parents:
30065
diff
changeset
|
282 |
c0f0118b6790
patch 9.0.0460: loop variable can't be found
Bram Moolenaar <Bram@vim.org>
parents:
30065
diff
changeset
|
283 hi = hash_find(&si->sn_all_vars.dv_hashtab, name); |
c0f0118b6790
patch 9.0.0460: loop variable can't be found
Bram Moolenaar <Bram@vim.org>
parents:
30065
diff
changeset
|
284 if (HASHITEM_EMPTY(hi)) |
c0f0118b6790
patch 9.0.0460: loop variable can't be found
Bram Moolenaar <Bram@vim.org>
parents:
30065
diff
changeset
|
285 return; |
c0f0118b6790
patch 9.0.0460: loop variable can't be found
Bram Moolenaar <Bram@vim.org>
parents:
30065
diff
changeset
|
286 sav = HI2SAV(hi); |
c0f0118b6790
patch 9.0.0460: loop variable can't be found
Bram Moolenaar <Bram@vim.org>
parents:
30065
diff
changeset
|
287 sav->sav_block_id = block_id; |
c0f0118b6790
patch 9.0.0460: loop variable can't be found
Bram Moolenaar <Bram@vim.org>
parents:
30065
diff
changeset
|
288 } |
c0f0118b6790
patch 9.0.0460: loop variable can't be found
Bram Moolenaar <Bram@vim.org>
parents:
30065
diff
changeset
|
289 |
c0f0118b6790
patch 9.0.0460: loop variable can't be found
Bram Moolenaar <Bram@vim.org>
parents:
30065
diff
changeset
|
290 /* |
23229
b545334ae654
patch 8.2.2160: various typos
Bram Moolenaar <Bram@vim.org>
parents:
23199
diff
changeset
|
291 * Return TRUE if the script context is Vim9 script. |
21931
8e09827f8bac
patch 8.2.1515: Vim9: can create s:var in legacy script but cannot unlet
Bram Moolenaar <Bram@vim.org>
parents:
21921
diff
changeset
|
292 */ |
26662
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
293 int |
32009
4545f58c8490
patch 9.0.1336: functions without arguments are not always declared properly
Bram Moolenaar <Bram@vim.org>
parents:
32005
diff
changeset
|
294 script_is_vim9(void) |
21931
8e09827f8bac
patch 8.2.1515: Vim9: can create s:var in legacy script but cannot unlet
Bram Moolenaar <Bram@vim.org>
parents:
21921
diff
changeset
|
295 { |
8e09827f8bac
patch 8.2.1515: Vim9: can create s:var in legacy script but cannot unlet
Bram Moolenaar <Bram@vim.org>
parents:
21921
diff
changeset
|
296 return SCRIPT_ITEM(current_sctx.sc_sid)->sn_version == SCRIPT_VERSION_VIM9; |
8e09827f8bac
patch 8.2.1515: Vim9: can create s:var in legacy script but cannot unlet
Bram Moolenaar <Bram@vim.org>
parents:
21921
diff
changeset
|
297 } |
8e09827f8bac
patch 8.2.1515: Vim9: can create s:var in legacy script but cannot unlet
Bram Moolenaar <Bram@vim.org>
parents:
21921
diff
changeset
|
298 |
8e09827f8bac
patch 8.2.1515: Vim9: can create s:var in legacy script but cannot unlet
Bram Moolenaar <Bram@vim.org>
parents:
21921
diff
changeset
|
299 /* |
22596
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
300 * Lookup a variable (without s: prefix) in the current script. |
27714
072c7ae27b06
patch 8.2.4383: Vim9: unused code lines
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
301 * "cctx" is NULL at the script level, "cstack" is NULL in a function. |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
302 * Returns OK or FAIL. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
303 */ |
26662
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
304 int |
27611
e311a80f8cbe
patch 8.2.4332: Vim9: incomplete test for existing script variable in block
Bram Moolenaar <Bram@vim.org>
parents:
27595
diff
changeset
|
305 script_var_exists(char_u *name, size_t len, cctx_T *cctx, cstack_T *cstack) |
24388
72f3e40f046c
patch 8.2.2734: Vim9: cannot use legacy script-local var from :def function
Bram Moolenaar <Bram@vim.org>
parents:
24379
diff
changeset
|
306 { |
22381
6fe9536694ff
patch 8.2.1739: Vim9: crash when compiling a manually defined function
Bram Moolenaar <Bram@vim.org>
parents:
22371
diff
changeset
|
307 if (current_sctx.sc_sid <= 0) |
6fe9536694ff
patch 8.2.1739: Vim9: crash when compiling a manually defined function
Bram Moolenaar <Bram@vim.org>
parents:
22371
diff
changeset
|
308 return FAIL; |
24388
72f3e40f046c
patch 8.2.2734: Vim9: cannot use legacy script-local var from :def function
Bram Moolenaar <Bram@vim.org>
parents:
24379
diff
changeset
|
309 if (script_is_vim9()) |
22596
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
310 { |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
311 // Check script variables that were visible where the function was |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
312 // defined. |
27611
e311a80f8cbe
patch 8.2.4332: Vim9: incomplete test for existing script variable in block
Bram Moolenaar <Bram@vim.org>
parents:
27595
diff
changeset
|
313 if (find_script_var(name, len, cctx, cstack) != NULL) |
22596
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
314 return OK; |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
315 } |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
316 else |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
317 { |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
318 hashtab_T *ht = &SCRIPT_VARS(current_sctx.sc_sid); |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
319 dictitem_T *di; |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
320 int cc; |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
321 |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
322 // Check script variables that are currently visible |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
323 cc = name[len]; |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
324 name[len] = NUL; |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
325 di = find_var_in_ht(ht, 0, name, TRUE); |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
326 name[len] = cc; |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
327 if (di != NULL) |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
328 return OK; |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
329 } |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
330 |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
331 return FAIL; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
332 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
333 |
19623
2fee087c94cb
patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents:
19597
diff
changeset
|
334 /* |
23966
09bde146adcb
patch 8.2.2525: Vim9: only local variables checked for a name
Bram Moolenaar <Bram@vim.org>
parents:
23948
diff
changeset
|
335 * Return TRUE if "name" is a local variable, argument, script variable or |
32005
ef644af2c330
patch 9.0.1334: using tt_member for the class leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents:
31980
diff
changeset
|
336 * imported. Also if "name" is "this" and in a class method. |
23966
09bde146adcb
patch 8.2.2525: Vim9: only local variables checked for a name
Bram Moolenaar <Bram@vim.org>
parents:
23948
diff
changeset
|
337 */ |
09bde146adcb
patch 8.2.2525: Vim9: only local variables checked for a name
Bram Moolenaar <Bram@vim.org>
parents:
23948
diff
changeset
|
338 static int |
09bde146adcb
patch 8.2.2525: Vim9: only local variables checked for a name
Bram Moolenaar <Bram@vim.org>
parents:
23948
diff
changeset
|
339 variable_exists(char_u *name, size_t len, cctx_T *cctx) |
09bde146adcb
patch 8.2.2525: Vim9: only local variables checked for a name
Bram Moolenaar <Bram@vim.org>
parents:
23948
diff
changeset
|
340 { |
24033
308d29307910
patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents:
23996
diff
changeset
|
341 return (cctx != NULL |
308d29307910
patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents:
23996
diff
changeset
|
342 && (lookup_local(name, len, NULL, cctx) == OK |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
343 || arg_exists(name, len, NULL, NULL, NULL, cctx) == OK |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
344 || (len == 4 |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
345 && cctx->ctx_ufunc != NULL |
31616
0eb51cec2154
patch 9.0.1140: cannot call an object method in a compiled function
Bram Moolenaar <Bram@vim.org>
parents:
31602
diff
changeset
|
346 && (cctx->ctx_ufunc->uf_flags & (FC_OBJECT|FC_NEW)) |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
347 && STRNCMP(name, "this", 4) == 0))) |
27611
e311a80f8cbe
patch 8.2.4332: Vim9: incomplete test for existing script variable in block
Bram Moolenaar <Bram@vim.org>
parents:
27595
diff
changeset
|
348 || script_var_exists(name, len, cctx, NULL) == OK |
31590
aee868b9229a
patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents:
31551
diff
changeset
|
349 || class_member_index(name, len, NULL, cctx) >= 0 |
27698
3813036f19cb
patch 8.2.4375: ctx_imports is not used
Bram Moolenaar <Bram@vim.org>
parents:
27696
diff
changeset
|
350 || find_imported(name, len, FALSE) != NULL; |
23966
09bde146adcb
patch 8.2.2525: Vim9: only local variables checked for a name
Bram Moolenaar <Bram@vim.org>
parents:
23948
diff
changeset
|
351 } |
09bde146adcb
patch 8.2.2525: Vim9: only local variables checked for a name
Bram Moolenaar <Bram@vim.org>
parents:
23948
diff
changeset
|
352 |
09bde146adcb
patch 8.2.2525: Vim9: only local variables checked for a name
Bram Moolenaar <Bram@vim.org>
parents:
23948
diff
changeset
|
353 /* |
24067
780dec2ffa6b
patch 8.2.2575: Vim9: a function name with "->" in the next line doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24061
diff
changeset
|
354 * Return TRUE if "name" is a local variable, argument, script variable, |
28281
bd1dcc605e58
patch 8.2.4666: Vim9: assignment not recognized in skipped block
Bram Moolenaar <Bram@vim.org>
parents:
28217
diff
changeset
|
355 * imported or function. Or commands are being skipped, a declaration may have |
bd1dcc605e58
patch 8.2.4666: Vim9: assignment not recognized in skipped block
Bram Moolenaar <Bram@vim.org>
parents:
28217
diff
changeset
|
356 * been skipped then. |
24067
780dec2ffa6b
patch 8.2.2575: Vim9: a function name with "->" in the next line doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24061
diff
changeset
|
357 */ |
780dec2ffa6b
patch 8.2.2575: Vim9: a function name with "->" in the next line doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24061
diff
changeset
|
358 static int |
24124
f4061617c438
patch 8.2.2603: Vim9: no effect if user command is also a function
Bram Moolenaar <Bram@vim.org>
parents:
24116
diff
changeset
|
359 item_exists(char_u *name, size_t len, int cmd UNUSED, cctx_T *cctx) |
24067
780dec2ffa6b
patch 8.2.2575: Vim9: a function name with "->" in the next line doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24061
diff
changeset
|
360 { |
27696
78d4f843521a
patch 8.2.4374: unreachable code
Bram Moolenaar <Bram@vim.org>
parents:
27669
diff
changeset
|
361 return variable_exists(name, len, cctx); |
24067
780dec2ffa6b
patch 8.2.2575: Vim9: a function name with "->" in the next line doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24061
diff
changeset
|
362 } |
780dec2ffa6b
patch 8.2.2575: Vim9: a function name with "->" in the next line doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24061
diff
changeset
|
363 |
780dec2ffa6b
patch 8.2.2575: Vim9: a function name with "->" in the next line doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24061
diff
changeset
|
364 /* |
19623
2fee087c94cb
patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents:
19597
diff
changeset
|
365 * Check if "p[len]" is already defined, either in script "import_sid" or in |
27714
072c7ae27b06
patch 8.2.4383: Vim9: unused code lines
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
366 * compilation context "cctx". |
072c7ae27b06
patch 8.2.4383: Vim9: unused code lines
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
367 * "cctx" is NULL at the script level, "cstack" is NULL in a function. |
22236
3d0632b260fd
patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents:
22216
diff
changeset
|
368 * Does not check the global namespace. |
24033
308d29307910
patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents:
23996
diff
changeset
|
369 * If "is_arg" is TRUE the error message is for an argument name. |
19623
2fee087c94cb
patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents:
19597
diff
changeset
|
370 * Return FAIL and give an error if it defined. |
2fee087c94cb
patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents:
19597
diff
changeset
|
371 */ |
2fee087c94cb
patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents:
19597
diff
changeset
|
372 int |
27611
e311a80f8cbe
patch 8.2.4332: Vim9: incomplete test for existing script variable in block
Bram Moolenaar <Bram@vim.org>
parents:
27595
diff
changeset
|
373 check_defined( |
e311a80f8cbe
patch 8.2.4332: Vim9: incomplete test for existing script variable in block
Bram Moolenaar <Bram@vim.org>
parents:
27595
diff
changeset
|
374 char_u *p, |
e311a80f8cbe
patch 8.2.4332: Vim9: incomplete test for existing script variable in block
Bram Moolenaar <Bram@vim.org>
parents:
27595
diff
changeset
|
375 size_t len, |
e311a80f8cbe
patch 8.2.4332: Vim9: incomplete test for existing script variable in block
Bram Moolenaar <Bram@vim.org>
parents:
27595
diff
changeset
|
376 cctx_T *cctx, |
e311a80f8cbe
patch 8.2.4332: Vim9: incomplete test for existing script variable in block
Bram Moolenaar <Bram@vim.org>
parents:
27595
diff
changeset
|
377 cstack_T *cstack, |
e311a80f8cbe
patch 8.2.4332: Vim9: incomplete test for existing script variable in block
Bram Moolenaar <Bram@vim.org>
parents:
27595
diff
changeset
|
378 int is_arg) |
19623
2fee087c94cb
patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents:
19597
diff
changeset
|
379 { |
22236
3d0632b260fd
patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents:
22216
diff
changeset
|
380 int c = p[len]; |
3d0632b260fd
patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents:
22216
diff
changeset
|
381 ufunc_T *ufunc = NULL; |
21604
d9c45474cac1
patch 8.2.1352: Vim9: no error for shadowing a script-local function
Bram Moolenaar <Bram@vim.org>
parents:
21602
diff
changeset
|
382 |
24420
e0fa539a9b34
patch 8.2.2750: Vim9: error for using underscore in nested function
Bram Moolenaar <Bram@vim.org>
parents:
24408
diff
changeset
|
383 // underscore argument is OK |
e0fa539a9b34
patch 8.2.2750: Vim9: error for using underscore in nested function
Bram Moolenaar <Bram@vim.org>
parents:
24408
diff
changeset
|
384 if (len == 1 && *p == '_') |
e0fa539a9b34
patch 8.2.2750: Vim9: error for using underscore in nested function
Bram Moolenaar <Bram@vim.org>
parents:
24408
diff
changeset
|
385 return OK; |
e0fa539a9b34
patch 8.2.2750: Vim9: error for using underscore in nested function
Bram Moolenaar <Bram@vim.org>
parents:
24408
diff
changeset
|
386 |
27611
e311a80f8cbe
patch 8.2.4332: Vim9: incomplete test for existing script variable in block
Bram Moolenaar <Bram@vim.org>
parents:
27595
diff
changeset
|
387 if (script_var_exists(p, len, cctx, cstack) == OK) |
24033
308d29307910
patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents:
23996
diff
changeset
|
388 { |
308d29307910
patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents:
23996
diff
changeset
|
389 if (is_arg) |
308d29307910
patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents:
23996
diff
changeset
|
390 semsg(_(e_argument_already_declared_in_script_str), p); |
308d29307910
patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents:
23996
diff
changeset
|
391 else |
308d29307910
patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents:
23996
diff
changeset
|
392 semsg(_(e_variable_already_declared_in_script_str), p); |
308d29307910
patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents:
23996
diff
changeset
|
393 return FAIL; |
308d29307910
patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents:
23996
diff
changeset
|
394 } |
308d29307910
patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents:
23996
diff
changeset
|
395 |
31590
aee868b9229a
patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents:
31551
diff
changeset
|
396 if (class_member_index(p, len, NULL, cctx) >= 0) |
aee868b9229a
patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents:
31551
diff
changeset
|
397 { |
aee868b9229a
patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents:
31551
diff
changeset
|
398 if (is_arg) |
aee868b9229a
patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents:
31551
diff
changeset
|
399 semsg(_(e_argument_already_declared_in_class_str), p); |
aee868b9229a
patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents:
31551
diff
changeset
|
400 else |
aee868b9229a
patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents:
31551
diff
changeset
|
401 semsg(_(e_variable_already_declared_in_class_str), p); |
aee868b9229a
patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents:
31551
diff
changeset
|
402 return FAIL; |
aee868b9229a
patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents:
31551
diff
changeset
|
403 } |
aee868b9229a
patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents:
31551
diff
changeset
|
404 |
21604
d9c45474cac1
patch 8.2.1352: Vim9: no error for shadowing a script-local function
Bram Moolenaar <Bram@vim.org>
parents:
21602
diff
changeset
|
405 p[len] = NUL; |
24033
308d29307910
patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents:
23996
diff
changeset
|
406 if ((cctx != NULL |
23171
bb7531f77529
patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents:
23156
diff
changeset
|
407 && (lookup_local(p, len, NULL, cctx) == OK |
22596
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
408 || arg_exists(p, len, NULL, NULL, NULL, cctx) == OK)) |
27698
3813036f19cb
patch 8.2.4375: ctx_imports is not used
Bram Moolenaar <Bram@vim.org>
parents:
27696
diff
changeset
|
409 || find_imported(p, len, FALSE) != NULL |
27348
9a9c34c84cd4
patch 8.2.4202: Vim9: cannot export function that exists globally
Bram Moolenaar <Bram@vim.org>
parents:
27297
diff
changeset
|
410 || (ufunc = find_func_even_dead(p, 0)) != NULL) |
22236
3d0632b260fd
patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents:
22216
diff
changeset
|
411 { |
3d0632b260fd
patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents:
22216
diff
changeset
|
412 // A local or script-local function can shadow a global function. |
25057
ffc3e1164652
patch 8.2.3065: Vim9: error when sourcing script twice and reusing function
Bram Moolenaar <Bram@vim.org>
parents:
25034
diff
changeset
|
413 if (ufunc == NULL || ((ufunc->uf_flags & FC_DEAD) == 0 |
ffc3e1164652
patch 8.2.3065: Vim9: error when sourcing script twice and reusing function
Bram Moolenaar <Bram@vim.org>
parents:
25034
diff
changeset
|
414 && (!func_is_global(ufunc) |
ffc3e1164652
patch 8.2.3065: Vim9: error when sourcing script twice and reusing function
Bram Moolenaar <Bram@vim.org>
parents:
25034
diff
changeset
|
415 || (p[0] == 'g' && p[1] == ':')))) |
22236
3d0632b260fd
patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents:
22216
diff
changeset
|
416 { |
24033
308d29307910
patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents:
23996
diff
changeset
|
417 if (is_arg) |
308d29307910
patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents:
23996
diff
changeset
|
418 semsg(_(e_argument_name_shadows_existing_variable_str), p); |
308d29307910
patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents:
23996
diff
changeset
|
419 else |
308d29307910
patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents:
23996
diff
changeset
|
420 semsg(_(e_name_already_defined_str), p); |
22236
3d0632b260fd
patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents:
22216
diff
changeset
|
421 p[len] = c; |
3d0632b260fd
patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents:
22216
diff
changeset
|
422 return FAIL; |
3d0632b260fd
patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents:
22216
diff
changeset
|
423 } |
19623
2fee087c94cb
patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents:
19597
diff
changeset
|
424 } |
21604
d9c45474cac1
patch 8.2.1352: Vim9: no error for shadowing a script-local function
Bram Moolenaar <Bram@vim.org>
parents:
21602
diff
changeset
|
425 p[len] = c; |
19623
2fee087c94cb
patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents:
19597
diff
changeset
|
426 return OK; |
2fee087c94cb
patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents:
19597
diff
changeset
|
427 } |
2fee087c94cb
patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents:
19597
diff
changeset
|
428 |
21383
f25d007f90ac
patch 8.2.1242: Vim9: no error if calling a function with wrong type
Bram Moolenaar <Bram@vim.org>
parents:
21371
diff
changeset
|
429 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
430 /* |
22631
59cd5f8b2ab2
patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents:
22627
diff
changeset
|
431 * Return TRUE if "actual" could be "expected" and a runtime typecheck is to be |
59cd5f8b2ab2
patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents:
22627
diff
changeset
|
432 * used. Return FALSE if the types will never match. |
59cd5f8b2ab2
patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents:
22627
diff
changeset
|
433 */ |
25567
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25555
diff
changeset
|
434 static int |
22631
59cd5f8b2ab2
patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents:
22627
diff
changeset
|
435 use_typecheck(type_T *actual, type_T *expected) |
59cd5f8b2ab2
patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents:
22627
diff
changeset
|
436 { |
59cd5f8b2ab2
patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents:
22627
diff
changeset
|
437 if (actual->tt_type == VAR_ANY |
59cd5f8b2ab2
patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents:
22627
diff
changeset
|
438 || actual->tt_type == VAR_UNKNOWN |
59cd5f8b2ab2
patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents:
22627
diff
changeset
|
439 || (actual->tt_type == VAR_FUNC |
59cd5f8b2ab2
patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents:
22627
diff
changeset
|
440 && (expected->tt_type == VAR_FUNC |
59cd5f8b2ab2
patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents:
22627
diff
changeset
|
441 || expected->tt_type == VAR_PARTIAL) |
26680
1b288eb2fcdc
patch 8.2.3869: Vim9: type checking for "any" is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
26662
diff
changeset
|
442 && (actual->tt_member == &t_any |
1b288eb2fcdc
patch 8.2.3869: Vim9: type checking for "any" is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
26662
diff
changeset
|
443 || actual->tt_member == &t_unknown |
1b288eb2fcdc
patch 8.2.3869: Vim9: type checking for "any" is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
26662
diff
changeset
|
444 || actual->tt_argcount < 0) |
1b288eb2fcdc
patch 8.2.3869: Vim9: type checking for "any" is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
26662
diff
changeset
|
445 && (actual->tt_member == &t_unknown || |
1b288eb2fcdc
patch 8.2.3869: Vim9: type checking for "any" is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
26662
diff
changeset
|
446 (actual->tt_member == &t_void) |
23531
f39a18a42aed
patch 8.2.2308: Vim9: no error when assigning lambda to funcref
Bram Moolenaar <Bram@vim.org>
parents:
23527
diff
changeset
|
447 == (expected->tt_member == &t_void)))) |
22631
59cd5f8b2ab2
patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents:
22627
diff
changeset
|
448 return TRUE; |
59cd5f8b2ab2
patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents:
22627
diff
changeset
|
449 if ((actual->tt_type == VAR_LIST || actual->tt_type == VAR_DICT) |
59cd5f8b2ab2
patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents:
22627
diff
changeset
|
450 && actual->tt_type == expected->tt_type) |
59cd5f8b2ab2
patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents:
22627
diff
changeset
|
451 // This takes care of a nested list or dict. |
59cd5f8b2ab2
patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents:
22627
diff
changeset
|
452 return use_typecheck(actual->tt_member, expected->tt_member); |
59cd5f8b2ab2
patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents:
22627
diff
changeset
|
453 return FALSE; |
59cd5f8b2ab2
patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents:
22627
diff
changeset
|
454 } |
59cd5f8b2ab2
patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents:
22627
diff
changeset
|
455 |
59cd5f8b2ab2
patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents:
22627
diff
changeset
|
456 /* |
20244
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
457 * Check that |
22284
6b385c2b9ff5
patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents:
22276
diff
changeset
|
458 * - "actual" matches "expected" type or |
20244
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
459 * - "actual" is a type that can be "expected" type: add a runtime check; or |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
460 * - return FAIL. |
22631
59cd5f8b2ab2
patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents:
22627
diff
changeset
|
461 * If "actual_is_const" is TRUE then the type won't change at runtime, do not |
59cd5f8b2ab2
patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents:
22627
diff
changeset
|
462 * generate a TYPECHECK. |
20244
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
463 */ |
27515
1aff400b819e
patch 8.2.4285: Vim9: type of item in for loop not checked properly
Bram Moolenaar <Bram@vim.org>
parents:
27348
diff
changeset
|
464 int |
25547
ec4df0b982da
patch 8.2.3310: Vim9: unpack assignment does not mention source of type error
Bram Moolenaar <Bram@vim.org>
parents:
25541
diff
changeset
|
465 need_type_where( |
ec4df0b982da
patch 8.2.3310: Vim9: unpack assignment does not mention source of type error
Bram Moolenaar <Bram@vim.org>
parents:
25541
diff
changeset
|
466 type_T *actual, |
ec4df0b982da
patch 8.2.3310: Vim9: unpack assignment does not mention source of type error
Bram Moolenaar <Bram@vim.org>
parents:
25541
diff
changeset
|
467 type_T *expected, |
31551
67d9fbe516a3
patch 9.0.1108: type error when using "any" type and adding to float
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
468 int number_ok, // expect VAR_FLOAT but VAR_NUMBER is OK |
25547
ec4df0b982da
patch 8.2.3310: Vim9: unpack assignment does not mention source of type error
Bram Moolenaar <Bram@vim.org>
parents:
25541
diff
changeset
|
469 int offset, |
ec4df0b982da
patch 8.2.3310: Vim9: unpack assignment does not mention source of type error
Bram Moolenaar <Bram@vim.org>
parents:
25541
diff
changeset
|
470 where_T where, |
ec4df0b982da
patch 8.2.3310: Vim9: unpack assignment does not mention source of type error
Bram Moolenaar <Bram@vim.org>
parents:
25541
diff
changeset
|
471 cctx_T *cctx, |
ec4df0b982da
patch 8.2.3310: Vim9: unpack assignment does not mention source of type error
Bram Moolenaar <Bram@vim.org>
parents:
25541
diff
changeset
|
472 int silent, |
ec4df0b982da
patch 8.2.3310: Vim9: unpack assignment does not mention source of type error
Bram Moolenaar <Bram@vim.org>
parents:
25541
diff
changeset
|
473 int actual_is_const) |
ec4df0b982da
patch 8.2.3310: Vim9: unpack assignment does not mention source of type error
Bram Moolenaar <Bram@vim.org>
parents:
25541
diff
changeset
|
474 { |
26630
57bc1001160b
patch 8.2.3844: Vim9: no type error if assigning func(number) to func(string)
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
475 int ret; |
57bc1001160b
patch 8.2.3844: Vim9: no type error if assigning func(number) to func(string)
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
476 |
25547
ec4df0b982da
patch 8.2.3310: Vim9: unpack assignment does not mention source of type error
Bram Moolenaar <Bram@vim.org>
parents:
25541
diff
changeset
|
477 if (expected == &t_bool && actual != &t_bool |
ec4df0b982da
patch 8.2.3310: Vim9: unpack assignment does not mention source of type error
Bram Moolenaar <Bram@vim.org>
parents:
25541
diff
changeset
|
478 && (actual->tt_flags & TTFLAG_BOOL_OK)) |
ec4df0b982da
patch 8.2.3310: Vim9: unpack assignment does not mention source of type error
Bram Moolenaar <Bram@vim.org>
parents:
25541
diff
changeset
|
479 { |
ec4df0b982da
patch 8.2.3310: Vim9: unpack assignment does not mention source of type error
Bram Moolenaar <Bram@vim.org>
parents:
25541
diff
changeset
|
480 // Using "0", "1" or the result of an expression with "&&" or "||" as a |
ec4df0b982da
patch 8.2.3310: Vim9: unpack assignment does not mention source of type error
Bram Moolenaar <Bram@vim.org>
parents:
25541
diff
changeset
|
481 // boolean is OK but requires a conversion. |
ec4df0b982da
patch 8.2.3310: Vim9: unpack assignment does not mention source of type error
Bram Moolenaar <Bram@vim.org>
parents:
25541
diff
changeset
|
482 generate_2BOOL(cctx, FALSE, offset); |
ec4df0b982da
patch 8.2.3310: Vim9: unpack assignment does not mention source of type error
Bram Moolenaar <Bram@vim.org>
parents:
25541
diff
changeset
|
483 return OK; |
ec4df0b982da
patch 8.2.3310: Vim9: unpack assignment does not mention source of type error
Bram Moolenaar <Bram@vim.org>
parents:
25541
diff
changeset
|
484 } |
ec4df0b982da
patch 8.2.3310: Vim9: unpack assignment does not mention source of type error
Bram Moolenaar <Bram@vim.org>
parents:
25541
diff
changeset
|
485 |
26630
57bc1001160b
patch 8.2.3844: Vim9: no type error if assigning func(number) to func(string)
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
486 ret = check_type_maybe(expected, actual, FALSE, where); |
57bc1001160b
patch 8.2.3844: Vim9: no type error if assigning func(number) to func(string)
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
487 if (ret == OK) |
25547
ec4df0b982da
patch 8.2.3310: Vim9: unpack assignment does not mention source of type error
Bram Moolenaar <Bram@vim.org>
parents:
25541
diff
changeset
|
488 return OK; |
ec4df0b982da
patch 8.2.3310: Vim9: unpack assignment does not mention source of type error
Bram Moolenaar <Bram@vim.org>
parents:
25541
diff
changeset
|
489 |
28002
1012048eed26
patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents:
27970
diff
changeset
|
490 // If actual a constant a runtime check makes no sense. If it's |
1012048eed26
patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents:
27970
diff
changeset
|
491 // null_function it is OK. |
1012048eed26
patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents:
27970
diff
changeset
|
492 if (actual_is_const && ret == MAYBE && actual == &t_func_unknown) |
1012048eed26
patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents:
27970
diff
changeset
|
493 return OK; |
1012048eed26
patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents:
27970
diff
changeset
|
494 |
25547
ec4df0b982da
patch 8.2.3310: Vim9: unpack assignment does not mention source of type error
Bram Moolenaar <Bram@vim.org>
parents:
25541
diff
changeset
|
495 // If the actual type can be the expected type add a runtime check. |
26680
1b288eb2fcdc
patch 8.2.3869: Vim9: type checking for "any" is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
26662
diff
changeset
|
496 if (!actual_is_const && ret == MAYBE && use_typecheck(actual, expected)) |
25547
ec4df0b982da
patch 8.2.3310: Vim9: unpack assignment does not mention source of type error
Bram Moolenaar <Bram@vim.org>
parents:
25541
diff
changeset
|
497 { |
31551
67d9fbe516a3
patch 9.0.1108: type error when using "any" type and adding to float
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
498 generate_TYPECHECK(cctx, expected, number_ok, offset, |
28901
11609f025219
patch 8.2.4973: Vim9: type error for list unpack mentions argument
Bram Moolenaar <Bram@vim.org>
parents:
28833
diff
changeset
|
499 where.wt_variable, where.wt_index); |
25547
ec4df0b982da
patch 8.2.3310: Vim9: unpack assignment does not mention source of type error
Bram Moolenaar <Bram@vim.org>
parents:
25541
diff
changeset
|
500 return OK; |
ec4df0b982da
patch 8.2.3310: Vim9: unpack assignment does not mention source of type error
Bram Moolenaar <Bram@vim.org>
parents:
25541
diff
changeset
|
501 } |
ec4df0b982da
patch 8.2.3310: Vim9: unpack assignment does not mention source of type error
Bram Moolenaar <Bram@vim.org>
parents:
25541
diff
changeset
|
502 |
ec4df0b982da
patch 8.2.3310: Vim9: unpack assignment does not mention source of type error
Bram Moolenaar <Bram@vim.org>
parents:
25541
diff
changeset
|
503 if (!silent) |
ec4df0b982da
patch 8.2.3310: Vim9: unpack assignment does not mention source of type error
Bram Moolenaar <Bram@vim.org>
parents:
25541
diff
changeset
|
504 type_mismatch_where(expected, actual, where); |
ec4df0b982da
patch 8.2.3310: Vim9: unpack assignment does not mention source of type error
Bram Moolenaar <Bram@vim.org>
parents:
25541
diff
changeset
|
505 return FAIL; |
ec4df0b982da
patch 8.2.3310: Vim9: unpack assignment does not mention source of type error
Bram Moolenaar <Bram@vim.org>
parents:
25541
diff
changeset
|
506 } |
ec4df0b982da
patch 8.2.3310: Vim9: unpack assignment does not mention source of type error
Bram Moolenaar <Bram@vim.org>
parents:
25541
diff
changeset
|
507 |
23640
8dcb2255ff9a
patch 8.2.2362: Vim9: check of builtin function argument type is incomplete
Bram Moolenaar <Bram@vim.org>
parents:
23614
diff
changeset
|
508 int |
21265
6a4806e326dd
patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents:
21255
diff
changeset
|
509 need_type( |
6a4806e326dd
patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents:
21255
diff
changeset
|
510 type_T *actual, |
6a4806e326dd
patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents:
21255
diff
changeset
|
511 type_T *expected, |
31551
67d9fbe516a3
patch 9.0.1108: type error when using "any" type and adding to float
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
512 int number_ok, // when expected is float number is also OK |
21265
6a4806e326dd
patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents:
21255
diff
changeset
|
513 int offset, |
23640
8dcb2255ff9a
patch 8.2.2362: Vim9: check of builtin function argument type is incomplete
Bram Moolenaar <Bram@vim.org>
parents:
23614
diff
changeset
|
514 int arg_idx, |
21265
6a4806e326dd
patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents:
21255
diff
changeset
|
515 cctx_T *cctx, |
22631
59cd5f8b2ab2
patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents:
22627
diff
changeset
|
516 int silent, |
59cd5f8b2ab2
patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents:
22627
diff
changeset
|
517 int actual_is_const) |
20244
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
518 { |
25326
cfbf40f749b0
patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
519 where_T where = WHERE_INIT; |
23917
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
520 |
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
521 where.wt_index = arg_idx; |
31551
67d9fbe516a3
patch 9.0.1108: type error when using "any" type and adding to float
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
522 return need_type_where(actual, expected, number_ok, offset, where, |
25547
ec4df0b982da
patch 8.2.3310: Vim9: unpack assignment does not mention source of type error
Bram Moolenaar <Bram@vim.org>
parents:
25541
diff
changeset
|
523 cctx, silent, actual_is_const); |
20244
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
524 } |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
525 |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
526 /* |
30576
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30335
diff
changeset
|
527 * Set type of variable "lvar" to "type". If the variable is a constant then |
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30335
diff
changeset
|
528 * the type gets TTFLAG_CONST. |
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30335
diff
changeset
|
529 */ |
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30335
diff
changeset
|
530 static void |
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30335
diff
changeset
|
531 set_var_type(lvar_T *lvar, type_T *type_arg, cctx_T *cctx) |
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30335
diff
changeset
|
532 { |
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30335
diff
changeset
|
533 type_T *type = type_arg; |
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30335
diff
changeset
|
534 |
30584
ee039a6049ff
patch 9.0.0627: "const" and "final" both make the type a constant
Bram Moolenaar <Bram@vim.org>
parents:
30576
diff
changeset
|
535 if (lvar->lv_const == ASSIGN_CONST && (type->tt_flags & TTFLAG_CONST) == 0) |
30576
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30335
diff
changeset
|
536 { |
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30335
diff
changeset
|
537 if (type->tt_flags & TTFLAG_STATIC) |
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30335
diff
changeset
|
538 // entry in static_types[] is followed by const type |
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30335
diff
changeset
|
539 type = type + 1; |
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30335
diff
changeset
|
540 else |
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30335
diff
changeset
|
541 { |
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30335
diff
changeset
|
542 type = copy_type(type, cctx->ctx_type_list); |
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30335
diff
changeset
|
543 type->tt_flags |= TTFLAG_CONST; |
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30335
diff
changeset
|
544 } |
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30335
diff
changeset
|
545 } |
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30335
diff
changeset
|
546 lvar->lv_type = type; |
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30335
diff
changeset
|
547 } |
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30335
diff
changeset
|
548 |
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30335
diff
changeset
|
549 /* |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
550 * Reserve space for a local variable. |
30584
ee039a6049ff
patch 9.0.0627: "const" and "final" both make the type a constant
Bram Moolenaar <Bram@vim.org>
parents:
30576
diff
changeset
|
551 * "assign" can be ASSIGN_VAR for :var, ASSIGN_CONST for :const and |
ee039a6049ff
patch 9.0.0627: "const" and "final" both make the type a constant
Bram Moolenaar <Bram@vim.org>
parents:
30576
diff
changeset
|
552 * ASSIGN_FINAL for :final. |
20239
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
553 * Return the variable or NULL if it failed. |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
554 */ |
26662
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
555 lvar_T * |
22537
9870e8b6ed78
patch 8.2.1817: Vim9: wrong instruction when reusing a local variable spot
Bram Moolenaar <Bram@vim.org>
parents:
22508
diff
changeset
|
556 reserve_local( |
9870e8b6ed78
patch 8.2.1817: Vim9: wrong instruction when reusing a local variable spot
Bram Moolenaar <Bram@vim.org>
parents:
22508
diff
changeset
|
557 cctx_T *cctx, |
9870e8b6ed78
patch 8.2.1817: Vim9: wrong instruction when reusing a local variable spot
Bram Moolenaar <Bram@vim.org>
parents:
22508
diff
changeset
|
558 char_u *name, |
9870e8b6ed78
patch 8.2.1817: Vim9: wrong instruction when reusing a local variable spot
Bram Moolenaar <Bram@vim.org>
parents:
22508
diff
changeset
|
559 size_t len, |
30584
ee039a6049ff
patch 9.0.0627: "const" and "final" both make the type a constant
Bram Moolenaar <Bram@vim.org>
parents:
30576
diff
changeset
|
560 int assign, |
22537
9870e8b6ed78
patch 8.2.1817: Vim9: wrong instruction when reusing a local variable spot
Bram Moolenaar <Bram@vim.org>
parents:
22508
diff
changeset
|
561 type_T *type) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
562 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
563 lvar_T *lvar; |
24918
f11779c1d123
patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents:
24914
diff
changeset
|
564 dfunc_T *dfunc; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
565 |
22596
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
566 if (arg_exists(name, len, NULL, NULL, NULL, cctx) == OK) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
567 { |
21821
0deb6f96a5a3
patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
21811
diff
changeset
|
568 emsg_namelen(_(e_str_is_used_as_argument), name, (int)len); |
20239
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
569 return NULL; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
570 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
571 |
25477
a8f526c9b172
patch 8.2.3275: optimizer can use hints about ga_grow() normally succeeding
Bram Moolenaar <Bram@vim.org>
parents:
25469
diff
changeset
|
572 if (GA_GROW_FAILS(&cctx->ctx_locals, 1)) |
20239
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
573 return NULL; |
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
574 lvar = ((lvar_T *)cctx->ctx_locals.ga_data) + cctx->ctx_locals.ga_len++; |
22537
9870e8b6ed78
patch 8.2.1817: Vim9: wrong instruction when reusing a local variable spot
Bram Moolenaar <Bram@vim.org>
parents:
22508
diff
changeset
|
575 CLEAR_POINTER(lvar); |
20239
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
576 |
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
577 // Every local variable uses the next entry on the stack. We could re-use |
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
578 // the last ones when leaving a scope, but then variables used in a closure |
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
579 // might get overwritten. To keep things simple do not re-use stack |
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
580 // entries. This is less efficient, but memory is cheap these days. |
24918
f11779c1d123
patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents:
24914
diff
changeset
|
581 dfunc = ((dfunc_T *)def_functions.ga_data) + cctx->ctx_ufunc->uf_dfunc_idx; |
f11779c1d123
patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents:
24914
diff
changeset
|
582 lvar->lv_idx = dfunc->df_var_names.ga_len; |
20239
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
583 |
20830
9064044fd4f6
patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20538
diff
changeset
|
584 lvar->lv_name = vim_strnsave(name, len == 0 ? STRLEN(name) : len); |
30584
ee039a6049ff
patch 9.0.0627: "const" and "final" both make the type a constant
Bram Moolenaar <Bram@vim.org>
parents:
30576
diff
changeset
|
585 lvar->lv_const = assign; |
30576
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30335
diff
changeset
|
586 if (type == &t_unknown || type == &t_any) |
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30335
diff
changeset
|
587 // type not known yet, may be inferred from RHS |
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30335
diff
changeset
|
588 lvar->lv_type = type; |
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30335
diff
changeset
|
589 else |
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30335
diff
changeset
|
590 // may use TTFLAG_CONST |
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30335
diff
changeset
|
591 set_var_type(lvar, type, cctx); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
592 |
24918
f11779c1d123
patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents:
24914
diff
changeset
|
593 // Remember the name for debugging. |
25477
a8f526c9b172
patch 8.2.3275: optimizer can use hints about ga_grow() normally succeeding
Bram Moolenaar <Bram@vim.org>
parents:
25469
diff
changeset
|
594 if (GA_GROW_FAILS(&dfunc->df_var_names, 1)) |
24918
f11779c1d123
patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents:
24914
diff
changeset
|
595 return NULL; |
f11779c1d123
patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents:
24914
diff
changeset
|
596 ((char_u **)dfunc->df_var_names.ga_data)[lvar->lv_idx] = |
f11779c1d123
patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents:
24914
diff
changeset
|
597 vim_strsave(lvar->lv_name); |
f11779c1d123
patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents:
24914
diff
changeset
|
598 ++dfunc->df_var_names.ga_len; |
f11779c1d123
patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents:
24914
diff
changeset
|
599 |
20239
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
600 return lvar; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
601 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
602 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
603 /* |
23578
85ce241ff9e3
patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents:
23576
diff
changeset
|
604 * If "check_writable" is ASSIGN_CONST give an error if the variable was |
85ce241ff9e3
patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents:
23576
diff
changeset
|
605 * defined with :final or :const, if "check_writable" is ASSIGN_FINAL give an |
85ce241ff9e3
patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents:
23576
diff
changeset
|
606 * error if the variable was defined with :const. |
85ce241ff9e3
patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents:
23576
diff
changeset
|
607 */ |
85ce241ff9e3
patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents:
23576
diff
changeset
|
608 static int |
85ce241ff9e3
patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents:
23576
diff
changeset
|
609 check_item_writable(svar_T *sv, int check_writable, char_u *name) |
85ce241ff9e3
patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents:
23576
diff
changeset
|
610 { |
85ce241ff9e3
patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents:
23576
diff
changeset
|
611 if ((check_writable == ASSIGN_CONST && sv->sv_const != 0) |
85ce241ff9e3
patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents:
23576
diff
changeset
|
612 || (check_writable == ASSIGN_FINAL |
85ce241ff9e3
patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents:
23576
diff
changeset
|
613 && sv->sv_const == ASSIGN_CONST)) |
85ce241ff9e3
patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents:
23576
diff
changeset
|
614 { |
25320
1e6da8364a02
patch 8.2.3197: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
25318
diff
changeset
|
615 semsg(_(e_cannot_change_readonly_variable_str), name); |
23578
85ce241ff9e3
patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents:
23576
diff
changeset
|
616 return FAIL; |
85ce241ff9e3
patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents:
23576
diff
changeset
|
617 } |
85ce241ff9e3
patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents:
23576
diff
changeset
|
618 return OK; |
85ce241ff9e3
patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents:
23576
diff
changeset
|
619 } |
85ce241ff9e3
patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents:
23576
diff
changeset
|
620 |
85ce241ff9e3
patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents:
23576
diff
changeset
|
621 /* |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
622 * Find "name" in script-local items of script "sid". |
23578
85ce241ff9e3
patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents:
23576
diff
changeset
|
623 * Pass "check_writable" to check_item_writable(). |
27714
072c7ae27b06
patch 8.2.4383: Vim9: unused code lines
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
624 * "cctx" is NULL at the script level, "cstack" is NULL in a function. |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
625 * Returns the index in "sn_var_vals" if found. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
626 * If found but not in "sn_var_vals" returns -1. |
23578
85ce241ff9e3
patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents:
23576
diff
changeset
|
627 * If not found or the variable is not writable returns -2. |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
628 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
629 int |
27613
42d0279c6e7c
patch 8.2.4333: cstack not always passed to where it is needed
Bram Moolenaar <Bram@vim.org>
parents:
27611
diff
changeset
|
630 get_script_item_idx( |
42d0279c6e7c
patch 8.2.4333: cstack not always passed to where it is needed
Bram Moolenaar <Bram@vim.org>
parents:
27611
diff
changeset
|
631 int sid, |
42d0279c6e7c
patch 8.2.4333: cstack not always passed to where it is needed
Bram Moolenaar <Bram@vim.org>
parents:
27611
diff
changeset
|
632 char_u *name, |
42d0279c6e7c
patch 8.2.4333: cstack not always passed to where it is needed
Bram Moolenaar <Bram@vim.org>
parents:
27611
diff
changeset
|
633 int check_writable, |
42d0279c6e7c
patch 8.2.4333: cstack not always passed to where it is needed
Bram Moolenaar <Bram@vim.org>
parents:
27611
diff
changeset
|
634 cctx_T *cctx, |
42d0279c6e7c
patch 8.2.4333: cstack not always passed to where it is needed
Bram Moolenaar <Bram@vim.org>
parents:
27611
diff
changeset
|
635 cstack_T *cstack) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
636 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
637 hashtab_T *ht; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
638 dictitem_T *di; |
19191
133ef7ba4e4e
patch 8.2.0154: reallocating the list of scripts is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
639 scriptitem_T *si = SCRIPT_ITEM(sid); |
22596
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
640 svar_T *sv; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
641 int idx; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
642 |
22596
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
643 if (!SCRIPT_ID_VALID(sid)) |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
644 return -1; |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
645 if (sid == current_sctx.sc_sid) |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
646 { |
27613
42d0279c6e7c
patch 8.2.4333: cstack not always passed to where it is needed
Bram Moolenaar <Bram@vim.org>
parents:
27611
diff
changeset
|
647 sallvar_T *sav = find_script_var(name, 0, cctx, cstack); |
22596
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
648 |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
649 if (sav == NULL) |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
650 return -2; |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
651 idx = sav->sav_var_vals_idx; |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
652 sv = ((svar_T *)si->sn_var_vals.ga_data) + idx; |
23578
85ce241ff9e3
patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents:
23576
diff
changeset
|
653 if (check_item_writable(sv, check_writable, name) == FAIL) |
85ce241ff9e3
patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents:
23576
diff
changeset
|
654 return -2; |
22596
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
655 return idx; |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
656 } |
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
657 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
658 // First look the name up in the hashtable. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
659 ht = &SCRIPT_VARS(sid); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
660 di = find_var_in_ht(ht, 0, name, TRUE); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
661 if (di == NULL) |
27051
f17bdc9cda64
patch 8.2.4054: Vim9 script test fails
Bram Moolenaar <Bram@vim.org>
parents:
27043
diff
changeset
|
662 { |
f17bdc9cda64
patch 8.2.4054: Vim9 script test fails
Bram Moolenaar <Bram@vim.org>
parents:
27043
diff
changeset
|
663 if (si->sn_autoload_prefix != NULL) |
f17bdc9cda64
patch 8.2.4054: Vim9 script test fails
Bram Moolenaar <Bram@vim.org>
parents:
27043
diff
changeset
|
664 { |
f17bdc9cda64
patch 8.2.4054: Vim9 script test fails
Bram Moolenaar <Bram@vim.org>
parents:
27043
diff
changeset
|
665 hashitem_T *hi; |
f17bdc9cda64
patch 8.2.4054: Vim9 script test fails
Bram Moolenaar <Bram@vim.org>
parents:
27043
diff
changeset
|
666 |
f17bdc9cda64
patch 8.2.4054: Vim9 script test fails
Bram Moolenaar <Bram@vim.org>
parents:
27043
diff
changeset
|
667 // A variable exported from an autoload script is in the global |
f17bdc9cda64
patch 8.2.4054: Vim9 script test fails
Bram Moolenaar <Bram@vim.org>
parents:
27043
diff
changeset
|
668 // variables, we can find it in the all_vars table. |
f17bdc9cda64
patch 8.2.4054: Vim9 script test fails
Bram Moolenaar <Bram@vim.org>
parents:
27043
diff
changeset
|
669 hi = hash_find(&si->sn_all_vars.dv_hashtab, name); |
f17bdc9cda64
patch 8.2.4054: Vim9 script test fails
Bram Moolenaar <Bram@vim.org>
parents:
27043
diff
changeset
|
670 if (!HASHITEM_EMPTY(hi)) |
f17bdc9cda64
patch 8.2.4054: Vim9 script test fails
Bram Moolenaar <Bram@vim.org>
parents:
27043
diff
changeset
|
671 return HI2SAV(hi)->sav_var_vals_idx; |
f17bdc9cda64
patch 8.2.4054: Vim9 script test fails
Bram Moolenaar <Bram@vim.org>
parents:
27043
diff
changeset
|
672 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
673 return -2; |
27051
f17bdc9cda64
patch 8.2.4054: Vim9 script test fails
Bram Moolenaar <Bram@vim.org>
parents:
27043
diff
changeset
|
674 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
675 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
676 // Now find the svar_T index in sn_var_vals. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
677 for (idx = 0; idx < si->sn_var_vals.ga_len; ++idx) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
678 { |
22596
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
679 sv = ((svar_T *)si->sn_var_vals.ga_data) + idx; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
680 if (sv->sv_tv == &di->di_tv) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
681 { |
23578
85ce241ff9e3
patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents:
23576
diff
changeset
|
682 if (check_item_writable(sv, check_writable, name) == FAIL) |
85ce241ff9e3
patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents:
23576
diff
changeset
|
683 return -2; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
684 return idx; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
685 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
686 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
687 return -1; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
688 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
689 |
27032
18cafa092e8d
patch 8.2.4045: some global functions are only used in one file
Bram Moolenaar <Bram@vim.org>
parents:
27022
diff
changeset
|
690 static imported_T * |
18cafa092e8d
patch 8.2.4045: some global functions are only used in one file
Bram Moolenaar <Bram@vim.org>
parents:
27022
diff
changeset
|
691 find_imported_in_script(char_u *name, size_t len, int sid) |
18cafa092e8d
patch 8.2.4045: some global functions are only used in one file
Bram Moolenaar <Bram@vim.org>
parents:
27022
diff
changeset
|
692 { |
18cafa092e8d
patch 8.2.4045: some global functions are only used in one file
Bram Moolenaar <Bram@vim.org>
parents:
27022
diff
changeset
|
693 scriptitem_T *si; |
18cafa092e8d
patch 8.2.4045: some global functions are only used in one file
Bram Moolenaar <Bram@vim.org>
parents:
27022
diff
changeset
|
694 int idx; |
18cafa092e8d
patch 8.2.4045: some global functions are only used in one file
Bram Moolenaar <Bram@vim.org>
parents:
27022
diff
changeset
|
695 |
18cafa092e8d
patch 8.2.4045: some global functions are only used in one file
Bram Moolenaar <Bram@vim.org>
parents:
27022
diff
changeset
|
696 if (!SCRIPT_ID_VALID(sid)) |
18cafa092e8d
patch 8.2.4045: some global functions are only used in one file
Bram Moolenaar <Bram@vim.org>
parents:
27022
diff
changeset
|
697 return NULL; |
18cafa092e8d
patch 8.2.4045: some global functions are only used in one file
Bram Moolenaar <Bram@vim.org>
parents:
27022
diff
changeset
|
698 si = SCRIPT_ITEM(sid); |
18cafa092e8d
patch 8.2.4045: some global functions are only used in one file
Bram Moolenaar <Bram@vim.org>
parents:
27022
diff
changeset
|
699 for (idx = 0; idx < si->sn_imports.ga_len; ++idx) |
18cafa092e8d
patch 8.2.4045: some global functions are only used in one file
Bram Moolenaar <Bram@vim.org>
parents:
27022
diff
changeset
|
700 { |
18cafa092e8d
patch 8.2.4045: some global functions are only used in one file
Bram Moolenaar <Bram@vim.org>
parents:
27022
diff
changeset
|
701 imported_T *import = ((imported_T *)si->sn_imports.ga_data) + idx; |
18cafa092e8d
patch 8.2.4045: some global functions are only used in one file
Bram Moolenaar <Bram@vim.org>
parents:
27022
diff
changeset
|
702 |
18cafa092e8d
patch 8.2.4045: some global functions are only used in one file
Bram Moolenaar <Bram@vim.org>
parents:
27022
diff
changeset
|
703 if (len == 0 ? STRCMP(name, import->imp_name) == 0 |
18cafa092e8d
patch 8.2.4045: some global functions are only used in one file
Bram Moolenaar <Bram@vim.org>
parents:
27022
diff
changeset
|
704 : STRLEN(import->imp_name) == len |
18cafa092e8d
patch 8.2.4045: some global functions are only used in one file
Bram Moolenaar <Bram@vim.org>
parents:
27022
diff
changeset
|
705 && STRNCMP(name, import->imp_name, len) == 0) |
18cafa092e8d
patch 8.2.4045: some global functions are only used in one file
Bram Moolenaar <Bram@vim.org>
parents:
27022
diff
changeset
|
706 return import; |
18cafa092e8d
patch 8.2.4045: some global functions are only used in one file
Bram Moolenaar <Bram@vim.org>
parents:
27022
diff
changeset
|
707 } |
18cafa092e8d
patch 8.2.4045: some global functions are only used in one file
Bram Moolenaar <Bram@vim.org>
parents:
27022
diff
changeset
|
708 return NULL; |
18cafa092e8d
patch 8.2.4045: some global functions are only used in one file
Bram Moolenaar <Bram@vim.org>
parents:
27022
diff
changeset
|
709 } |
18cafa092e8d
patch 8.2.4045: some global functions are only used in one file
Bram Moolenaar <Bram@vim.org>
parents:
27022
diff
changeset
|
710 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
711 /* |
27698
3813036f19cb
patch 8.2.4375: ctx_imports is not used
Bram Moolenaar <Bram@vim.org>
parents:
27696
diff
changeset
|
712 * Find "name" in imported items of the current script. |
28560
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28281
diff
changeset
|
713 * If "len" is 0 use any length that works. |
27043
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27032
diff
changeset
|
714 * If "load" is TRUE and the script was not loaded yet, load it now. |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
715 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
716 imported_T * |
27698
3813036f19cb
patch 8.2.4375: ctx_imports is not used
Bram Moolenaar <Bram@vim.org>
parents:
27696
diff
changeset
|
717 find_imported(char_u *name, size_t len, int load) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
718 { |
21979
a98211c3e14e
patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
21963
diff
changeset
|
719 if (!SCRIPT_ID_VALID(current_sctx.sc_sid)) |
21110
8fb0e507491d
patch 8.2.1106: crash when trying to use s: variable in typed command
Bram Moolenaar <Bram@vim.org>
parents:
21040
diff
changeset
|
720 return NULL; |
27698
3813036f19cb
patch 8.2.4375: ctx_imports is not used
Bram Moolenaar <Bram@vim.org>
parents:
27696
diff
changeset
|
721 |
31172
4bde058d0be7
patch 9.0.0920: cannot find an import prefixed with "s:"
Bram Moolenaar <Bram@vim.org>
parents:
30954
diff
changeset
|
722 // Skip over "s:" before "s:something" to find the import name. |
4bde058d0be7
patch 9.0.0920: cannot find an import prefixed with "s:"
Bram Moolenaar <Bram@vim.org>
parents:
30954
diff
changeset
|
723 int off = name[0] == 's' && name[1] == ':' ? 2 : 0; |
4bde058d0be7
patch 9.0.0920: cannot find an import prefixed with "s:"
Bram Moolenaar <Bram@vim.org>
parents:
30954
diff
changeset
|
724 |
4bde058d0be7
patch 9.0.0920: cannot find an import prefixed with "s:"
Bram Moolenaar <Bram@vim.org>
parents:
30954
diff
changeset
|
725 imported_T *ret = find_imported_in_script(name + off, len - off, |
4bde058d0be7
patch 9.0.0920: cannot find an import prefixed with "s:"
Bram Moolenaar <Bram@vim.org>
parents:
30954
diff
changeset
|
726 current_sctx.sc_sid); |
27297
f7cb41ff22a4
patch 8.2.4177: Vim9: autoload script not loaded after "vim9script noclear"
Bram Moolenaar <Bram@vim.org>
parents:
27237
diff
changeset
|
727 if (ret != NULL && load && (ret->imp_flags & IMP_FLAGS_AUTOLOAD)) |
27043
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27032
diff
changeset
|
728 { |
29828
6b7020f3d856
patch 9.0.0253: a symlink to an autoload script results in two entries
Bram Moolenaar <Bram@vim.org>
parents:
29769
diff
changeset
|
729 scid_T actual_sid = 0; |
29475
fab3a46d0af7
patch 9.0.0079: error in autoload script not reported for 'foldexpr'
Bram Moolenaar <Bram@vim.org>
parents:
29008
diff
changeset
|
730 int save_emsg_off = emsg_off; |
fab3a46d0af7
patch 9.0.0079: error in autoload script not reported for 'foldexpr'
Bram Moolenaar <Bram@vim.org>
parents:
29008
diff
changeset
|
731 |
fab3a46d0af7
patch 9.0.0079: error in autoload script not reported for 'foldexpr'
Bram Moolenaar <Bram@vim.org>
parents:
29008
diff
changeset
|
732 // "emsg_off" will be set when evaluating an expression silently, but |
fab3a46d0af7
patch 9.0.0079: error in autoload script not reported for 'foldexpr'
Bram Moolenaar <Bram@vim.org>
parents:
29008
diff
changeset
|
733 // we do want to know about errors in a script. Also because it then |
fab3a46d0af7
patch 9.0.0079: error in autoload script not reported for 'foldexpr'
Bram Moolenaar <Bram@vim.org>
parents:
29008
diff
changeset
|
734 // aborts when an error is encountered. |
fab3a46d0af7
patch 9.0.0079: error in autoload script not reported for 'foldexpr'
Bram Moolenaar <Bram@vim.org>
parents:
29008
diff
changeset
|
735 emsg_off = FALSE; |
27074
19fefc42a063
patch 8.2.4066: Vim9: imported autoload script loaded again
Bram Moolenaar <Bram@vim.org>
parents:
27051
diff
changeset
|
736 |
27043
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27032
diff
changeset
|
737 // script found before but not loaded yet |
27297
f7cb41ff22a4
patch 8.2.4177: Vim9: autoload script not loaded after "vim9script noclear"
Bram Moolenaar <Bram@vim.org>
parents:
27237
diff
changeset
|
738 ret->imp_flags &= ~IMP_FLAGS_AUTOLOAD; |
27043
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27032
diff
changeset
|
739 (void)do_source(SCRIPT_ITEM(ret->imp_sid)->sn_name, FALSE, |
29828
6b7020f3d856
patch 9.0.0253: a symlink to an autoload script results in two entries
Bram Moolenaar <Bram@vim.org>
parents:
29769
diff
changeset
|
740 DOSO_NONE, &actual_sid); |
6b7020f3d856
patch 9.0.0253: a symlink to an autoload script results in two entries
Bram Moolenaar <Bram@vim.org>
parents:
29769
diff
changeset
|
741 // If the script is a symlink it may be sourced with another name, may |
6b7020f3d856
patch 9.0.0253: a symlink to an autoload script results in two entries
Bram Moolenaar <Bram@vim.org>
parents:
29769
diff
changeset
|
742 // need to adjust the script ID for that. |
6b7020f3d856
patch 9.0.0253: a symlink to an autoload script results in two entries
Bram Moolenaar <Bram@vim.org>
parents:
29769
diff
changeset
|
743 if (actual_sid != 0) |
6b7020f3d856
patch 9.0.0253: a symlink to an autoload script results in two entries
Bram Moolenaar <Bram@vim.org>
parents:
29769
diff
changeset
|
744 ret->imp_sid = actual_sid; |
29475
fab3a46d0af7
patch 9.0.0079: error in autoload script not reported for 'foldexpr'
Bram Moolenaar <Bram@vim.org>
parents:
29008
diff
changeset
|
745 |
fab3a46d0af7
patch 9.0.0079: error in autoload script not reported for 'foldexpr'
Bram Moolenaar <Bram@vim.org>
parents:
29008
diff
changeset
|
746 emsg_off = save_emsg_off; |
27043
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27032
diff
changeset
|
747 } |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27032
diff
changeset
|
748 return ret; |
21699
1b96535705a0
patch 8.2.1399: Vim9: may find imported item in wrong script
Bram Moolenaar <Bram@vim.org>
parents:
21693
diff
changeset
|
749 } |
1b96535705a0
patch 8.2.1399: Vim9: may find imported item in wrong script
Bram Moolenaar <Bram@vim.org>
parents:
21693
diff
changeset
|
750 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
751 /* |
26662
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
752 * Called when checking for a following operator at "arg". When the rest of |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
753 * the line is empty or only a comment, peek the next line. If there is a next |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
754 * line return a pointer to it and set "nextp". |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
755 * Otherwise skip over white space. |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
756 */ |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
757 char_u * |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
758 may_peek_next_line(cctx_T *cctx, char_u *arg, char_u **nextp) |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
759 { |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
760 char_u *p = skipwhite(arg); |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
761 |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
762 *nextp = NULL; |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
763 if (*p == NUL || (VIM_ISWHITE(*arg) && vim9_comment_start(p))) |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
764 { |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
765 *nextp = peek_next_line_from_context(cctx); |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
766 if (*nextp != NULL) |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
767 return *nextp; |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
768 } |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
769 return p; |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
770 } |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
771 |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
772 /* |
20955
396fe712eb0f
patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
773 * Return a pointer to the next line that isn't empty or only contains a |
396fe712eb0f
patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
774 * comment. Skips over white space. |
396fe712eb0f
patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
775 * Returns NULL if there is none. |
396fe712eb0f
patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
776 */ |
21208
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21202
diff
changeset
|
777 char_u * |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21202
diff
changeset
|
778 peek_next_line_from_context(cctx_T *cctx) |
20955
396fe712eb0f
patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
779 { |
396fe712eb0f
patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
780 int lnum = cctx->ctx_lnum; |
396fe712eb0f
patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
781 |
396fe712eb0f
patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
782 while (++lnum < cctx->ctx_ufunc->uf_lines.ga_len) |
396fe712eb0f
patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
783 { |
396fe712eb0f
patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
784 char_u *line = ((char_u **)cctx->ctx_ufunc->uf_lines.ga_data)[lnum]; |
20972
d561e3c6cd65
patch 8.2.1037: Vim9: crash when using line continuation inside :def
Bram Moolenaar <Bram@vim.org>
parents:
20966
diff
changeset
|
785 char_u *p; |
d561e3c6cd65
patch 8.2.1037: Vim9: crash when using line continuation inside :def
Bram Moolenaar <Bram@vim.org>
parents:
20966
diff
changeset
|
786 |
21767
9529a2367d3e
patch 8.2.1433: Vim9: cannot mingle comments in multi-line lambda
Bram Moolenaar <Bram@vim.org>
parents:
21763
diff
changeset
|
787 // ignore NULLs inserted for continuation lines |
9529a2367d3e
patch 8.2.1433: Vim9: cannot mingle comments in multi-line lambda
Bram Moolenaar <Bram@vim.org>
parents:
21763
diff
changeset
|
788 if (line != NULL) |
9529a2367d3e
patch 8.2.1433: Vim9: cannot mingle comments in multi-line lambda
Bram Moolenaar <Bram@vim.org>
parents:
21763
diff
changeset
|
789 { |
9529a2367d3e
patch 8.2.1433: Vim9: cannot mingle comments in multi-line lambda
Bram Moolenaar <Bram@vim.org>
parents:
21763
diff
changeset
|
790 p = skipwhite(line); |
24158
93e69703a290
patch 8.2.2620: Vim9: Using #{ for a dictionary gives strange errors
Bram Moolenaar <Bram@vim.org>
parents:
24154
diff
changeset
|
791 if (vim9_bad_comment(p)) |
93e69703a290
patch 8.2.2620: Vim9: Using #{ for a dictionary gives strange errors
Bram Moolenaar <Bram@vim.org>
parents:
24154
diff
changeset
|
792 return NULL; |
21767
9529a2367d3e
patch 8.2.1433: Vim9: cannot mingle comments in multi-line lambda
Bram Moolenaar <Bram@vim.org>
parents:
21763
diff
changeset
|
793 if (*p != NUL && !vim9_comment_start(p)) |
9529a2367d3e
patch 8.2.1433: Vim9: cannot mingle comments in multi-line lambda
Bram Moolenaar <Bram@vim.org>
parents:
21763
diff
changeset
|
794 return p; |
9529a2367d3e
patch 8.2.1433: Vim9: cannot mingle comments in multi-line lambda
Bram Moolenaar <Bram@vim.org>
parents:
21763
diff
changeset
|
795 } |
20955
396fe712eb0f
patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
796 } |
396fe712eb0f
patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
797 return NULL; |
396fe712eb0f
patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
798 } |
396fe712eb0f
patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
799 |
396fe712eb0f
patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
800 /* |
20011
628011800942
patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
801 * Get the next line of the function from "cctx". |
20955
396fe712eb0f
patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
802 * Skips over empty lines. Skips over comment lines if "skip_comment" is TRUE. |
20011
628011800942
patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
803 * Returns NULL when at the end. |
628011800942
patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
804 */ |
21208
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21202
diff
changeset
|
805 char_u * |
20955
396fe712eb0f
patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
806 next_line_from_context(cctx_T *cctx, int skip_comment) |
20011
628011800942
patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
807 { |
20059
de756b3f4dee
patch 8.2.0585: Vim9: # comment not recognized after :vim9script
Bram Moolenaar <Bram@vim.org>
parents:
20055
diff
changeset
|
808 char_u *line; |
20011
628011800942
patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
809 |
628011800942
patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
810 do |
628011800942
patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
811 { |
628011800942
patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
812 ++cctx->ctx_lnum; |
628011800942
patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
813 if (cctx->ctx_lnum >= cctx->ctx_ufunc->uf_lines.ga_len) |
20059
de756b3f4dee
patch 8.2.0585: Vim9: # comment not recognized after :vim9script
Bram Moolenaar <Bram@vim.org>
parents:
20055
diff
changeset
|
814 { |
de756b3f4dee
patch 8.2.0585: Vim9: # comment not recognized after :vim9script
Bram Moolenaar <Bram@vim.org>
parents:
20055
diff
changeset
|
815 line = NULL; |
20011
628011800942
patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
816 break; |
20059
de756b3f4dee
patch 8.2.0585: Vim9: # comment not recognized after :vim9script
Bram Moolenaar <Bram@vim.org>
parents:
20055
diff
changeset
|
817 } |
20011
628011800942
patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
818 line = ((char_u **)cctx->ctx_ufunc->uf_lines.ga_data)[cctx->ctx_lnum]; |
20059
de756b3f4dee
patch 8.2.0585: Vim9: # comment not recognized after :vim9script
Bram Moolenaar <Bram@vim.org>
parents:
20055
diff
changeset
|
819 cctx->ctx_line_start = line; |
20538
9f921ba86d05
patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents:
20534
diff
changeset
|
820 SOURCING_LNUM = cctx->ctx_lnum + 1; |
20955
396fe712eb0f
patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
821 } while (line == NULL || *skipwhite(line) == NUL |
21689
10866fd07595
patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents:
21683
diff
changeset
|
822 || (skip_comment && vim9_comment_start(skipwhite(line)))); |
20011
628011800942
patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
823 return line; |
628011800942
patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
824 } |
628011800942
patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
825 |
628011800942
patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
826 /* |
23491
ac5ead954dcd
patch 8.2.2288: Vim9: line break and comment not always skipped
Bram Moolenaar <Bram@vim.org>
parents:
23477
diff
changeset
|
827 * Skip over white space at "whitep" and assign to "*arg". |
20013
bf377a9ffccb
patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20011
diff
changeset
|
828 * If "*arg" is at the end of the line, advance to the next line. |
20023
c85d4e173cc9
patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents:
20019
diff
changeset
|
829 * Also when "whitep" points to white space and "*arg" is on a "#". |
20013
bf377a9ffccb
patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20011
diff
changeset
|
830 * Return FAIL if beyond the last line, "*arg" is unmodified then. |
bf377a9ffccb
patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20011
diff
changeset
|
831 */ |
26662
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
832 int |
20023
c85d4e173cc9
patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents:
20019
diff
changeset
|
833 may_get_next_line(char_u *whitep, char_u **arg, cctx_T *cctx) |
20013
bf377a9ffccb
patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20011
diff
changeset
|
834 { |
23491
ac5ead954dcd
patch 8.2.2288: Vim9: line break and comment not always skipped
Bram Moolenaar <Bram@vim.org>
parents:
23477
diff
changeset
|
835 *arg = skipwhite(whitep); |
24158
93e69703a290
patch 8.2.2620: Vim9: Using #{ for a dictionary gives strange errors
Bram Moolenaar <Bram@vim.org>
parents:
24154
diff
changeset
|
836 if (vim9_bad_comment(*arg)) |
93e69703a290
patch 8.2.2620: Vim9: Using #{ for a dictionary gives strange errors
Bram Moolenaar <Bram@vim.org>
parents:
24154
diff
changeset
|
837 return FAIL; |
21353
fb8c8fcb7b60
patch 8.2.1227: Vim9: allowing both quoted and # comments is confusing
Bram Moolenaar <Bram@vim.org>
parents:
21345
diff
changeset
|
838 if (**arg == NUL || (VIM_ISWHITE(*whitep) && vim9_comment_start(*arg))) |
20013
bf377a9ffccb
patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20011
diff
changeset
|
839 { |
20955
396fe712eb0f
patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
840 char_u *next = next_line_from_context(cctx, TRUE); |
20013
bf377a9ffccb
patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20011
diff
changeset
|
841 |
bf377a9ffccb
patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20011
diff
changeset
|
842 if (next == NULL) |
bf377a9ffccb
patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20011
diff
changeset
|
843 return FAIL; |
bf377a9ffccb
patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20011
diff
changeset
|
844 *arg = skipwhite(next); |
bf377a9ffccb
patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20011
diff
changeset
|
845 } |
bf377a9ffccb
patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20011
diff
changeset
|
846 return OK; |
bf377a9ffccb
patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20011
diff
changeset
|
847 } |
bf377a9ffccb
patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20011
diff
changeset
|
848 |
21248
4edc60c9c0aa
patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents:
21232
diff
changeset
|
849 /* |
4edc60c9c0aa
patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents:
21232
diff
changeset
|
850 * Idem, and give an error when failed. |
4edc60c9c0aa
patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents:
21232
diff
changeset
|
851 */ |
26662
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
852 int |
21248
4edc60c9c0aa
patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents:
21232
diff
changeset
|
853 may_get_next_line_error(char_u *whitep, char_u **arg, cctx_T *cctx) |
4edc60c9c0aa
patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents:
21232
diff
changeset
|
854 { |
4edc60c9c0aa
patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents:
21232
diff
changeset
|
855 if (may_get_next_line(whitep, arg, cctx) == FAIL) |
4edc60c9c0aa
patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents:
21232
diff
changeset
|
856 { |
23122
60a0221beab0
patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents:
23114
diff
changeset
|
857 SOURCING_LNUM = cctx->ctx_lnum + 1; |
21821
0deb6f96a5a3
patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
21811
diff
changeset
|
858 emsg(_(e_line_incomplete)); |
21248
4edc60c9c0aa
patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents:
21232
diff
changeset
|
859 return FAIL; |
4edc60c9c0aa
patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents:
21232
diff
changeset
|
860 } |
4edc60c9c0aa
patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents:
21232
diff
changeset
|
861 return OK; |
4edc60c9c0aa
patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents:
21232
diff
changeset
|
862 } |
4edc60c9c0aa
patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents:
21232
diff
changeset
|
863 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
864 /* |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
865 * Get a line from the compilation context, compatible with exarg_T getline(). |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
866 * Return a pointer to the line in allocated memory. |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
867 * Return NULL for end-of-file or some error. |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
868 */ |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
869 static char_u * |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
870 exarg_getline( |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
871 int c UNUSED, |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
872 void *cookie, |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
873 int indent UNUSED, |
21883
a427f5f26419
patch 8.2.1491: Vim9: crash when compiling heredoc lines start with comment
Bram Moolenaar <Bram@vim.org>
parents:
21881
diff
changeset
|
874 getline_opt_T options UNUSED) |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
875 { |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
876 cctx_T *cctx = (cctx_T *)cookie; |
21883
a427f5f26419
patch 8.2.1491: Vim9: crash when compiling heredoc lines start with comment
Bram Moolenaar <Bram@vim.org>
parents:
21881
diff
changeset
|
877 char_u *p; |
a427f5f26419
patch 8.2.1491: Vim9: crash when compiling heredoc lines start with comment
Bram Moolenaar <Bram@vim.org>
parents:
21881
diff
changeset
|
878 |
a427f5f26419
patch 8.2.1491: Vim9: crash when compiling heredoc lines start with comment
Bram Moolenaar <Bram@vim.org>
parents:
21881
diff
changeset
|
879 for (;;) |
a427f5f26419
patch 8.2.1491: Vim9: crash when compiling heredoc lines start with comment
Bram Moolenaar <Bram@vim.org>
parents:
21881
diff
changeset
|
880 { |
22423
5b35b477eff0
patch 8.2.1760: Vim9: crash when end marker is missing
Bram Moolenaar <Bram@vim.org>
parents:
22415
diff
changeset
|
881 if (cctx->ctx_lnum >= cctx->ctx_ufunc->uf_lines.ga_len - 1) |
21883
a427f5f26419
patch 8.2.1491: Vim9: crash when compiling heredoc lines start with comment
Bram Moolenaar <Bram@vim.org>
parents:
21881
diff
changeset
|
882 return NULL; |
a427f5f26419
patch 8.2.1491: Vim9: crash when compiling heredoc lines start with comment
Bram Moolenaar <Bram@vim.org>
parents:
21881
diff
changeset
|
883 ++cctx->ctx_lnum; |
a427f5f26419
patch 8.2.1491: Vim9: crash when compiling heredoc lines start with comment
Bram Moolenaar <Bram@vim.org>
parents:
21881
diff
changeset
|
884 p = ((char_u **)cctx->ctx_ufunc->uf_lines.ga_data)[cctx->ctx_lnum]; |
a427f5f26419
patch 8.2.1491: Vim9: crash when compiling heredoc lines start with comment
Bram Moolenaar <Bram@vim.org>
parents:
21881
diff
changeset
|
885 // Comment lines result in NULL pointers, skip them. |
a427f5f26419
patch 8.2.1491: Vim9: crash when compiling heredoc lines start with comment
Bram Moolenaar <Bram@vim.org>
parents:
21881
diff
changeset
|
886 if (p != NULL) |
a427f5f26419
patch 8.2.1491: Vim9: crash when compiling heredoc lines start with comment
Bram Moolenaar <Bram@vim.org>
parents:
21881
diff
changeset
|
887 return vim_strsave(p); |
a427f5f26419
patch 8.2.1491: Vim9: crash when compiling heredoc lines start with comment
Bram Moolenaar <Bram@vim.org>
parents:
21881
diff
changeset
|
888 } |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
889 } |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
890 |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24158
diff
changeset
|
891 void |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24158
diff
changeset
|
892 fill_exarg_from_cctx(exarg_T *eap, cctx_T *cctx) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24158
diff
changeset
|
893 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24158
diff
changeset
|
894 eap->getline = exarg_getline; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24158
diff
changeset
|
895 eap->cookie = cctx; |
28063
b47698ee4a14
patch 8.2.4556: test fails without the +job or +channel feature
Bram Moolenaar <Bram@vim.org>
parents:
28029
diff
changeset
|
896 eap->skip = cctx->ctx_skip == SKIP_YES; |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24158
diff
changeset
|
897 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24158
diff
changeset
|
898 |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
899 /* |
26662
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
900 * Return TRUE if "ufunc" should be compiled, taking into account whether |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
901 * "profile" indicates profiling is to be done. |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
902 */ |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
903 int |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
904 func_needs_compiling(ufunc_T *ufunc, compiletype_T compile_type) |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
905 { |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
906 switch (ufunc->uf_def_status) |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
907 { |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
908 case UF_TO_BE_COMPILED: |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
909 return TRUE; |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
910 |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
911 case UF_COMPILED: |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
912 { |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
913 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data) |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
914 + ufunc->uf_dfunc_idx; |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
915 |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
916 switch (compile_type) |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
917 { |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
918 case CT_PROFILE: |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
919 #ifdef FEAT_PROFILE |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
920 return dfunc->df_instr_prof == NULL; |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
921 #endif |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
922 case CT_NONE: |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
923 return dfunc->df_instr == NULL; |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
924 case CT_DEBUG: |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
925 return dfunc->df_instr_debug == NULL; |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
926 } |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
927 } |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
928 |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
929 case UF_NOT_COMPILED: |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
930 case UF_COMPILE_ERROR: |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
931 case UF_COMPILING: |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
932 break; |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
933 } |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
934 return FALSE; |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
935 } |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
936 |
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
937 /* |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
938 * Compile a nested :def command. |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
939 */ |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
940 static char_u * |
27022
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26980
diff
changeset
|
941 compile_nested_function(exarg_T *eap, cctx_T *cctx, garray_T *lines_to_free) |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
942 { |
21558
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
943 int is_global = *eap->arg == 'g' && eap->arg[1] == ':'; |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
944 char_u *name_start = eap->arg; |
21602
7028f45bf0ea
patch 8.2.1351: Vim9: no proper error if using namespace for nested function
Bram Moolenaar <Bram@vim.org>
parents:
21598
diff
changeset
|
945 char_u *name_end = to_name_end(eap->arg, TRUE); |
26747
a8a4e1e7b111
patch 8.2.3902: Vim9: double free with nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
26729
diff
changeset
|
946 int off; |
a8a4e1e7b111
patch 8.2.3902: Vim9: double free with nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
26729
diff
changeset
|
947 char_u *func_name; |
21598
7b5b9558500a
patch 8.2.1349: Vim9: can define a function with the name of an import
Bram Moolenaar <Bram@vim.org>
parents:
21584
diff
changeset
|
948 char_u *lambda_name; |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
949 ufunc_T *ufunc; |
23291
8e1427ac2bce
patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents:
23289
diff
changeset
|
950 int r = FAIL; |
25230
658dfd6be868
patch 8.2.3151: Vim9: profiling fails if nested function is also profiled
Bram Moolenaar <Bram@vim.org>
parents:
25224
diff
changeset
|
951 compiletype_T compile_type; |
28173
b0c885507de4
patch 8.2.4612: Vim9: cannot use a recursive call in a nested function
Bram Moolenaar <Bram@vim.org>
parents:
28156
diff
changeset
|
952 isn_T *funcref_isn = NULL; |
29763
c0debb5290b5
patch 9.0.0221: accessing freed memory if compiling nested function fails
Bram Moolenaar <Bram@vim.org>
parents:
29668
diff
changeset
|
953 lvar_T *lvar = NULL; |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
954 |
22272
eb1f5f618c75
patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents:
22266
diff
changeset
|
955 if (eap->forceit) |
22216
f9b4576a618b
patch 8.2.1657: Vim9: no proper error for nested ":def!"
Bram Moolenaar <Bram@vim.org>
parents:
22196
diff
changeset
|
956 { |
f9b4576a618b
patch 8.2.1657: Vim9: no proper error for nested ":def!"
Bram Moolenaar <Bram@vim.org>
parents:
22196
diff
changeset
|
957 emsg(_(e_cannot_use_bang_with_nested_def)); |
f9b4576a618b
patch 8.2.1657: Vim9: no proper error for nested ":def!"
Bram Moolenaar <Bram@vim.org>
parents:
22196
diff
changeset
|
958 return NULL; |
f9b4576a618b
patch 8.2.1657: Vim9: no proper error for nested ":def!"
Bram Moolenaar <Bram@vim.org>
parents:
22196
diff
changeset
|
959 } |
f9b4576a618b
patch 8.2.1657: Vim9: no proper error for nested ":def!"
Bram Moolenaar <Bram@vim.org>
parents:
22196
diff
changeset
|
960 |
22973
4c97c0747017
patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents:
22946
diff
changeset
|
961 if (*name_start == '/') |
4c97c0747017
patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents:
22946
diff
changeset
|
962 { |
4c97c0747017
patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents:
22946
diff
changeset
|
963 name_end = skip_regexp(name_start + 1, '/', TRUE); |
4c97c0747017
patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents:
22946
diff
changeset
|
964 if (*name_end == '/') |
4c97c0747017
patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents:
22946
diff
changeset
|
965 ++name_end; |
25521
2063b858cad9
patch 8.2.3297: cannot use all commands inside a {} block
Bram Moolenaar <Bram@vim.org>
parents:
25519
diff
changeset
|
966 set_nextcmd(eap, name_end); |
22973
4c97c0747017
patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents:
22946
diff
changeset
|
967 } |
4c97c0747017
patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents:
22946
diff
changeset
|
968 if (name_end == name_start || *skipwhite(name_end) != '(') |
4c97c0747017
patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents:
22946
diff
changeset
|
969 { |
4c97c0747017
patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents:
22946
diff
changeset
|
970 if (!ends_excmd2(name_start, name_end)) |
4c97c0747017
patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents:
22946
diff
changeset
|
971 { |
27869
6a0ecde89d35
patch 8.2.4460: Vim9: wrong error for defining dict function
Bram Moolenaar <Bram@vim.org>
parents:
27843
diff
changeset
|
972 if (*skipwhite(name_end) == '.') |
6a0ecde89d35
patch 8.2.4460: Vim9: wrong error for defining dict function
Bram Moolenaar <Bram@vim.org>
parents:
27843
diff
changeset
|
973 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:
27843
diff
changeset
|
974 eap->cmd); |
6a0ecde89d35
patch 8.2.4460: Vim9: wrong error for defining dict function
Bram Moolenaar <Bram@vim.org>
parents:
27843
diff
changeset
|
975 else |
6a0ecde89d35
patch 8.2.4460: Vim9: wrong error for defining dict function
Bram Moolenaar <Bram@vim.org>
parents:
27843
diff
changeset
|
976 semsg(_(e_invalid_command_str), eap->cmd); |
22973
4c97c0747017
patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents:
22946
diff
changeset
|
977 return NULL; |
4c97c0747017
patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents:
22946
diff
changeset
|
978 } |
4c97c0747017
patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents:
22946
diff
changeset
|
979 |
4c97c0747017
patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents:
22946
diff
changeset
|
980 // "def" or "def Name": list functions |
4c97c0747017
patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents:
22946
diff
changeset
|
981 if (generate_DEF(cctx, name_start, name_end - name_start) == FAIL) |
4c97c0747017
patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents:
22946
diff
changeset
|
982 return NULL; |
4c97c0747017
patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents:
22946
diff
changeset
|
983 return eap->nextcmd == NULL ? (char_u *)"" : eap->nextcmd; |
4c97c0747017
patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents:
22946
diff
changeset
|
984 } |
4c97c0747017
patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents:
22946
diff
changeset
|
985 |
21602
7028f45bf0ea
patch 8.2.1351: Vim9: no proper error if using namespace for nested function
Bram Moolenaar <Bram@vim.org>
parents:
21598
diff
changeset
|
986 // Only g:Func() can use a namespace. |
7028f45bf0ea
patch 8.2.1351: Vim9: no proper error if using namespace for nested function
Bram Moolenaar <Bram@vim.org>
parents:
21598
diff
changeset
|
987 if (name_start[1] == ':' && !is_global) |
7028f45bf0ea
patch 8.2.1351: Vim9: no proper error if using namespace for nested function
Bram Moolenaar <Bram@vim.org>
parents:
21598
diff
changeset
|
988 { |
21821
0deb6f96a5a3
patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
21811
diff
changeset
|
989 semsg(_(e_namespace_not_supported_str), name_start); |
21602
7028f45bf0ea
patch 8.2.1351: Vim9: no proper error if using namespace for nested function
Bram Moolenaar <Bram@vim.org>
parents:
21598
diff
changeset
|
990 return NULL; |
7028f45bf0ea
patch 8.2.1351: Vim9: no proper error if using namespace for nested function
Bram Moolenaar <Bram@vim.org>
parents:
21598
diff
changeset
|
991 } |
28063
b47698ee4a14
patch 8.2.4556: test fails without the +job or +channel feature
Bram Moolenaar <Bram@vim.org>
parents:
28029
diff
changeset
|
992 if (cctx->ctx_skip != SKIP_YES |
b47698ee4a14
patch 8.2.4556: test fails without the +job or +channel feature
Bram Moolenaar <Bram@vim.org>
parents:
28029
diff
changeset
|
993 && check_defined(name_start, name_end - name_start, cctx, |
27611
e311a80f8cbe
patch 8.2.4332: Vim9: incomplete test for existing script variable in block
Bram Moolenaar <Bram@vim.org>
parents:
27595
diff
changeset
|
994 NULL, FALSE) == FAIL) |
21598
7b5b9558500a
patch 8.2.1349: Vim9: can define a function with the name of an import
Bram Moolenaar <Bram@vim.org>
parents:
21584
diff
changeset
|
995 return NULL; |
27593
8c7836f8668d
patch 8.2.4323: Vim9: nested function name can start with "_"
Bram Moolenaar <Bram@vim.org>
parents:
27575
diff
changeset
|
996 if (!ASCII_ISUPPER(is_global ? name_start[2] : name_start[0])) |
8c7836f8668d
patch 8.2.4323: Vim9: nested function name can start with "_"
Bram Moolenaar <Bram@vim.org>
parents:
27575
diff
changeset
|
997 { |
27595
d504745607bc
patch 8.2.4324: Vim9: script-local function name can start with "_"
Bram Moolenaar <Bram@vim.org>
parents:
27593
diff
changeset
|
998 semsg(_(e_function_name_must_start_with_capital_str), name_start); |
27593
8c7836f8668d
patch 8.2.4323: Vim9: nested function name can start with "_"
Bram Moolenaar <Bram@vim.org>
parents:
27575
diff
changeset
|
999 return NULL; |
8c7836f8668d
patch 8.2.4323: Vim9: nested function name can start with "_"
Bram Moolenaar <Bram@vim.org>
parents:
27575
diff
changeset
|
1000 } |
21598
7b5b9558500a
patch 8.2.1349: Vim9: can define a function with the name of an import
Bram Moolenaar <Bram@vim.org>
parents:
21584
diff
changeset
|
1001 |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
1002 eap->arg = name_end; |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24158
diff
changeset
|
1003 fill_exarg_from_cctx(eap, cctx); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24158
diff
changeset
|
1004 |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
1005 eap->forceit = FALSE; |
26323
3841da4eac23
patch 8.2.3692: Vim9: cannot use :func inside a :def function
Bram Moolenaar <Bram@vim.org>
parents:
26248
diff
changeset
|
1006 // We use the special <Lamba>99 name, but it's not really a lambda. |
23291
8e1427ac2bce
patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents:
23289
diff
changeset
|
1007 lambda_name = vim_strsave(get_lambda_name()); |
8e1427ac2bce
patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents:
23289
diff
changeset
|
1008 if (lambda_name == NULL) |
8e1427ac2bce
patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents:
23289
diff
changeset
|
1009 return NULL; |
26747
a8a4e1e7b111
patch 8.2.3902: Vim9: double free with nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
26729
diff
changeset
|
1010 |
a8a4e1e7b111
patch 8.2.3902: Vim9: double free with nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
26729
diff
changeset
|
1011 // This may free the current line, make a copy of the name. |
a8a4e1e7b111
patch 8.2.3902: Vim9: double free with nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
26729
diff
changeset
|
1012 off = is_global ? 2 : 0; |
a8a4e1e7b111
patch 8.2.3902: Vim9: double free with nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
26729
diff
changeset
|
1013 func_name = vim_strnsave(name_start + off, name_end - name_start - off); |
a8a4e1e7b111
patch 8.2.3902: Vim9: double free with nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
26729
diff
changeset
|
1014 if (func_name == NULL) |
a8a4e1e7b111
patch 8.2.3902: Vim9: double free with nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
26729
diff
changeset
|
1015 { |
a8a4e1e7b111
patch 8.2.3902: Vim9: double free with nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
26729
diff
changeset
|
1016 r = FAIL; |
a8a4e1e7b111
patch 8.2.3902: Vim9: double free with nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
26729
diff
changeset
|
1017 goto theend; |
a8a4e1e7b111
patch 8.2.3902: Vim9: double free with nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
26729
diff
changeset
|
1018 } |
a8a4e1e7b111
patch 8.2.3902: Vim9: double free with nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
26729
diff
changeset
|
1019 |
31596
394967126db9
patch 9.0.1130: unexpected output when autoloading a script
Bram Moolenaar <Bram@vim.org>
parents:
31590
diff
changeset
|
1020 // Make sure "KeyTyped" is not set, it may cause indent to be written. |
394967126db9
patch 9.0.1130: unexpected output when autoloading a script
Bram Moolenaar <Bram@vim.org>
parents:
31590
diff
changeset
|
1021 int save_KeyTyped = KeyTyped; |
394967126db9
patch 9.0.1130: unexpected output when autoloading a script
Bram Moolenaar <Bram@vim.org>
parents:
31590
diff
changeset
|
1022 KeyTyped = FALSE; |
394967126db9
patch 9.0.1130: unexpected output when autoloading a script
Bram Moolenaar <Bram@vim.org>
parents:
31590
diff
changeset
|
1023 |
31635
5c1b7a87466e
patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31616
diff
changeset
|
1024 ufunc = define_function(eap, lambda_name, lines_to_free, 0); |
31596
394967126db9
patch 9.0.1130: unexpected output when autoloading a script
Bram Moolenaar <Bram@vim.org>
parents:
31590
diff
changeset
|
1025 |
394967126db9
patch 9.0.1130: unexpected output when autoloading a script
Bram Moolenaar <Bram@vim.org>
parents:
31590
diff
changeset
|
1026 KeyTyped = save_KeyTyped; |
394967126db9
patch 9.0.1130: unexpected output when autoloading a script
Bram Moolenaar <Bram@vim.org>
parents:
31590
diff
changeset
|
1027 |
20528
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20419
diff
changeset
|
1028 if (ufunc == NULL) |
23291
8e1427ac2bce
patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents:
23289
diff
changeset
|
1029 { |
8e1427ac2bce
patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents:
23289
diff
changeset
|
1030 r = eap->skip ? OK : FAIL; |
8e1427ac2bce
patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents:
23289
diff
changeset
|
1031 goto theend; |
8e1427ac2bce
patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents:
23289
diff
changeset
|
1032 } |
26792
30d8377ea1b1
patch 8.2.3924: Vim9: no error if something follows :enddef
Bram Moolenaar <Bram@vim.org>
parents:
26747
diff
changeset
|
1033 if (eap->nextcmd != NULL) |
30d8377ea1b1
patch 8.2.3924: Vim9: no error if something follows :enddef
Bram Moolenaar <Bram@vim.org>
parents:
26747
diff
changeset
|
1034 { |
30d8377ea1b1
patch 8.2.3924: Vim9: no error if something follows :enddef
Bram Moolenaar <Bram@vim.org>
parents:
26747
diff
changeset
|
1035 semsg(_(e_text_found_after_str_str), |
30d8377ea1b1
patch 8.2.3924: Vim9: no error if something follows :enddef
Bram Moolenaar <Bram@vim.org>
parents:
26747
diff
changeset
|
1036 eap->cmdidx == CMD_def ? "enddef" : "endfunction", eap->nextcmd); |
30d8377ea1b1
patch 8.2.3924: Vim9: no error if something follows :enddef
Bram Moolenaar <Bram@vim.org>
parents:
26747
diff
changeset
|
1037 r = FAIL; |
26845
a6ccb6ec581c
patch 8.2.3951: Vim9: memory leak when text after a nested function
Bram Moolenaar <Bram@vim.org>
parents:
26792
diff
changeset
|
1038 func_ptr_unref(ufunc); |
26792
30d8377ea1b1
patch 8.2.3924: Vim9: no error if something follows :enddef
Bram Moolenaar <Bram@vim.org>
parents:
26747
diff
changeset
|
1039 goto theend; |
30d8377ea1b1
patch 8.2.3924: Vim9: no error if something follows :enddef
Bram Moolenaar <Bram@vim.org>
parents:
26747
diff
changeset
|
1040 } |
24152
c308076e225e
patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents:
24124
diff
changeset
|
1041 |
c308076e225e
patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents:
24124
diff
changeset
|
1042 // copy over the block scope IDs before compiling |
c308076e225e
patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents:
24124
diff
changeset
|
1043 if (!is_global && cctx->ctx_ufunc->uf_block_depth > 0) |
c308076e225e
patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents:
24124
diff
changeset
|
1044 { |
c308076e225e
patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents:
24124
diff
changeset
|
1045 int block_depth = cctx->ctx_ufunc->uf_block_depth; |
c308076e225e
patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents:
24124
diff
changeset
|
1046 |
c308076e225e
patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents:
24124
diff
changeset
|
1047 ufunc->uf_block_ids = ALLOC_MULT(int, block_depth); |
c308076e225e
patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents:
24124
diff
changeset
|
1048 if (ufunc->uf_block_ids != NULL) |
c308076e225e
patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents:
24124
diff
changeset
|
1049 { |
c308076e225e
patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents:
24124
diff
changeset
|
1050 mch_memmove(ufunc->uf_block_ids, cctx->ctx_ufunc->uf_block_ids, |
c308076e225e
patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents:
24124
diff
changeset
|
1051 sizeof(int) * block_depth); |
c308076e225e
patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents:
24124
diff
changeset
|
1052 ufunc->uf_block_depth = block_depth; |
c308076e225e
patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents:
24124
diff
changeset
|
1053 } |
c308076e225e
patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents:
24124
diff
changeset
|
1054 } |
c308076e225e
patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents:
24124
diff
changeset
|
1055 |
28173
b0c885507de4
patch 8.2.4612: Vim9: cannot use a recursive call in a nested function
Bram Moolenaar <Bram@vim.org>
parents:
28156
diff
changeset
|
1056 // Define the funcref before compiling, so that it is found by any |
b0c885507de4
patch 8.2.4612: Vim9: cannot use a recursive call in a nested function
Bram Moolenaar <Bram@vim.org>
parents:
28156
diff
changeset
|
1057 // recursive call. |
b0c885507de4
patch 8.2.4612: Vim9: cannot use a recursive call in a nested function
Bram Moolenaar <Bram@vim.org>
parents:
28156
diff
changeset
|
1058 if (is_global) |
b0c885507de4
patch 8.2.4612: Vim9: cannot use a recursive call in a nested function
Bram Moolenaar <Bram@vim.org>
parents:
28156
diff
changeset
|
1059 { |
30335
bff0506a0911
patch 9.0.0503: build failure
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
1060 r = generate_NEWFUNC(cctx, lambda_name, func_name); |
28173
b0c885507de4
patch 8.2.4612: Vim9: cannot use a recursive call in a nested function
Bram Moolenaar <Bram@vim.org>
parents:
28156
diff
changeset
|
1061 func_name = NULL; |
b0c885507de4
patch 8.2.4612: Vim9: cannot use a recursive call in a nested function
Bram Moolenaar <Bram@vim.org>
parents:
28156
diff
changeset
|
1062 lambda_name = NULL; |
b0c885507de4
patch 8.2.4612: Vim9: cannot use a recursive call in a nested function
Bram Moolenaar <Bram@vim.org>
parents:
28156
diff
changeset
|
1063 } |
b0c885507de4
patch 8.2.4612: Vim9: cannot use a recursive call in a nested function
Bram Moolenaar <Bram@vim.org>
parents:
28156
diff
changeset
|
1064 else |
b0c885507de4
patch 8.2.4612: Vim9: cannot use a recursive call in a nested function
Bram Moolenaar <Bram@vim.org>
parents:
28156
diff
changeset
|
1065 { |
b0c885507de4
patch 8.2.4612: Vim9: cannot use a recursive call in a nested function
Bram Moolenaar <Bram@vim.org>
parents:
28156
diff
changeset
|
1066 // Define a local variable for the function reference. |
29763
c0debb5290b5
patch 9.0.0221: accessing freed memory if compiling nested function fails
Bram Moolenaar <Bram@vim.org>
parents:
29668
diff
changeset
|
1067 lvar = reserve_local(cctx, func_name, name_end - name_start, |
30584
ee039a6049ff
patch 9.0.0627: "const" and "final" both make the type a constant
Bram Moolenaar <Bram@vim.org>
parents:
30576
diff
changeset
|
1068 ASSIGN_CONST, ufunc->uf_func_type); |
28173
b0c885507de4
patch 8.2.4612: Vim9: cannot use a recursive call in a nested function
Bram Moolenaar <Bram@vim.org>
parents:
28156
diff
changeset
|
1069 if (lvar == NULL) |
b0c885507de4
patch 8.2.4612: Vim9: cannot use a recursive call in a nested function
Bram Moolenaar <Bram@vim.org>
parents:
28156
diff
changeset
|
1070 goto theend; |
31920
f1a5e67e9a1b
patch 9.0.1292: :defer may call the wrong method for an object
Bram Moolenaar <Bram@vim.org>
parents:
31867
diff
changeset
|
1071 if (generate_FUNCREF(cctx, ufunc, NULL, 0, &funcref_isn) == FAIL) |
28173
b0c885507de4
patch 8.2.4612: Vim9: cannot use a recursive call in a nested function
Bram Moolenaar <Bram@vim.org>
parents:
28156
diff
changeset
|
1072 goto theend; |
b0c885507de4
patch 8.2.4612: Vim9: cannot use a recursive call in a nested function
Bram Moolenaar <Bram@vim.org>
parents:
28156
diff
changeset
|
1073 r = generate_STORE(cctx, ISN_STORE, lvar->lv_idx, NULL); |
b0c885507de4
patch 8.2.4612: Vim9: cannot use a recursive call in a nested function
Bram Moolenaar <Bram@vim.org>
parents:
28156
diff
changeset
|
1074 } |
b0c885507de4
patch 8.2.4612: Vim9: cannot use a recursive call in a nested function
Bram Moolenaar <Bram@vim.org>
parents:
28156
diff
changeset
|
1075 |
28101
3bc0a639dfb0
patch 8.2.4575: Vim9: test for profiling still fails
Bram Moolenaar <Bram@vim.org>
parents:
28097
diff
changeset
|
1076 compile_type = get_compile_type(ufunc); |
25230
658dfd6be868
patch 8.2.3151: Vim9: profiling fails if nested function is also profiled
Bram Moolenaar <Bram@vim.org>
parents:
25224
diff
changeset
|
1077 #ifdef FEAT_PROFILE |
658dfd6be868
patch 8.2.3151: Vim9: profiling fails if nested function is also profiled
Bram Moolenaar <Bram@vim.org>
parents:
25224
diff
changeset
|
1078 // If the outer function is profiled, also compile the nested function for |
658dfd6be868
patch 8.2.3151: Vim9: profiling fails if nested function is also profiled
Bram Moolenaar <Bram@vim.org>
parents:
25224
diff
changeset
|
1079 // profiling. |
658dfd6be868
patch 8.2.3151: Vim9: profiling fails if nested function is also profiled
Bram Moolenaar <Bram@vim.org>
parents:
25224
diff
changeset
|
1080 if (cctx->ctx_compile_type == CT_PROFILE) |
658dfd6be868
patch 8.2.3151: Vim9: profiling fails if nested function is also profiled
Bram Moolenaar <Bram@vim.org>
parents:
25224
diff
changeset
|
1081 compile_type = CT_PROFILE; |
658dfd6be868
patch 8.2.3151: Vim9: profiling fails if nested function is also profiled
Bram Moolenaar <Bram@vim.org>
parents:
25224
diff
changeset
|
1082 #endif |
658dfd6be868
patch 8.2.3151: Vim9: profiling fails if nested function is also profiled
Bram Moolenaar <Bram@vim.org>
parents:
25224
diff
changeset
|
1083 if (func_needs_compiling(ufunc, compile_type) |
658dfd6be868
patch 8.2.3151: Vim9: profiling fails if nested function is also profiled
Bram Moolenaar <Bram@vim.org>
parents:
25224
diff
changeset
|
1084 && compile_def_function(ufunc, TRUE, compile_type, cctx) == FAIL) |
22369
62192fd08e0e
patch 8.2.1733: Vim9: memory leaks when using nested function
Bram Moolenaar <Bram@vim.org>
parents:
22363
diff
changeset
|
1085 { |
62192fd08e0e
patch 8.2.1733: Vim9: memory leaks when using nested function
Bram Moolenaar <Bram@vim.org>
parents:
22363
diff
changeset
|
1086 func_ptr_unref(ufunc); |
29763
c0debb5290b5
patch 9.0.0221: accessing freed memory if compiling nested function fails
Bram Moolenaar <Bram@vim.org>
parents:
29668
diff
changeset
|
1087 if (lvar != NULL) |
c0debb5290b5
patch 9.0.0221: accessing freed memory if compiling nested function fails
Bram Moolenaar <Bram@vim.org>
parents:
29668
diff
changeset
|
1088 // Now the local variable can't be used. |
c0debb5290b5
patch 9.0.0221: accessing freed memory if compiling nested function fails
Bram Moolenaar <Bram@vim.org>
parents:
29668
diff
changeset
|
1089 *lvar->lv_name = '/'; // impossible value |
23291
8e1427ac2bce
patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents:
23289
diff
changeset
|
1090 goto theend; |
22369
62192fd08e0e
patch 8.2.1733: Vim9: memory leaks when using nested function
Bram Moolenaar <Bram@vim.org>
parents:
22363
diff
changeset
|
1091 } |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
1092 |
25222
fbb530e081ca
patch 8.2.3147: Vim9: profiling does not work with a nested function
Bram Moolenaar <Bram@vim.org>
parents:
25214
diff
changeset
|
1093 #ifdef FEAT_PROFILE |
fbb530e081ca
patch 8.2.3147: Vim9: profiling does not work with a nested function
Bram Moolenaar <Bram@vim.org>
parents:
25214
diff
changeset
|
1094 // When the outer function is compiled for profiling, the nested function |
fbb530e081ca
patch 8.2.3147: Vim9: profiling does not work with a nested function
Bram Moolenaar <Bram@vim.org>
parents:
25214
diff
changeset
|
1095 // may be called without profiling. Compile it here in the right context. |
25230
658dfd6be868
patch 8.2.3151: Vim9: profiling fails if nested function is also profiled
Bram Moolenaar <Bram@vim.org>
parents:
25224
diff
changeset
|
1096 if (compile_type == CT_PROFILE && func_needs_compiling(ufunc, CT_NONE)) |
25222
fbb530e081ca
patch 8.2.3147: Vim9: profiling does not work with a nested function
Bram Moolenaar <Bram@vim.org>
parents:
25214
diff
changeset
|
1097 compile_def_function(ufunc, FALSE, CT_NONE, cctx); |
fbb530e081ca
patch 8.2.3147: Vim9: profiling does not work with a nested function
Bram Moolenaar <Bram@vim.org>
parents:
25214
diff
changeset
|
1098 #endif |
fbb530e081ca
patch 8.2.3147: Vim9: profiling does not work with a nested function
Bram Moolenaar <Bram@vim.org>
parents:
25214
diff
changeset
|
1099 |
28173
b0c885507de4
patch 8.2.4612: Vim9: cannot use a recursive call in a nested function
Bram Moolenaar <Bram@vim.org>
parents:
28156
diff
changeset
|
1100 // If a FUNCREF instruction was generated, set the index after compiling. |
b0c885507de4
patch 8.2.4612: Vim9: cannot use a recursive call in a nested function
Bram Moolenaar <Bram@vim.org>
parents:
28156
diff
changeset
|
1101 if (funcref_isn != NULL && ufunc->uf_def_status == UF_COMPILED) |
b0c885507de4
patch 8.2.4612: Vim9: cannot use a recursive call in a nested function
Bram Moolenaar <Bram@vim.org>
parents:
28156
diff
changeset
|
1102 funcref_isn->isn_arg.funcref.fr_dfunc_idx = ufunc->uf_dfunc_idx; |
23291
8e1427ac2bce
patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents:
23289
diff
changeset
|
1103 |
8e1427ac2bce
patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents:
23289
diff
changeset
|
1104 theend: |
8e1427ac2bce
patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents:
23289
diff
changeset
|
1105 vim_free(lambda_name); |
26747
a8a4e1e7b111
patch 8.2.3902: Vim9: double free with nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
26729
diff
changeset
|
1106 vim_free(func_name); |
21558
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
1107 return r == FAIL ? NULL : (char_u *)""; |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
1108 } |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
1109 |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
1110 /* |
28813
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1111 * Compile one Vim expression {expr} in string "p". |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1112 * "p" points to the opening "{". |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1113 * Return a pointer to the character after "}", NULL for an error. |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1114 */ |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1115 char_u * |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1116 compile_one_expr_in_str(char_u *p, cctx_T *cctx) |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1117 { |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1118 char_u *block_start; |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1119 char_u *block_end; |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1120 |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1121 // Skip the opening {. |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1122 block_start = skipwhite(p + 1); |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1123 block_end = block_start; |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1124 if (*block_start != NUL && skip_expr(&block_end, NULL) == FAIL) |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1125 return NULL; |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1126 block_end = skipwhite(block_end); |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1127 // The block must be closed by a }. |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1128 if (*block_end != '}') |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1129 { |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1130 semsg(_(e_missing_close_curly_str), p); |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1131 return NULL; |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1132 } |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1133 if (compile_expr0(&block_start, cctx) == FAIL) |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1134 return NULL; |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1135 may_generate_2STRING(-1, TRUE, cctx); |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1136 |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1137 return block_end + 1; |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1138 } |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1139 |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1140 /* |
28718
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1141 * Compile a string "str" (either containing a literal string or a mix of |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1142 * literal strings and Vim expressions of the form `{expr}`). This is used |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1143 * when compiling a heredoc assignment to a variable or an interpolated string |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1144 * in a Vim9 def function. Vim9 instructions are generated to push strings, |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1145 * evaluate expressions, concatenate them and create a list of lines. When |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1146 * "evalstr" is TRUE, Vim expressions in "str" are evaluated. |
28560
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28281
diff
changeset
|
1147 */ |
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28281
diff
changeset
|
1148 int |
28718
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1149 compile_all_expr_in_str(char_u *str, int evalstr, cctx_T *cctx) |
28560
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28281
diff
changeset
|
1150 { |
28718
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1151 char_u *p = str; |
28560
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28281
diff
changeset
|
1152 char_u *val; |
28718
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1153 int count = 0; |
28560
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28281
diff
changeset
|
1154 |
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28281
diff
changeset
|
1155 if (cctx->ctx_skip == SKIP_YES) |
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28281
diff
changeset
|
1156 return OK; |
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28281
diff
changeset
|
1157 |
28718
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1158 if (!evalstr || *str == NUL) |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1159 { |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1160 // Literal string, possibly empty. |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1161 val = *str != NUL ? vim_strsave(str) : NULL; |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1162 return generate_PUSHS(cctx, &val); |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1163 } |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1164 |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1165 // Push all the string pieces to the stack, followed by a ISN_CONCAT. |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1166 while (*p != NUL) |
28560
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28281
diff
changeset
|
1167 { |
28718
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1168 char_u *lit_start; |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1169 int escaped_brace = FALSE; |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1170 |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1171 // Look for a block start. |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1172 lit_start = p; |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1173 while (*p != '{' && *p != '}' && *p != NUL) |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1174 ++p; |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1175 |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1176 if (*p != NUL && *p == p[1]) |
28560
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28281
diff
changeset
|
1177 { |
28718
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1178 // Escaped brace, unescape and continue. |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1179 // Include the brace in the literal string. |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1180 ++p; |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1181 escaped_brace = TRUE; |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1182 } |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1183 else if (*p == '}') |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1184 { |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1185 semsg(_(e_stray_closing_curly_str), str); |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1186 return FAIL; |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1187 } |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1188 |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1189 // Append the literal part. |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1190 if (p != lit_start) |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1191 { |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1192 val = vim_strnsave(lit_start, (size_t)(p - lit_start)); |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1193 if (generate_PUSHS(cctx, &val) == FAIL) |
28560
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28281
diff
changeset
|
1194 return FAIL; |
28718
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1195 ++count; |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1196 } |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1197 |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1198 if (*p == NUL) |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1199 break; |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1200 |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1201 if (escaped_brace) |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1202 { |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1203 // Skip the second brace. |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1204 ++p; |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1205 continue; |
28560
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28281
diff
changeset
|
1206 } |
28598
d550054e1328
patch 8.2.4823: concat more than 2 strings in :def function is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28560
diff
changeset
|
1207 |
28813
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1208 p = compile_one_expr_in_str(p, cctx); |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1209 if (p == NULL) |
28718
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1210 return FAIL; |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1211 ++count; |
28560
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28281
diff
changeset
|
1212 } |
28718
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1213 |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1214 // Small optimization, if there's only a single piece skip the ISN_CONCAT. |
28813
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1215 if (count > 1) |
28718
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28694
diff
changeset
|
1216 return generate_CONCAT(cctx, count); |
28560
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28281
diff
changeset
|
1217 |
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28281
diff
changeset
|
1218 return OK; |
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28281
diff
changeset
|
1219 } |
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28281
diff
changeset
|
1220 |
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28281
diff
changeset
|
1221 /* |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1222 * Return the length of an assignment operator, or zero if there isn't one. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1223 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1224 int |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1225 assignment_len(char_u *p, int *heredoc) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1226 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1227 if (*p == '=') |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1228 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1229 if (p[1] == '<' && p[2] == '<') |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1230 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1231 *heredoc = TRUE; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1232 return 3; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1233 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1234 return 1; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1235 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1236 if (vim_strchr((char_u *)"+-*/%", *p) != NULL && p[1] == '=') |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1237 return 2; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1238 if (STRNCMP(p, "..=", 3) == 0) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1239 return 3; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1240 return 0; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1241 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1242 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1243 /* |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
1244 * Generate the load instruction for "name". |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
1245 */ |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
1246 static void |
31483
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31445
diff
changeset
|
1247 generate_loadvar(cctx_T *cctx, lhs_T *lhs) |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
1248 { |
31483
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31445
diff
changeset
|
1249 char_u *name = lhs->lhs_name; |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31445
diff
changeset
|
1250 type_T *type = lhs->lhs_type; |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31445
diff
changeset
|
1251 |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31445
diff
changeset
|
1252 switch (lhs->lhs_dest) |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
1253 { |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
1254 case dest_option: |
26470
ff0310e6f889
patch 8.2.3765: Vim9: cannot use a lambda for 'opfunc' and others
Bram Moolenaar <Bram@vim.org>
parents:
26441
diff
changeset
|
1255 case dest_func_option: |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
1256 generate_LOAD(cctx, ISN_LOADOPT, 0, name, type); |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
1257 break; |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
1258 case dest_global: |
23233
657216220293
patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
1259 if (vim_strchr(name, AUTOLOAD_CHAR) == NULL) |
28129
dd2ed5345f20
patch 8.2.4589: cannot index the g: dictionary
Bram Moolenaar <Bram@vim.org>
parents:
28101
diff
changeset
|
1260 { |
dd2ed5345f20
patch 8.2.4589: cannot index the g: dictionary
Bram Moolenaar <Bram@vim.org>
parents:
28101
diff
changeset
|
1261 if (name[2] == NUL) |
dd2ed5345f20
patch 8.2.4589: cannot index the g: dictionary
Bram Moolenaar <Bram@vim.org>
parents:
28101
diff
changeset
|
1262 generate_instr_type(cctx, ISN_LOADGDICT, &t_dict_any); |
dd2ed5345f20
patch 8.2.4589: cannot index the g: dictionary
Bram Moolenaar <Bram@vim.org>
parents:
28101
diff
changeset
|
1263 else |
dd2ed5345f20
patch 8.2.4589: cannot index the g: dictionary
Bram Moolenaar <Bram@vim.org>
parents:
28101
diff
changeset
|
1264 generate_LOAD(cctx, ISN_LOADG, 0, name + 2, type); |
dd2ed5345f20
patch 8.2.4589: cannot index the g: dictionary
Bram Moolenaar <Bram@vim.org>
parents:
28101
diff
changeset
|
1265 } |
23233
657216220293
patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
1266 else |
657216220293
patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
1267 generate_LOAD(cctx, ISN_LOADAUTO, 0, name, type); |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
1268 break; |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
1269 case dest_buffer: |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
1270 generate_LOAD(cctx, ISN_LOADB, 0, name + 2, type); |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
1271 break; |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
1272 case dest_window: |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
1273 generate_LOAD(cctx, ISN_LOADW, 0, name + 2, type); |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
1274 break; |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
1275 case dest_tab: |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
1276 generate_LOAD(cctx, ISN_LOADT, 0, name + 2, type); |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
1277 break; |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
1278 case dest_script: |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
1279 compile_load_scriptvar(cctx, |
28833
bf013128ccf4
patch 8.2.4940: some code is never used
Bram Moolenaar <Bram@vim.org>
parents:
28813
diff
changeset
|
1280 name + (name[1] == ':' ? 2 : 0), NULL, NULL); |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
1281 break; |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
1282 case dest_env: |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
1283 // Include $ in the name here |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
1284 generate_LOAD(cctx, ISN_LOADENV, 0, name, type); |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
1285 break; |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
1286 case dest_reg: |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
1287 generate_LOAD(cctx, ISN_LOADREG, name[1], NULL, &t_string); |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
1288 break; |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
1289 case dest_vimvar: |
28992
0e9642706a59
patch 8.2.5018: Vim9: some code is not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28901
diff
changeset
|
1290 generate_LOADV(cctx, name + 2); |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
1291 break; |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
1292 case dest_local: |
29769
e0259a817d82
patch 9.0.0224: Using NULL pointer when skipping compiled code
Bram Moolenaar <Bram@vim.org>
parents:
29763
diff
changeset
|
1293 if (cctx->ctx_skip != SKIP_YES) |
e0259a817d82
patch 9.0.0224: Using NULL pointer when skipping compiled code
Bram Moolenaar <Bram@vim.org>
parents:
29763
diff
changeset
|
1294 { |
31483
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31445
diff
changeset
|
1295 lvar_T *lvar = lhs->lhs_lvar; |
29769
e0259a817d82
patch 9.0.0224: Using NULL pointer when skipping compiled code
Bram Moolenaar <Bram@vim.org>
parents:
29763
diff
changeset
|
1296 if (lvar->lv_from_outer > 0) |
e0259a817d82
patch 9.0.0224: Using NULL pointer when skipping compiled code
Bram Moolenaar <Bram@vim.org>
parents:
29763
diff
changeset
|
1297 generate_LOADOUTER(cctx, lvar->lv_idx, lvar->lv_from_outer, |
30335
bff0506a0911
patch 9.0.0503: build failure
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
1298 lvar->lv_loop_depth, lvar->lv_loop_idx, type); |
29769
e0259a817d82
patch 9.0.0224: Using NULL pointer when skipping compiled code
Bram Moolenaar <Bram@vim.org>
parents:
29763
diff
changeset
|
1299 else |
e0259a817d82
patch 9.0.0224: Using NULL pointer when skipping compiled code
Bram Moolenaar <Bram@vim.org>
parents:
29763
diff
changeset
|
1300 generate_LOAD(cctx, ISN_LOAD, lvar->lv_idx, NULL, type); |
e0259a817d82
patch 9.0.0224: Using NULL pointer when skipping compiled code
Bram Moolenaar <Bram@vim.org>
parents:
29763
diff
changeset
|
1301 } |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
1302 break; |
31483
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31445
diff
changeset
|
1303 case dest_class_member: |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31445
diff
changeset
|
1304 generate_CLASSMEMBER(cctx, TRUE, lhs->lhs_class, |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31445
diff
changeset
|
1305 lhs->lhs_classmember_idx); |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31445
diff
changeset
|
1306 break; |
23033
b98003d73150
patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents:
22975
diff
changeset
|
1307 case dest_expr: |
b98003d73150
patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents:
22975
diff
changeset
|
1308 // list or dict value should already be on the stack. |
b98003d73150
patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents:
22975
diff
changeset
|
1309 break; |
b98003d73150
patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents:
22975
diff
changeset
|
1310 } |
b98003d73150
patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents:
22975
diff
changeset
|
1311 } |
b98003d73150
patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents:
22975
diff
changeset
|
1312 |
b98003d73150
patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents:
22975
diff
changeset
|
1313 /* |
b98003d73150
patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents:
22975
diff
changeset
|
1314 * Skip over "[expr]" or ".member". |
b98003d73150
patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents:
22975
diff
changeset
|
1315 * Does not check for any errors. |
b98003d73150
patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents:
22975
diff
changeset
|
1316 */ |
b98003d73150
patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents:
22975
diff
changeset
|
1317 static char_u * |
b98003d73150
patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents:
22975
diff
changeset
|
1318 skip_index(char_u *start) |
b98003d73150
patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents:
22975
diff
changeset
|
1319 { |
b98003d73150
patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents:
22975
diff
changeset
|
1320 char_u *p = start; |
b98003d73150
patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents:
22975
diff
changeset
|
1321 |
b98003d73150
patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents:
22975
diff
changeset
|
1322 if (*p == '[') |
b98003d73150
patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents:
22975
diff
changeset
|
1323 { |
b98003d73150
patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents:
22975
diff
changeset
|
1324 p = skipwhite(p + 1); |
b98003d73150
patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents:
22975
diff
changeset
|
1325 (void)skip_expr(&p, NULL); |
b98003d73150
patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents:
22975
diff
changeset
|
1326 p = skipwhite(p); |
b98003d73150
patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents:
22975
diff
changeset
|
1327 if (*p == ']') |
b98003d73150
patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents:
22975
diff
changeset
|
1328 return p + 1; |
b98003d73150
patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents:
22975
diff
changeset
|
1329 return p; |
b98003d73150
patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents:
22975
diff
changeset
|
1330 } |
b98003d73150
patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents:
22975
diff
changeset
|
1331 // if (*p == '.') |
b98003d73150
patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents:
22975
diff
changeset
|
1332 return to_name_end(p + 1, TRUE); |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
1333 } |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
1334 |
20953
6b4b887a12f0
patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents:
20949
diff
changeset
|
1335 void |
6b4b887a12f0
patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents:
20949
diff
changeset
|
1336 vim9_declare_error(char_u *name) |
6b4b887a12f0
patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents:
20949
diff
changeset
|
1337 { |
6b4b887a12f0
patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents:
20949
diff
changeset
|
1338 char *scope = ""; |
6b4b887a12f0
patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents:
20949
diff
changeset
|
1339 |
6b4b887a12f0
patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents:
20949
diff
changeset
|
1340 switch (*name) |
6b4b887a12f0
patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents:
20949
diff
changeset
|
1341 { |
20961
0e01976dfd3b
patch 8.2.1032: error message for declaring a variable cannot be translated
Bram Moolenaar <Bram@vim.org>
parents:
20955
diff
changeset
|
1342 case 'g': scope = _("global"); break; |
0e01976dfd3b
patch 8.2.1032: error message for declaring a variable cannot be translated
Bram Moolenaar <Bram@vim.org>
parents:
20955
diff
changeset
|
1343 case 'b': scope = _("buffer"); break; |
0e01976dfd3b
patch 8.2.1032: error message for declaring a variable cannot be translated
Bram Moolenaar <Bram@vim.org>
parents:
20955
diff
changeset
|
1344 case 'w': scope = _("window"); break; |
0e01976dfd3b
patch 8.2.1032: error message for declaring a variable cannot be translated
Bram Moolenaar <Bram@vim.org>
parents:
20955
diff
changeset
|
1345 case 't': scope = _("tab"); break; |
0e01976dfd3b
patch 8.2.1032: error message for declaring a variable cannot be translated
Bram Moolenaar <Bram@vim.org>
parents:
20955
diff
changeset
|
1346 case 'v': scope = "v:"; break; |
31602
53c3df37a2b0
patch 9.0.1133: error message names do not match the items
Bram Moolenaar <Bram@vim.org>
parents:
31596
diff
changeset
|
1347 case '$': semsg(_(e_cannot_declare_an_environment_variable_str), name); |
21610
586241ee8096
patch 8.2.1355: Vim9: no error using :let for options and registers
Bram Moolenaar <Bram@vim.org>
parents:
21604
diff
changeset
|
1348 return; |
31602
53c3df37a2b0
patch 9.0.1133: error message names do not match the items
Bram Moolenaar <Bram@vim.org>
parents:
31596
diff
changeset
|
1349 case '&': semsg(_(e_cannot_declare_an_option_str), name); |
21610
586241ee8096
patch 8.2.1355: Vim9: no error using :let for options and registers
Bram Moolenaar <Bram@vim.org>
parents:
21604
diff
changeset
|
1350 return; |
21909
a211bca98bc3
patch 8.2.1504: Vim9: white space checks are only done for a :def function
Bram Moolenaar <Bram@vim.org>
parents:
21903
diff
changeset
|
1351 case '@': semsg(_(e_cannot_declare_a_register_str), name); |
21610
586241ee8096
patch 8.2.1355: Vim9: no error using :let for options and registers
Bram Moolenaar <Bram@vim.org>
parents:
21604
diff
changeset
|
1352 return; |
20961
0e01976dfd3b
patch 8.2.1032: error message for declaring a variable cannot be translated
Bram Moolenaar <Bram@vim.org>
parents:
20955
diff
changeset
|
1353 default: return; |
20953
6b4b887a12f0
patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents:
20949
diff
changeset
|
1354 } |
31602
53c3df37a2b0
patch 9.0.1133: error message names do not match the items
Bram Moolenaar <Bram@vim.org>
parents:
31596
diff
changeset
|
1355 semsg(_(e_cannot_declare_a_scope_variable_str), scope, name); |
20953
6b4b887a12f0
patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents:
20949
diff
changeset
|
1356 } |
6b4b887a12f0
patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents:
20949
diff
changeset
|
1357 |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
1358 /* |
30815
90a257beac7a
patch 9.0.0742: reading past end of the line when compiling a function
Bram Moolenaar <Bram@vim.org>
parents:
30779
diff
changeset
|
1359 * Return TRUE if "name" is a valid register to use. |
90a257beac7a
patch 9.0.0742: reading past end of the line when compiling a function
Bram Moolenaar <Bram@vim.org>
parents:
30779
diff
changeset
|
1360 * Return FALSE and give an error message if not. |
90a257beac7a
patch 9.0.0742: reading past end of the line when compiling a function
Bram Moolenaar <Bram@vim.org>
parents:
30779
diff
changeset
|
1361 */ |
90a257beac7a
patch 9.0.0742: reading past end of the line when compiling a function
Bram Moolenaar <Bram@vim.org>
parents:
30779
diff
changeset
|
1362 static int |
90a257beac7a
patch 9.0.0742: reading past end of the line when compiling a function
Bram Moolenaar <Bram@vim.org>
parents:
30779
diff
changeset
|
1363 valid_dest_reg(int name) |
90a257beac7a
patch 9.0.0742: reading past end of the line when compiling a function
Bram Moolenaar <Bram@vim.org>
parents:
30779
diff
changeset
|
1364 { |
90a257beac7a
patch 9.0.0742: reading past end of the line when compiling a function
Bram Moolenaar <Bram@vim.org>
parents:
30779
diff
changeset
|
1365 if ((name == '@' || valid_yank_reg(name, FALSE)) && name != '.') |
90a257beac7a
patch 9.0.0742: reading past end of the line when compiling a function
Bram Moolenaar <Bram@vim.org>
parents:
30779
diff
changeset
|
1366 return TRUE; |
90a257beac7a
patch 9.0.0742: reading past end of the line when compiling a function
Bram Moolenaar <Bram@vim.org>
parents:
30779
diff
changeset
|
1367 emsg_invreg(name); |
90a257beac7a
patch 9.0.0742: reading past end of the line when compiling a function
Bram Moolenaar <Bram@vim.org>
parents:
30779
diff
changeset
|
1368 return FAIL; |
90a257beac7a
patch 9.0.0742: reading past end of the line when compiling a function
Bram Moolenaar <Bram@vim.org>
parents:
30779
diff
changeset
|
1369 } |
90a257beac7a
patch 9.0.0742: reading past end of the line when compiling a function
Bram Moolenaar <Bram@vim.org>
parents:
30779
diff
changeset
|
1370 |
90a257beac7a
patch 9.0.0742: reading past end of the line when compiling a function
Bram Moolenaar <Bram@vim.org>
parents:
30779
diff
changeset
|
1371 /* |
23054
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1372 * For one assignment figure out the type of destination. Return it in "dest". |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1373 * When not recognized "dest" is not set. |
26441
65ab0b035dd8
patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents:
26404
diff
changeset
|
1374 * For an option "option_scope" is set. |
23054
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1375 * For a v:var "vimvaridx" is set. |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1376 * "type" is set to the destination type if known, unchanted otherwise. |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1377 * Return FAIL if an error message was given. |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1378 */ |
26662
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
1379 int |
23054
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1380 get_var_dest( |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1381 char_u *name, |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1382 assign_dest_T *dest, |
28281
bd1dcc605e58
patch 8.2.4666: Vim9: assignment not recognized in skipped block
Bram Moolenaar <Bram@vim.org>
parents:
28217
diff
changeset
|
1383 cmdidx_T cmdidx, |
26441
65ab0b035dd8
patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents:
26404
diff
changeset
|
1384 int *option_scope, |
23054
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1385 int *vimvaridx, |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1386 type_T **type, |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1387 cctx_T *cctx) |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1388 { |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1389 char_u *p; |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1390 |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1391 if (*name == '&') |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1392 { |
23422
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
23418
diff
changeset
|
1393 int cc; |
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
23418
diff
changeset
|
1394 long numval; |
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
23418
diff
changeset
|
1395 getoption_T opt_type; |
26470
ff0310e6f889
patch 8.2.3765: Vim9: cannot use a lambda for 'opfunc' and others
Bram Moolenaar <Bram@vim.org>
parents:
26441
diff
changeset
|
1396 int opt_p_flags; |
23054
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1397 |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1398 *dest = dest_option; |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1399 if (cmdidx == CMD_final || cmdidx == CMD_const) |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1400 { |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26960
diff
changeset
|
1401 emsg(_(e_cannot_lock_option)); |
23054
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1402 return FAIL; |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1403 } |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1404 p = name; |
26441
65ab0b035dd8
patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents:
26404
diff
changeset
|
1405 p = find_option_end(&p, option_scope); |
23054
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1406 if (p == NULL) |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1407 { |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1408 // cannot happen? |
25064
8f2262c72178
patch 8.2.3069: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
25059
diff
changeset
|
1409 emsg(_(e_unexpected_characters_in_assignment)); |
23054
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1410 return FAIL; |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1411 } |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1412 cc = *p; |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1413 *p = NUL; |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1414 opt_type = get_option_value(skip_option_env_lead(name), |
26470
ff0310e6f889
patch 8.2.3765: Vim9: cannot use a lambda for 'opfunc' and others
Bram Moolenaar <Bram@vim.org>
parents:
26441
diff
changeset
|
1415 &numval, NULL, &opt_p_flags, *option_scope); |
23054
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1416 *p = cc; |
23422
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
23418
diff
changeset
|
1417 switch (opt_type) |
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
23418
diff
changeset
|
1418 { |
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
23418
diff
changeset
|
1419 case gov_unknown: |
26602
fac6673086df
patch 8.2.3830: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26594
diff
changeset
|
1420 semsg(_(e_unknown_option_str), name); |
23422
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
23418
diff
changeset
|
1421 return FAIL; |
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
23418
diff
changeset
|
1422 case gov_string: |
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
23418
diff
changeset
|
1423 case gov_hidden_string: |
26470
ff0310e6f889
patch 8.2.3765: Vim9: cannot use a lambda for 'opfunc' and others
Bram Moolenaar <Bram@vim.org>
parents:
26441
diff
changeset
|
1424 if (opt_p_flags & P_FUNC) |
ff0310e6f889
patch 8.2.3765: Vim9: cannot use a lambda for 'opfunc' and others
Bram Moolenaar <Bram@vim.org>
parents:
26441
diff
changeset
|
1425 { |
ff0310e6f889
patch 8.2.3765: Vim9: cannot use a lambda for 'opfunc' and others
Bram Moolenaar <Bram@vim.org>
parents:
26441
diff
changeset
|
1426 // might be a Funcref, check the type later |
ff0310e6f889
patch 8.2.3765: Vim9: cannot use a lambda for 'opfunc' and others
Bram Moolenaar <Bram@vim.org>
parents:
26441
diff
changeset
|
1427 *type = &t_any; |
ff0310e6f889
patch 8.2.3765: Vim9: cannot use a lambda for 'opfunc' and others
Bram Moolenaar <Bram@vim.org>
parents:
26441
diff
changeset
|
1428 *dest = dest_func_option; |
ff0310e6f889
patch 8.2.3765: Vim9: cannot use a lambda for 'opfunc' and others
Bram Moolenaar <Bram@vim.org>
parents:
26441
diff
changeset
|
1429 } |
ff0310e6f889
patch 8.2.3765: Vim9: cannot use a lambda for 'opfunc' and others
Bram Moolenaar <Bram@vim.org>
parents:
26441
diff
changeset
|
1430 else |
ff0310e6f889
patch 8.2.3765: Vim9: cannot use a lambda for 'opfunc' and others
Bram Moolenaar <Bram@vim.org>
parents:
26441
diff
changeset
|
1431 { |
ff0310e6f889
patch 8.2.3765: Vim9: cannot use a lambda for 'opfunc' and others
Bram Moolenaar <Bram@vim.org>
parents:
26441
diff
changeset
|
1432 *type = &t_string; |
ff0310e6f889
patch 8.2.3765: Vim9: cannot use a lambda for 'opfunc' and others
Bram Moolenaar <Bram@vim.org>
parents:
26441
diff
changeset
|
1433 } |
23422
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
23418
diff
changeset
|
1434 break; |
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
23418
diff
changeset
|
1435 case gov_bool: |
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
23418
diff
changeset
|
1436 case gov_hidden_bool: |
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
23418
diff
changeset
|
1437 *type = &t_bool; |
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
23418
diff
changeset
|
1438 break; |
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
23418
diff
changeset
|
1439 case gov_number: |
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
23418
diff
changeset
|
1440 case gov_hidden_number: |
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
23418
diff
changeset
|
1441 *type = &t_number; |
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
23418
diff
changeset
|
1442 break; |
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
23418
diff
changeset
|
1443 } |
23054
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1444 } |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1445 else if (*name == '$') |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1446 { |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1447 *dest = dest_env; |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1448 *type = &t_string; |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1449 } |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1450 else if (*name == '@') |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1451 { |
30815
90a257beac7a
patch 9.0.0742: reading past end of the line when compiling a function
Bram Moolenaar <Bram@vim.org>
parents:
30779
diff
changeset
|
1452 if (!valid_dest_reg(name[1])) |
23054
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1453 return FAIL; |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1454 *dest = dest_reg; |
24956
d0b6a8d82cef
patch 8.2.3015: Vim9: Assigning to @# requires a string
Bram Moolenaar <Bram@vim.org>
parents:
24948
diff
changeset
|
1455 *type = name[1] == '#' ? &t_number_or_string : &t_string; |
23054
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1456 } |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1457 else if (STRNCMP(name, "g:", 2) == 0) |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1458 { |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1459 *dest = dest_global; |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1460 } |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1461 else if (STRNCMP(name, "b:", 2) == 0) |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1462 { |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1463 *dest = dest_buffer; |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1464 } |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1465 else if (STRNCMP(name, "w:", 2) == 0) |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1466 { |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1467 *dest = dest_window; |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1468 } |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1469 else if (STRNCMP(name, "t:", 2) == 0) |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1470 { |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1471 *dest = dest_tab; |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1472 } |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1473 else if (STRNCMP(name, "v:", 2) == 0) |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1474 { |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1475 typval_T *vtv; |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1476 int di_flags; |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1477 |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1478 *vimvaridx = find_vim_var(name + 2, &di_flags); |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1479 if (*vimvaridx < 0) |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1480 { |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1481 semsg(_(e_variable_not_found_str), name); |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1482 return FAIL; |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1483 } |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1484 // We use the current value of "sandbox" here, is that OK? |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1485 if (var_check_ro(di_flags, name, FALSE)) |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1486 return FAIL; |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1487 *dest = dest_vimvar; |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1488 vtv = get_vim_var_tv(*vimvaridx); |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1489 *type = typval2type_vimvar(vtv, cctx->ctx_type_list); |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1490 } |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1491 return OK; |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1492 } |
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
1493 |
24490
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24488
diff
changeset
|
1494 static int |
28281
bd1dcc605e58
patch 8.2.4666: Vim9: assignment not recognized in skipped block
Bram Moolenaar <Bram@vim.org>
parents:
28217
diff
changeset
|
1495 is_decl_command(cmdidx_T cmdidx) |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1496 { |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1497 return cmdidx == CMD_let || cmdidx == CMD_var |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1498 || cmdidx == CMD_final || cmdidx == CMD_const; |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1499 } |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1500 |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1501 /* |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1502 * Figure out the LHS type and other properties for an assignment or one item |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1503 * of ":unlet" with an index. |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1504 * Returns OK or FAIL. |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1505 */ |
26662
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
1506 int |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1507 compile_lhs( |
28281
bd1dcc605e58
patch 8.2.4666: Vim9: assignment not recognized in skipped block
Bram Moolenaar <Bram@vim.org>
parents:
28217
diff
changeset
|
1508 char_u *var_start, |
bd1dcc605e58
patch 8.2.4666: Vim9: assignment not recognized in skipped block
Bram Moolenaar <Bram@vim.org>
parents:
28217
diff
changeset
|
1509 lhs_T *lhs, |
bd1dcc605e58
patch 8.2.4666: Vim9: assignment not recognized in skipped block
Bram Moolenaar <Bram@vim.org>
parents:
28217
diff
changeset
|
1510 cmdidx_T cmdidx, |
bd1dcc605e58
patch 8.2.4666: Vim9: assignment not recognized in skipped block
Bram Moolenaar <Bram@vim.org>
parents:
28217
diff
changeset
|
1511 int heredoc, |
bd1dcc605e58
patch 8.2.4666: Vim9: assignment not recognized in skipped block
Bram Moolenaar <Bram@vim.org>
parents:
28217
diff
changeset
|
1512 int has_cmd, // "var" before "var_start" |
bd1dcc605e58
patch 8.2.4666: Vim9: assignment not recognized in skipped block
Bram Moolenaar <Bram@vim.org>
parents:
28217
diff
changeset
|
1513 int oplen, |
bd1dcc605e58
patch 8.2.4666: Vim9: assignment not recognized in skipped block
Bram Moolenaar <Bram@vim.org>
parents:
28217
diff
changeset
|
1514 cctx_T *cctx) |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1515 { |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1516 char_u *var_end; |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1517 int is_decl = is_decl_command(cmdidx); |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1518 |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1519 CLEAR_POINTER(lhs); |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1520 lhs->lhs_dest = dest_local; |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1521 lhs->lhs_vimvaridx = -1; |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1522 lhs->lhs_scriptvar_idx = -1; |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
1523 lhs->lhs_member_idx = -1; |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1524 |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1525 // "dest_end" is the end of the destination, including "[expr]" or |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1526 // ".name". |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1527 // "var_end" is the end of the variable/option/etc. name. |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1528 lhs->lhs_dest_end = skip_var_one(var_start, FALSE); |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1529 if (*var_start == '@') |
30815
90a257beac7a
patch 9.0.0742: reading past end of the line when compiling a function
Bram Moolenaar <Bram@vim.org>
parents:
30779
diff
changeset
|
1530 { |
90a257beac7a
patch 9.0.0742: reading past end of the line when compiling a function
Bram Moolenaar <Bram@vim.org>
parents:
30779
diff
changeset
|
1531 if (!valid_dest_reg(var_start[1])) |
90a257beac7a
patch 9.0.0742: reading past end of the line when compiling a function
Bram Moolenaar <Bram@vim.org>
parents:
30779
diff
changeset
|
1532 return FAIL; |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1533 var_end = var_start + 2; |
30815
90a257beac7a
patch 9.0.0742: reading past end of the line when compiling a function
Bram Moolenaar <Bram@vim.org>
parents:
30779
diff
changeset
|
1534 } |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1535 else |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1536 { |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1537 // skip over the leading "&", "&l:", "&g:" and "$" |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1538 var_end = skip_option_env_lead(var_start); |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1539 var_end = to_name_end(var_end, TRUE); |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1540 } |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1541 |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1542 // "a: type" is declaring variable "a" with a type, not dict "a:". |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1543 if (is_decl && lhs->lhs_dest_end == var_start + 2 |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1544 && lhs->lhs_dest_end[-1] == ':') |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1545 --lhs->lhs_dest_end; |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1546 if (is_decl && var_end == var_start + 2 && var_end[-1] == ':') |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1547 --var_end; |
26346
8be6413a8e27
patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
26340
diff
changeset
|
1548 lhs->lhs_end = lhs->lhs_dest_end; |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1549 |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1550 // compute the length of the destination without "[expr]" or ".name" |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1551 lhs->lhs_varlen = var_end - var_start; |
24512
53871095bb65
patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents:
24510
diff
changeset
|
1552 lhs->lhs_varlen_total = lhs->lhs_varlen; |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1553 lhs->lhs_name = vim_strnsave(var_start, lhs->lhs_varlen); |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1554 if (lhs->lhs_name == NULL) |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1555 return FAIL; |
23578
85ce241ff9e3
patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents:
23576
diff
changeset
|
1556 |
85ce241ff9e3
patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents:
23576
diff
changeset
|
1557 if (lhs->lhs_dest_end > var_start + lhs->lhs_varlen) |
85ce241ff9e3
patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents:
23576
diff
changeset
|
1558 // Something follows after the variable: "var[idx]" or "var.key". |
85ce241ff9e3
patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents:
23576
diff
changeset
|
1559 lhs->lhs_has_index = TRUE; |
85ce241ff9e3
patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents:
23576
diff
changeset
|
1560 |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1561 if (heredoc) |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1562 lhs->lhs_type = &t_list_string; |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1563 else |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1564 lhs->lhs_type = &t_any; |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1565 |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1566 if (cctx->ctx_skip != SKIP_YES) |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1567 { |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1568 int declare_error = FALSE; |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1569 |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1570 if (get_var_dest(lhs->lhs_name, &lhs->lhs_dest, cmdidx, |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1571 &lhs->lhs_opt_flags, &lhs->lhs_vimvaridx, |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1572 &lhs->lhs_type, cctx) == FAIL) |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1573 return FAIL; |
24293
bbf4b3185554
patch 8.2.2687: Vim9: cannot use "const" for global variable in :def function
Bram Moolenaar <Bram@vim.org>
parents:
24283
diff
changeset
|
1574 if (lhs->lhs_dest != dest_local |
bbf4b3185554
patch 8.2.2687: Vim9: cannot use "const" for global variable in :def function
Bram Moolenaar <Bram@vim.org>
parents:
24283
diff
changeset
|
1575 && cmdidx != CMD_const && cmdidx != CMD_final) |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1576 { |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1577 // Specific kind of variable recognized. |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1578 declare_error = is_decl; |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1579 } |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1580 else |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1581 { |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1582 // No specific kind of variable recognized, just a name. |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
1583 if (check_reserved_name(lhs->lhs_name, cctx) == FAIL) |
24717
bf8feac8a89a
patch 8.2.2897: Vim9: can use reserved words at the script level
Bram Moolenaar <Bram@vim.org>
parents:
24713
diff
changeset
|
1584 return FAIL; |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1585 |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1586 if (lookup_local(var_start, lhs->lhs_varlen, |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1587 &lhs->lhs_local_lvar, cctx) == OK) |
31483
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31445
diff
changeset
|
1588 { |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1589 lhs->lhs_lvar = &lhs->lhs_local_lvar; |
31483
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31445
diff
changeset
|
1590 } |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1591 else |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1592 { |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1593 CLEAR_FIELD(lhs->lhs_arg_lvar); |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1594 if (arg_exists(var_start, lhs->lhs_varlen, |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1595 &lhs->lhs_arg_lvar.lv_idx, &lhs->lhs_arg_lvar.lv_type, |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1596 &lhs->lhs_arg_lvar.lv_from_outer, cctx) == OK) |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1597 { |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1598 if (is_decl) |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1599 { |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1600 semsg(_(e_str_is_used_as_argument), lhs->lhs_name); |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1601 return FAIL; |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1602 } |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1603 lhs->lhs_lvar = &lhs->lhs_arg_lvar; |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1604 } |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1605 } |
31483
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31445
diff
changeset
|
1606 |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1607 if (lhs->lhs_lvar != NULL) |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1608 { |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1609 if (is_decl) |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1610 { |
31602
53c3df37a2b0
patch 9.0.1133: error message names do not match the items
Bram Moolenaar <Bram@vim.org>
parents:
31596
diff
changeset
|
1611 semsg(_(e_variable_already_declared_str), lhs->lhs_name); |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1612 return FAIL; |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1613 } |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1614 } |
31483
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31445
diff
changeset
|
1615 else if ((lhs->lhs_classmember_idx = class_member_index( |
31590
aee868b9229a
patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents:
31551
diff
changeset
|
1616 var_start, lhs->lhs_varlen, NULL, cctx)) >= 0) |
31483
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31445
diff
changeset
|
1617 { |
31590
aee868b9229a
patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents:
31551
diff
changeset
|
1618 if (is_decl) |
aee868b9229a
patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents:
31551
diff
changeset
|
1619 { |
aee868b9229a
patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents:
31551
diff
changeset
|
1620 semsg(_(e_variable_already_declared_in_class_str), |
aee868b9229a
patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents:
31551
diff
changeset
|
1621 lhs->lhs_name); |
aee868b9229a
patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents:
31551
diff
changeset
|
1622 return FAIL; |
aee868b9229a
patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents:
31551
diff
changeset
|
1623 } |
31483
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31445
diff
changeset
|
1624 lhs->lhs_dest = dest_class_member; |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31445
diff
changeset
|
1625 lhs->lhs_class = cctx->ctx_ufunc->uf_class; |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31445
diff
changeset
|
1626 } |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1627 else |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1628 { |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1629 int script_namespace = lhs->lhs_varlen > 1 |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1630 && STRNCMP(var_start, "s:", 2) == 0; |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1631 int script_var = (script_namespace |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1632 ? script_var_exists(var_start + 2, lhs->lhs_varlen - 2, |
27611
e311a80f8cbe
patch 8.2.4332: Vim9: incomplete test for existing script variable in block
Bram Moolenaar <Bram@vim.org>
parents:
27595
diff
changeset
|
1633 cctx, NULL) |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1634 : script_var_exists(var_start, lhs->lhs_varlen, |
27611
e311a80f8cbe
patch 8.2.4332: Vim9: incomplete test for existing script variable in block
Bram Moolenaar <Bram@vim.org>
parents:
27595
diff
changeset
|
1635 cctx, NULL)) == OK; |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1636 imported_T *import = |
27698
3813036f19cb
patch 8.2.4375: ctx_imports is not used
Bram Moolenaar <Bram@vim.org>
parents:
27696
diff
changeset
|
1637 find_imported(var_start, lhs->lhs_varlen, FALSE); |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1638 |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1639 if (script_namespace || script_var || import != NULL) |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1640 { |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1641 char_u *rawname = lhs->lhs_name |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1642 + (lhs->lhs_name[1] == ':' ? 2 : 0); |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1643 |
27843
532a0c5de1ec
patch 8.2.4447: Vim9: can still use s:var in a compiled function
Bram Moolenaar <Bram@vim.org>
parents:
27800
diff
changeset
|
1644 if (script_namespace && current_script_is_vim9()) |
532a0c5de1ec
patch 8.2.4447: Vim9: can still use s:var in a compiled function
Bram Moolenaar <Bram@vim.org>
parents:
27800
diff
changeset
|
1645 { |
532a0c5de1ec
patch 8.2.4447: Vim9: can still use s:var in a compiled function
Bram Moolenaar <Bram@vim.org>
parents:
27800
diff
changeset
|
1646 semsg(_(e_cannot_use_s_colon_in_vim9_script_str), |
532a0c5de1ec
patch 8.2.4447: Vim9: can still use s:var in a compiled function
Bram Moolenaar <Bram@vim.org>
parents:
27800
diff
changeset
|
1647 var_start); |
532a0c5de1ec
patch 8.2.4447: Vim9: can still use s:var in a compiled function
Bram Moolenaar <Bram@vim.org>
parents:
27800
diff
changeset
|
1648 return FAIL; |
532a0c5de1ec
patch 8.2.4447: Vim9: can still use s:var in a compiled function
Bram Moolenaar <Bram@vim.org>
parents:
27800
diff
changeset
|
1649 } |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1650 if (is_decl) |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1651 { |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1652 if (script_namespace) |
27669
5c4ab8d4472c
patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents:
27613
diff
changeset
|
1653 semsg(_(e_cannot_declare_script_variable_in_function_str), |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1654 lhs->lhs_name); |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1655 else |
24033
308d29307910
patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents:
23996
diff
changeset
|
1656 semsg(_(e_variable_already_declared_in_script_str), |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1657 lhs->lhs_name); |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1658 return FAIL; |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1659 } |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1660 else if (cctx->ctx_ufunc->uf_script_ctx_version |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1661 == SCRIPT_VERSION_VIM9 |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1662 && script_namespace |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1663 && !script_var && import == NULL) |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1664 { |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1665 semsg(_(e_unknown_variable_str), lhs->lhs_name); |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1666 return FAIL; |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1667 } |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1668 |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1669 lhs->lhs_dest = dest_script; |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1670 |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1671 // existing script-local variables should have a type |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1672 lhs->lhs_scriptvar_sid = current_sctx.sc_sid; |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1673 if (import != NULL) |
26980
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26974
diff
changeset
|
1674 { |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26974
diff
changeset
|
1675 char_u *dot = vim_strchr(var_start, '.'); |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26974
diff
changeset
|
1676 char_u *p; |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26974
diff
changeset
|
1677 |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26974
diff
changeset
|
1678 // for an import the name is what comes after the dot |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26974
diff
changeset
|
1679 if (dot == NULL) |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26974
diff
changeset
|
1680 { |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26974
diff
changeset
|
1681 semsg(_(e_no_dot_after_imported_name_str), |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26974
diff
changeset
|
1682 var_start); |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26974
diff
changeset
|
1683 return FAIL; |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26974
diff
changeset
|
1684 } |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26974
diff
changeset
|
1685 p = skipwhite(dot + 1); |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26974
diff
changeset
|
1686 var_end = to_name_end(p, TRUE); |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26974
diff
changeset
|
1687 if (var_end == p) |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26974
diff
changeset
|
1688 { |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26974
diff
changeset
|
1689 semsg(_(e_missing_name_after_imported_name_str), |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26974
diff
changeset
|
1690 var_start); |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26974
diff
changeset
|
1691 return FAIL; |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26974
diff
changeset
|
1692 } |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26974
diff
changeset
|
1693 vim_free(lhs->lhs_name); |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26974
diff
changeset
|
1694 lhs->lhs_varlen = var_end - p; |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26974
diff
changeset
|
1695 lhs->lhs_name = vim_strnsave(p, lhs->lhs_varlen); |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26974
diff
changeset
|
1696 if (lhs->lhs_name == NULL) |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26974
diff
changeset
|
1697 return FAIL; |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26974
diff
changeset
|
1698 rawname = lhs->lhs_name; |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1699 lhs->lhs_scriptvar_sid = import->imp_sid; |
26980
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26974
diff
changeset
|
1700 // TODO: where do we check this name is exported? |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26974
diff
changeset
|
1701 |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26974
diff
changeset
|
1702 // Check if something follows: "exp.var[idx]" or |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26974
diff
changeset
|
1703 // "exp.var.key". |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26974
diff
changeset
|
1704 lhs->lhs_has_index = lhs->lhs_dest_end |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26974
diff
changeset
|
1705 > skipwhite(var_end); |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26974
diff
changeset
|
1706 } |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1707 if (SCRIPT_ID_VALID(lhs->lhs_scriptvar_sid)) |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1708 { |
23578
85ce241ff9e3
patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents:
23576
diff
changeset
|
1709 // Check writable only when no index follows. |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1710 lhs->lhs_scriptvar_idx = get_script_item_idx( |
23578
85ce241ff9e3
patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents:
23576
diff
changeset
|
1711 lhs->lhs_scriptvar_sid, rawname, |
85ce241ff9e3
patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents:
23576
diff
changeset
|
1712 lhs->lhs_has_index ? ASSIGN_FINAL : ASSIGN_CONST, |
27613
42d0279c6e7c
patch 8.2.4333: cstack not always passed to where it is needed
Bram Moolenaar <Bram@vim.org>
parents:
27611
diff
changeset
|
1713 cctx, NULL); |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1714 if (lhs->lhs_scriptvar_idx >= 0) |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1715 { |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1716 scriptitem_T *si = SCRIPT_ITEM( |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1717 lhs->lhs_scriptvar_sid); |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1718 svar_T *sv = |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1719 ((svar_T *)si->sn_var_vals.ga_data) |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1720 + lhs->lhs_scriptvar_idx; |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1721 lhs->lhs_type = sv->sv_type; |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1722 } |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1723 } |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1724 } |
27611
e311a80f8cbe
patch 8.2.4332: Vim9: incomplete test for existing script variable in block
Bram Moolenaar <Bram@vim.org>
parents:
27595
diff
changeset
|
1725 else if (check_defined(var_start, lhs->lhs_varlen, cctx, |
e311a80f8cbe
patch 8.2.4332: Vim9: incomplete test for existing script variable in block
Bram Moolenaar <Bram@vim.org>
parents:
27595
diff
changeset
|
1726 NULL, FALSE) == FAIL) |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1727 return FAIL; |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1728 } |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1729 } |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1730 |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1731 if (declare_error) |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1732 { |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1733 vim9_declare_error(lhs->lhs_name); |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1734 return FAIL; |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1735 } |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1736 } |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1737 |
26346
8be6413a8e27
patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
26340
diff
changeset
|
1738 // handle "a:name" as a name, not index "name" in "a" |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1739 if (lhs->lhs_varlen > 1 || var_start[lhs->lhs_varlen] != ':') |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1740 var_end = lhs->lhs_dest_end; |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1741 |
26470
ff0310e6f889
patch 8.2.3765: Vim9: cannot use a lambda for 'opfunc' and others
Bram Moolenaar <Bram@vim.org>
parents:
26441
diff
changeset
|
1742 if (lhs->lhs_dest != dest_option && lhs->lhs_dest != dest_func_option) |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1743 { |
31867
7d505d77f6da
patch 9.0.1266: error for space before ": type" is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
31865
diff
changeset
|
1744 if (is_decl && *skipwhite(var_end) == ':') |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1745 { |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1746 char_u *p; |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1747 |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1748 // parse optional type: "let var: type = expr" |
31867
7d505d77f6da
patch 9.0.1266: error for space before ": type" is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
31865
diff
changeset
|
1749 if (VIM_ISWHITE(*var_end)) |
7d505d77f6da
patch 9.0.1266: error for space before ": type" is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
31865
diff
changeset
|
1750 { |
7d505d77f6da
patch 9.0.1266: error for space before ": type" is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
31865
diff
changeset
|
1751 semsg(_(e_no_white_space_allowed_before_colon_str), var_end); |
7d505d77f6da
patch 9.0.1266: error for space before ": type" is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
31865
diff
changeset
|
1752 return FAIL; |
7d505d77f6da
patch 9.0.1266: error for space before ": type" is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
31865
diff
changeset
|
1753 } |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1754 if (!VIM_ISWHITE(var_end[1])) |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1755 { |
23877
85cf06ddb2a8
patch 8.2.2480: Vim9: some errors for white space do not show context
Bram Moolenaar <Bram@vim.org>
parents:
23837
diff
changeset
|
1756 semsg(_(e_white_space_required_after_str_str), ":", var_end); |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1757 return FAIL; |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1758 } |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1759 p = skipwhite(var_end + 1); |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1760 lhs->lhs_type = parse_type(&p, cctx->ctx_type_list, TRUE); |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1761 if (lhs->lhs_type == NULL) |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1762 return FAIL; |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1763 lhs->lhs_has_type = TRUE; |
26346
8be6413a8e27
patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
26340
diff
changeset
|
1764 lhs->lhs_end = p; |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1765 } |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1766 else if (lhs->lhs_lvar != NULL) |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1767 lhs->lhs_type = lhs->lhs_lvar->lv_type; |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1768 } |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1769 |
24357
108a6e2497f6
patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24339
diff
changeset
|
1770 if (oplen == 3 && !heredoc |
108a6e2497f6
patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24339
diff
changeset
|
1771 && lhs->lhs_dest != dest_global |
108a6e2497f6
patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24339
diff
changeset
|
1772 && !lhs->lhs_has_index |
108a6e2497f6
patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24339
diff
changeset
|
1773 && lhs->lhs_type->tt_type != VAR_STRING |
108a6e2497f6
patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24339
diff
changeset
|
1774 && lhs->lhs_type->tt_type != VAR_ANY) |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1775 { |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1776 emsg(_(e_can_only_concatenate_to_string)); |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1777 return FAIL; |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1778 } |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1779 |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1780 if (lhs->lhs_lvar == NULL && lhs->lhs_dest == dest_local |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1781 && cctx->ctx_skip != SKIP_YES) |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1782 { |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1783 if (oplen > 1 && !heredoc) |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1784 { |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1785 // +=, /=, etc. require an existing variable |
31602
53c3df37a2b0
patch 9.0.1133: error message names do not match the items
Bram Moolenaar <Bram@vim.org>
parents:
31596
diff
changeset
|
1786 semsg(_(e_cannot_use_operator_on_new_variable_str), lhs->lhs_name); |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1787 return FAIL; |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1788 } |
28281
bd1dcc605e58
patch 8.2.4666: Vim9: assignment not recognized in skipped block
Bram Moolenaar <Bram@vim.org>
parents:
28217
diff
changeset
|
1789 if (!is_decl || (lhs->lhs_has_index && !has_cmd |
bd1dcc605e58
patch 8.2.4666: Vim9: assignment not recognized in skipped block
Bram Moolenaar <Bram@vim.org>
parents:
28217
diff
changeset
|
1790 && cctx->ctx_skip != SKIP_YES)) |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1791 { |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1792 semsg(_(e_unknown_variable_str), lhs->lhs_name); |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1793 return FAIL; |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1794 } |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1795 |
24154
6e8f49a4a193
patch 8.2.2618: Vim9: cannot use a normal list name to store function refs
Bram Moolenaar <Bram@vim.org>
parents:
24152
diff
changeset
|
1796 // Check the name is valid for a funcref. |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1797 if ((lhs->lhs_type->tt_type == VAR_FUNC |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1798 || lhs->lhs_type->tt_type == VAR_PARTIAL) |
24154
6e8f49a4a193
patch 8.2.2618: Vim9: cannot use a normal list name to store function refs
Bram Moolenaar <Bram@vim.org>
parents:
24152
diff
changeset
|
1799 && var_wrong_func_name(lhs->lhs_name, TRUE)) |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1800 return FAIL; |
24154
6e8f49a4a193
patch 8.2.2618: Vim9: cannot use a normal list name to store function refs
Bram Moolenaar <Bram@vim.org>
parents:
24152
diff
changeset
|
1801 |
6e8f49a4a193
patch 8.2.2618: Vim9: cannot use a normal list name to store function refs
Bram Moolenaar <Bram@vim.org>
parents:
24152
diff
changeset
|
1802 // New local variable. |
30584
ee039a6049ff
patch 9.0.0627: "const" and "final" both make the type a constant
Bram Moolenaar <Bram@vim.org>
parents:
30576
diff
changeset
|
1803 int assign = cmdidx == CMD_final ? ASSIGN_FINAL |
ee039a6049ff
patch 9.0.0627: "const" and "final" both make the type a constant
Bram Moolenaar <Bram@vim.org>
parents:
30576
diff
changeset
|
1804 : cmdidx == CMD_const ? ASSIGN_CONST : ASSIGN_VAR; |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1805 lhs->lhs_lvar = reserve_local(cctx, var_start, lhs->lhs_varlen, |
30584
ee039a6049ff
patch 9.0.0627: "const" and "final" both make the type a constant
Bram Moolenaar <Bram@vim.org>
parents:
30576
diff
changeset
|
1806 assign, lhs->lhs_type); |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1807 if (lhs->lhs_lvar == NULL) |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1808 return FAIL; |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1809 lhs->lhs_new_local = TRUE; |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1810 } |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1811 |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1812 lhs->lhs_member_type = lhs->lhs_type; |
23578
85ce241ff9e3
patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents:
23576
diff
changeset
|
1813 if (lhs->lhs_has_index) |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1814 { |
26340
4044306e3836
patch 8.2.3701: Vim9: invalid LHS is not possible
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
1815 char_u *after = var_start + lhs->lhs_varlen; |
4044306e3836
patch 8.2.3701: Vim9: invalid LHS is not possible
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
1816 char_u *p; |
4044306e3836
patch 8.2.3701: Vim9: invalid LHS is not possible
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
1817 |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1818 // Something follows after the variable: "var[idx]" or "var.key". |
28281
bd1dcc605e58
patch 8.2.4666: Vim9: assignment not recognized in skipped block
Bram Moolenaar <Bram@vim.org>
parents:
28217
diff
changeset
|
1819 if (is_decl && cctx->ctx_skip != SKIP_YES) |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1820 { |
28281
bd1dcc605e58
patch 8.2.4666: Vim9: assignment not recognized in skipped block
Bram Moolenaar <Bram@vim.org>
parents:
28217
diff
changeset
|
1821 if (has_cmd) |
bd1dcc605e58
patch 8.2.4666: Vim9: assignment not recognized in skipped block
Bram Moolenaar <Bram@vim.org>
parents:
28217
diff
changeset
|
1822 emsg(_(e_cannot_use_index_when_declaring_variable)); |
bd1dcc605e58
patch 8.2.4666: Vim9: assignment not recognized in skipped block
Bram Moolenaar <Bram@vim.org>
parents:
28217
diff
changeset
|
1823 else |
bd1dcc605e58
patch 8.2.4666: Vim9: assignment not recognized in skipped block
Bram Moolenaar <Bram@vim.org>
parents:
28217
diff
changeset
|
1824 semsg(_(e_unknown_variable_str), lhs->lhs_name); |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1825 return FAIL; |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1826 } |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1827 |
26340
4044306e3836
patch 8.2.3701: Vim9: invalid LHS is not possible
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
1828 // Now: var_start[lhs->lhs_varlen] is '[' or '.' |
4044306e3836
patch 8.2.3701: Vim9: invalid LHS is not possible
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
1829 // Only the last index is used below, if there are others |
4044306e3836
patch 8.2.3701: Vim9: invalid LHS is not possible
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
1830 // before it generate code for the expression. Thus for |
4044306e3836
patch 8.2.3701: Vim9: invalid LHS is not possible
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
1831 // "ll[1][2]" the expression is "ll[1]" and "[2]" is the index. |
4044306e3836
patch 8.2.3701: Vim9: invalid LHS is not possible
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
1832 for (;;) |
4044306e3836
patch 8.2.3701: Vim9: invalid LHS is not possible
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
1833 { |
4044306e3836
patch 8.2.3701: Vim9: invalid LHS is not possible
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
1834 p = skip_index(after); |
4044306e3836
patch 8.2.3701: Vim9: invalid LHS is not possible
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
1835 if (*p != '[' && *p != '.') |
4044306e3836
patch 8.2.3701: Vim9: invalid LHS is not possible
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
1836 { |
4044306e3836
patch 8.2.3701: Vim9: invalid LHS is not possible
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
1837 lhs->lhs_varlen_total = p - var_start; |
4044306e3836
patch 8.2.3701: Vim9: invalid LHS is not possible
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
1838 break; |
4044306e3836
patch 8.2.3701: Vim9: invalid LHS is not possible
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
1839 } |
4044306e3836
patch 8.2.3701: Vim9: invalid LHS is not possible
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
1840 after = p; |
4044306e3836
patch 8.2.3701: Vim9: invalid LHS is not possible
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
1841 } |
4044306e3836
patch 8.2.3701: Vim9: invalid LHS is not possible
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
1842 if (after > var_start + lhs->lhs_varlen) |
4044306e3836
patch 8.2.3701: Vim9: invalid LHS is not possible
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
1843 { |
4044306e3836
patch 8.2.3701: Vim9: invalid LHS is not possible
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
1844 lhs->lhs_varlen = after - var_start; |
4044306e3836
patch 8.2.3701: Vim9: invalid LHS is not possible
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
1845 lhs->lhs_dest = dest_expr; |
4044306e3836
patch 8.2.3701: Vim9: invalid LHS is not possible
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
1846 // We don't know the type before evaluating the expression, |
4044306e3836
patch 8.2.3701: Vim9: invalid LHS is not possible
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
1847 // use "any" until then. |
4044306e3836
patch 8.2.3701: Vim9: invalid LHS is not possible
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
1848 lhs->lhs_type = &t_any; |
4044306e3836
patch 8.2.3701: Vim9: invalid LHS is not possible
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
1849 } |
4044306e3836
patch 8.2.3701: Vim9: invalid LHS is not possible
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
1850 |
32017
b4e5d28b788c
patch 9.0.1340: Coverity warns for using NULL pointer
Bram Moolenaar <Bram@vim.org>
parents:
32009
diff
changeset
|
1851 int use_class = lhs->lhs_type != NULL |
b4e5d28b788c
patch 9.0.1340: Coverity warns for using NULL pointer
Bram Moolenaar <Bram@vim.org>
parents:
32009
diff
changeset
|
1852 && (lhs->lhs_type->tt_type == VAR_CLASS |
b4e5d28b788c
patch 9.0.1340: Coverity warns for using NULL pointer
Bram Moolenaar <Bram@vim.org>
parents:
32009
diff
changeset
|
1853 || lhs->lhs_type->tt_type == VAR_OBJECT); |
32005
ef644af2c330
patch 9.0.1334: using tt_member for the class leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents:
31980
diff
changeset
|
1854 if (lhs->lhs_type == NULL |
ef644af2c330
patch 9.0.1334: using tt_member for the class leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents:
31980
diff
changeset
|
1855 || (use_class ? lhs->lhs_type->tt_class == NULL |
ef644af2c330
patch 9.0.1334: using tt_member for the class leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents:
31980
diff
changeset
|
1856 : lhs->lhs_type->tt_member == NULL)) |
ef644af2c330
patch 9.0.1334: using tt_member for the class leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents:
31980
diff
changeset
|
1857 { |
26340
4044306e3836
patch 8.2.3701: Vim9: invalid LHS is not possible
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
1858 lhs->lhs_member_type = &t_any; |
32005
ef644af2c330
patch 9.0.1334: using tt_member for the class leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents:
31980
diff
changeset
|
1859 } |
ef644af2c330
patch 9.0.1334: using tt_member for the class leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents:
31980
diff
changeset
|
1860 else if (use_class) |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
1861 { |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
1862 // for an object or class member get the type of the member |
32005
ef644af2c330
patch 9.0.1334: using tt_member for the class leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents:
31980
diff
changeset
|
1863 class_T *cl = lhs->lhs_type->tt_class; |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
1864 lhs->lhs_member_type = class_member_type(cl, after + 1, |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
1865 lhs->lhs_end, &lhs->lhs_member_idx); |
31517
cd5247f4da06
patch 9.0.1091: assignment to non-existing member causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
31483
diff
changeset
|
1866 if (lhs->lhs_member_idx < 0) |
cd5247f4da06
patch 9.0.1091: assignment to non-existing member causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
31483
diff
changeset
|
1867 return FAIL; |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
1868 } |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1869 else |
32005
ef644af2c330
patch 9.0.1334: using tt_member for the class leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents:
31980
diff
changeset
|
1870 { |
26340
4044306e3836
patch 8.2.3701: Vim9: invalid LHS is not possible
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
1871 lhs->lhs_member_type = lhs->lhs_type->tt_member; |
32005
ef644af2c330
patch 9.0.1334: using tt_member for the class leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents:
31980
diff
changeset
|
1872 } |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1873 } |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1874 return OK; |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1875 } |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1876 |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1877 /* |
24490
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24488
diff
changeset
|
1878 * Figure out the LHS and check a few errors. |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24488
diff
changeset
|
1879 */ |
26662
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
1880 int |
24490
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24488
diff
changeset
|
1881 compile_assign_lhs( |
28281
bd1dcc605e58
patch 8.2.4666: Vim9: assignment not recognized in skipped block
Bram Moolenaar <Bram@vim.org>
parents:
28217
diff
changeset
|
1882 char_u *var_start, |
bd1dcc605e58
patch 8.2.4666: Vim9: assignment not recognized in skipped block
Bram Moolenaar <Bram@vim.org>
parents:
28217
diff
changeset
|
1883 lhs_T *lhs, |
bd1dcc605e58
patch 8.2.4666: Vim9: assignment not recognized in skipped block
Bram Moolenaar <Bram@vim.org>
parents:
28217
diff
changeset
|
1884 cmdidx_T cmdidx, |
bd1dcc605e58
patch 8.2.4666: Vim9: assignment not recognized in skipped block
Bram Moolenaar <Bram@vim.org>
parents:
28217
diff
changeset
|
1885 int is_decl, |
bd1dcc605e58
patch 8.2.4666: Vim9: assignment not recognized in skipped block
Bram Moolenaar <Bram@vim.org>
parents:
28217
diff
changeset
|
1886 int heredoc, |
bd1dcc605e58
patch 8.2.4666: Vim9: assignment not recognized in skipped block
Bram Moolenaar <Bram@vim.org>
parents:
28217
diff
changeset
|
1887 int has_cmd, // "var" before "var_start" |
bd1dcc605e58
patch 8.2.4666: Vim9: assignment not recognized in skipped block
Bram Moolenaar <Bram@vim.org>
parents:
28217
diff
changeset
|
1888 int oplen, |
bd1dcc605e58
patch 8.2.4666: Vim9: assignment not recognized in skipped block
Bram Moolenaar <Bram@vim.org>
parents:
28217
diff
changeset
|
1889 cctx_T *cctx) |
24490
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24488
diff
changeset
|
1890 { |
28281
bd1dcc605e58
patch 8.2.4666: Vim9: assignment not recognized in skipped block
Bram Moolenaar <Bram@vim.org>
parents:
28217
diff
changeset
|
1891 if (compile_lhs(var_start, lhs, cmdidx, heredoc, has_cmd, oplen, cctx) |
bd1dcc605e58
patch 8.2.4666: Vim9: assignment not recognized in skipped block
Bram Moolenaar <Bram@vim.org>
parents:
28217
diff
changeset
|
1892 == FAIL) |
24490
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24488
diff
changeset
|
1893 return FAIL; |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24488
diff
changeset
|
1894 |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24488
diff
changeset
|
1895 if (!lhs->lhs_has_index && lhs->lhs_lvar == &lhs->lhs_arg_lvar) |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24488
diff
changeset
|
1896 { |
31602
53c3df37a2b0
patch 9.0.1133: error message names do not match the items
Bram Moolenaar <Bram@vim.org>
parents:
31596
diff
changeset
|
1897 semsg(_(e_cannot_assign_to_argument_str), lhs->lhs_name); |
24490
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24488
diff
changeset
|
1898 return FAIL; |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24488
diff
changeset
|
1899 } |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24488
diff
changeset
|
1900 if (!is_decl && lhs->lhs_lvar != NULL |
30584
ee039a6049ff
patch 9.0.0627: "const" and "final" both make the type a constant
Bram Moolenaar <Bram@vim.org>
parents:
30576
diff
changeset
|
1901 && lhs->lhs_lvar->lv_const != ASSIGN_VAR |
ee039a6049ff
patch 9.0.0627: "const" and "final" both make the type a constant
Bram Moolenaar <Bram@vim.org>
parents:
30576
diff
changeset
|
1902 && !lhs->lhs_has_index) |
24490
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24488
diff
changeset
|
1903 { |
31602
53c3df37a2b0
patch 9.0.1133: error message names do not match the items
Bram Moolenaar <Bram@vim.org>
parents:
31596
diff
changeset
|
1904 semsg(_(e_cannot_assign_to_constant_str), lhs->lhs_name); |
24490
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24488
diff
changeset
|
1905 return FAIL; |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24488
diff
changeset
|
1906 } |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24488
diff
changeset
|
1907 return OK; |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24488
diff
changeset
|
1908 } |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24488
diff
changeset
|
1909 |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24488
diff
changeset
|
1910 /* |
25591
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25579
diff
changeset
|
1911 * Return TRUE if "lhs" has a range index: "[expr : expr]". |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25579
diff
changeset
|
1912 */ |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25579
diff
changeset
|
1913 static int |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25579
diff
changeset
|
1914 has_list_index(char_u *idx_start, cctx_T *cctx) |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25579
diff
changeset
|
1915 { |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25579
diff
changeset
|
1916 char_u *p = idx_start; |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25579
diff
changeset
|
1917 int save_skip; |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25579
diff
changeset
|
1918 |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25579
diff
changeset
|
1919 if (*p != '[') |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25579
diff
changeset
|
1920 return FALSE; |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25579
diff
changeset
|
1921 |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25579
diff
changeset
|
1922 p = skipwhite(p + 1); |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25579
diff
changeset
|
1923 if (*p == ':') |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25579
diff
changeset
|
1924 return TRUE; |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25579
diff
changeset
|
1925 |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25579
diff
changeset
|
1926 save_skip = cctx->ctx_skip; |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25579
diff
changeset
|
1927 cctx->ctx_skip = SKIP_YES; |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25579
diff
changeset
|
1928 (void)compile_expr0(&p, cctx); |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25579
diff
changeset
|
1929 cctx->ctx_skip = save_skip; |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25579
diff
changeset
|
1930 return *skipwhite(p) == ':'; |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25579
diff
changeset
|
1931 } |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25579
diff
changeset
|
1932 |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25579
diff
changeset
|
1933 /* |
24357
108a6e2497f6
patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24339
diff
changeset
|
1934 * For an assignment with an index, compile the "idx" in "var[idx]" or "key" in |
108a6e2497f6
patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24339
diff
changeset
|
1935 * "var.key". |
108a6e2497f6
patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24339
diff
changeset
|
1936 */ |
108a6e2497f6
patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24339
diff
changeset
|
1937 static int |
108a6e2497f6
patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24339
diff
changeset
|
1938 compile_assign_index( |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1939 char_u *var_start, |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1940 lhs_T *lhs, |
24357
108a6e2497f6
patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24339
diff
changeset
|
1941 int *range, |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1942 cctx_T *cctx) |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1943 { |
24357
108a6e2497f6
patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24339
diff
changeset
|
1944 size_t varlen = lhs->lhs_varlen; |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1945 char_u *p; |
24357
108a6e2497f6
patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24339
diff
changeset
|
1946 int r = OK; |
24434
602e528a8e43
patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents:
24432
diff
changeset
|
1947 int need_white_before = TRUE; |
602e528a8e43
patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents:
24432
diff
changeset
|
1948 int empty_second; |
24357
108a6e2497f6
patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24339
diff
changeset
|
1949 |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1950 p = var_start + varlen; |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1951 if (*p == '[') |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1952 { |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1953 p = skipwhite(p + 1); |
24434
602e528a8e43
patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents:
24432
diff
changeset
|
1954 if (*p == ':') |
602e528a8e43
patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents:
24432
diff
changeset
|
1955 { |
602e528a8e43
patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents:
24432
diff
changeset
|
1956 // empty first index, push zero |
602e528a8e43
patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents:
24432
diff
changeset
|
1957 r = generate_PUSHNR(cctx, 0); |
602e528a8e43
patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents:
24432
diff
changeset
|
1958 need_white_before = FALSE; |
602e528a8e43
patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents:
24432
diff
changeset
|
1959 } |
602e528a8e43
patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents:
24432
diff
changeset
|
1960 else |
602e528a8e43
patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents:
24432
diff
changeset
|
1961 r = compile_expr0(&p, cctx); |
23982
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
1962 |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
1963 if (r == OK && *skipwhite(p) == ':') |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
1964 { |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
1965 // unlet var[idx : idx] |
24434
602e528a8e43
patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents:
24432
diff
changeset
|
1966 // blob[idx : idx] = value |
24357
108a6e2497f6
patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24339
diff
changeset
|
1967 *range = TRUE; |
23982
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
1968 p = skipwhite(p); |
24434
602e528a8e43
patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents:
24432
diff
changeset
|
1969 empty_second = *skipwhite(p + 1) == ']'; |
602e528a8e43
patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents:
24432
diff
changeset
|
1970 if ((need_white_before && !IS_WHITE_OR_NUL(p[-1])) |
602e528a8e43
patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents:
24432
diff
changeset
|
1971 || (!empty_second && !IS_WHITE_OR_NUL(p[1]))) |
23982
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
1972 { |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
1973 semsg(_(e_white_space_required_before_and_after_str_at_str), |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
1974 ":", p); |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
1975 return FAIL; |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
1976 } |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
1977 p = skipwhite(p + 1); |
24434
602e528a8e43
patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents:
24432
diff
changeset
|
1978 if (*p == ']') |
602e528a8e43
patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents:
24432
diff
changeset
|
1979 // empty second index, push "none" |
602e528a8e43
patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents:
24432
diff
changeset
|
1980 r = generate_PUSHSPEC(cctx, VVAL_NONE); |
602e528a8e43
patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents:
24432
diff
changeset
|
1981 else |
602e528a8e43
patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents:
24432
diff
changeset
|
1982 r = compile_expr0(&p, cctx); |
23982
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
1983 } |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
1984 |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1985 if (r == OK && *skipwhite(p) != ']') |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1986 { |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1987 // this should not happen |
26602
fac6673086df
patch 8.2.3830: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26594
diff
changeset
|
1988 emsg(_(e_missing_closing_square_brace)); |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1989 r = FAIL; |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1990 } |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1991 } |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
1992 else if (lhs->lhs_member_idx >= 0) |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
1993 { |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
1994 // object member index |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
1995 r = generate_PUSHNR(cctx, lhs->lhs_member_idx); |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
1996 } |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1997 else // if (*p == '.') |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1998 { |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
1999 char_u *key_end = to_name_end(p + 1, TRUE); |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2000 char_u *key = vim_strnsave(p + 1, key_end - p - 1); |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2001 |
25507
1ac82ad3ee01
patch 8.2.3290: Vim9: compiling dict may use pointer after free
Bram Moolenaar <Bram@vim.org>
parents:
25483
diff
changeset
|
2002 r = generate_PUSHS(cctx, &key); |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2003 } |
24357
108a6e2497f6
patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24339
diff
changeset
|
2004 return r; |
108a6e2497f6
patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24339
diff
changeset
|
2005 } |
108a6e2497f6
patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24339
diff
changeset
|
2006 |
108a6e2497f6
patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24339
diff
changeset
|
2007 /* |
24363
1a145eb83a28
patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents:
24361
diff
changeset
|
2008 * For a LHS with an index, load the variable to be indexed. |
1a145eb83a28
patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents:
24361
diff
changeset
|
2009 */ |
1a145eb83a28
patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents:
24361
diff
changeset
|
2010 static int |
1a145eb83a28
patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents:
24361
diff
changeset
|
2011 compile_load_lhs( |
1a145eb83a28
patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents:
24361
diff
changeset
|
2012 lhs_T *lhs, |
1a145eb83a28
patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents:
24361
diff
changeset
|
2013 char_u *var_start, |
1a145eb83a28
patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents:
24361
diff
changeset
|
2014 type_T *rhs_type, |
1a145eb83a28
patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents:
24361
diff
changeset
|
2015 cctx_T *cctx) |
1a145eb83a28
patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents:
24361
diff
changeset
|
2016 { |
1a145eb83a28
patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents:
24361
diff
changeset
|
2017 if (lhs->lhs_dest == dest_expr) |
1a145eb83a28
patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents:
24361
diff
changeset
|
2018 { |
1a145eb83a28
patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents:
24361
diff
changeset
|
2019 size_t varlen = lhs->lhs_varlen; |
1a145eb83a28
patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents:
24361
diff
changeset
|
2020 int c = var_start[varlen]; |
25459
9adaa0c056c7
patch 8.2.3266: Vim9: assignment with two indexes may check next line
Bram Moolenaar <Bram@vim.org>
parents:
25453
diff
changeset
|
2021 int lines_len = cctx->ctx_ufunc->uf_lines.ga_len; |
9adaa0c056c7
patch 8.2.3266: Vim9: assignment with two indexes may check next line
Bram Moolenaar <Bram@vim.org>
parents:
25453
diff
changeset
|
2022 int res; |
9adaa0c056c7
patch 8.2.3266: Vim9: assignment with two indexes may check next line
Bram Moolenaar <Bram@vim.org>
parents:
25453
diff
changeset
|
2023 |
9adaa0c056c7
patch 8.2.3266: Vim9: assignment with two indexes may check next line
Bram Moolenaar <Bram@vim.org>
parents:
25453
diff
changeset
|
2024 // Evaluate "ll[expr]" of "ll[expr][idx]". End the line with a NUL and |
9adaa0c056c7
patch 8.2.3266: Vim9: assignment with two indexes may check next line
Bram Moolenaar <Bram@vim.org>
parents:
25453
diff
changeset
|
2025 // limit the lines array length to avoid skipping to a following line. |
24363
1a145eb83a28
patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents:
24361
diff
changeset
|
2026 var_start[varlen] = NUL; |
25459
9adaa0c056c7
patch 8.2.3266: Vim9: assignment with two indexes may check next line
Bram Moolenaar <Bram@vim.org>
parents:
25453
diff
changeset
|
2027 cctx->ctx_ufunc->uf_lines.ga_len = cctx->ctx_lnum + 1; |
31980
13329cb9faee
patch 9.0.1322: crash when indexing "any" which is an object
Bram Moolenaar <Bram@vim.org>
parents:
31920
diff
changeset
|
2028 char_u *p = var_start; |
25459
9adaa0c056c7
patch 8.2.3266: Vim9: assignment with two indexes may check next line
Bram Moolenaar <Bram@vim.org>
parents:
25453
diff
changeset
|
2029 res = compile_expr0(&p, cctx); |
9adaa0c056c7
patch 8.2.3266: Vim9: assignment with two indexes may check next line
Bram Moolenaar <Bram@vim.org>
parents:
25453
diff
changeset
|
2030 var_start[varlen] = c; |
9adaa0c056c7
patch 8.2.3266: Vim9: assignment with two indexes may check next line
Bram Moolenaar <Bram@vim.org>
parents:
25453
diff
changeset
|
2031 cctx->ctx_ufunc->uf_lines.ga_len = lines_len; |
9adaa0c056c7
patch 8.2.3266: Vim9: assignment with two indexes may check next line
Bram Moolenaar <Bram@vim.org>
parents:
25453
diff
changeset
|
2032 if (res == FAIL || p != var_start + varlen) |
24363
1a145eb83a28
patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents:
24361
diff
changeset
|
2033 { |
1a145eb83a28
patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents:
24361
diff
changeset
|
2034 // this should not happen |
25459
9adaa0c056c7
patch 8.2.3266: Vim9: assignment with two indexes may check next line
Bram Moolenaar <Bram@vim.org>
parents:
25453
diff
changeset
|
2035 if (res != FAIL) |
26602
fac6673086df
patch 8.2.3830: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26594
diff
changeset
|
2036 emsg(_(e_missing_closing_square_brace)); |
24363
1a145eb83a28
patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents:
24361
diff
changeset
|
2037 return FAIL; |
1a145eb83a28
patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents:
24361
diff
changeset
|
2038 } |
1a145eb83a28
patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents:
24361
diff
changeset
|
2039 |
26935
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
2040 lhs->lhs_type = cctx->ctx_type_stack.ga_len == 0 ? &t_void |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
2041 : get_type_on_stack(cctx, 0); |
31980
13329cb9faee
patch 9.0.1322: crash when indexing "any" which is an object
Bram Moolenaar <Bram@vim.org>
parents:
31920
diff
changeset
|
2042 // Now we can properly check the type. The variable is indexed, thus |
13329cb9faee
patch 9.0.1322: crash when indexing "any" which is an object
Bram Moolenaar <Bram@vim.org>
parents:
31920
diff
changeset
|
2043 // we need the member type. For a class or object we don't know the |
13329cb9faee
patch 9.0.1322: crash when indexing "any" which is an object
Bram Moolenaar <Bram@vim.org>
parents:
31920
diff
changeset
|
2044 // type yet, it depends on what member is used. |
13329cb9faee
patch 9.0.1322: crash when indexing "any" which is an object
Bram Moolenaar <Bram@vim.org>
parents:
31920
diff
changeset
|
2045 vartype_T vartype = lhs->lhs_type->tt_type; |
13329cb9faee
patch 9.0.1322: crash when indexing "any" which is an object
Bram Moolenaar <Bram@vim.org>
parents:
31920
diff
changeset
|
2046 type_T *member_type = lhs->lhs_type->tt_member; |
13329cb9faee
patch 9.0.1322: crash when indexing "any" which is an object
Bram Moolenaar <Bram@vim.org>
parents:
31920
diff
changeset
|
2047 if (rhs_type != NULL && member_type != NULL |
13329cb9faee
patch 9.0.1322: crash when indexing "any" which is an object
Bram Moolenaar <Bram@vim.org>
parents:
31920
diff
changeset
|
2048 && vartype != VAR_OBJECT && vartype != VAR_CLASS |
24363
1a145eb83a28
patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents:
24361
diff
changeset
|
2049 && rhs_type != &t_void |
31980
13329cb9faee
patch 9.0.1322: crash when indexing "any" which is an object
Bram Moolenaar <Bram@vim.org>
parents:
31920
diff
changeset
|
2050 && need_type(rhs_type, member_type, FALSE, |
31551
67d9fbe516a3
patch 9.0.1108: type error when using "any" type and adding to float
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
2051 -2, 0, cctx, FALSE, FALSE) == FAIL) |
24363
1a145eb83a28
patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents:
24361
diff
changeset
|
2052 return FAIL; |
1a145eb83a28
patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents:
24361
diff
changeset
|
2053 } |
1a145eb83a28
patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents:
24361
diff
changeset
|
2054 else |
31483
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31445
diff
changeset
|
2055 generate_loadvar(cctx, lhs); |
24363
1a145eb83a28
patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents:
24361
diff
changeset
|
2056 return OK; |
1a145eb83a28
patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents:
24361
diff
changeset
|
2057 } |
1a145eb83a28
patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents:
24361
diff
changeset
|
2058 |
1a145eb83a28
patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents:
24361
diff
changeset
|
2059 /* |
24516
056f954c6fd2
patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents:
24512
diff
changeset
|
2060 * Produce code for loading "lhs" and also take care of an index. |
056f954c6fd2
patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents:
24512
diff
changeset
|
2061 * Return OK/FAIL. |
056f954c6fd2
patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents:
24512
diff
changeset
|
2062 */ |
26662
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
2063 int |
24516
056f954c6fd2
patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents:
24512
diff
changeset
|
2064 compile_load_lhs_with_index(lhs_T *lhs, char_u *var_start, cctx_T *cctx) |
056f954c6fd2
patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents:
24512
diff
changeset
|
2065 { |
31738
ad0712119bee
patch 9.0.1201: assignment with operator doesn't work in object method
Bram Moolenaar <Bram@vim.org>
parents:
31694
diff
changeset
|
2066 if (lhs->lhs_type->tt_type == VAR_OBJECT) |
ad0712119bee
patch 9.0.1201: assignment with operator doesn't work in object method
Bram Moolenaar <Bram@vim.org>
parents:
31694
diff
changeset
|
2067 { |
ad0712119bee
patch 9.0.1201: assignment with operator doesn't work in object method
Bram Moolenaar <Bram@vim.org>
parents:
31694
diff
changeset
|
2068 // "this.value": load "this" object and get the value at index |
ad0712119bee
patch 9.0.1201: assignment with operator doesn't work in object method
Bram Moolenaar <Bram@vim.org>
parents:
31694
diff
changeset
|
2069 // for an object or class member get the type of the member |
32005
ef644af2c330
patch 9.0.1334: using tt_member for the class leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents:
31980
diff
changeset
|
2070 class_T *cl = lhs->lhs_type->tt_class; |
31738
ad0712119bee
patch 9.0.1201: assignment with operator doesn't work in object method
Bram Moolenaar <Bram@vim.org>
parents:
31694
diff
changeset
|
2071 type_T *type = class_member_type(cl, var_start + 5, |
ad0712119bee
patch 9.0.1201: assignment with operator doesn't work in object method
Bram Moolenaar <Bram@vim.org>
parents:
31694
diff
changeset
|
2072 lhs->lhs_end, &lhs->lhs_member_idx); |
ad0712119bee
patch 9.0.1201: assignment with operator doesn't work in object method
Bram Moolenaar <Bram@vim.org>
parents:
31694
diff
changeset
|
2073 if (lhs->lhs_member_idx < 0) |
ad0712119bee
patch 9.0.1201: assignment with operator doesn't work in object method
Bram Moolenaar <Bram@vim.org>
parents:
31694
diff
changeset
|
2074 return FAIL; |
ad0712119bee
patch 9.0.1201: assignment with operator doesn't work in object method
Bram Moolenaar <Bram@vim.org>
parents:
31694
diff
changeset
|
2075 |
ad0712119bee
patch 9.0.1201: assignment with operator doesn't work in object method
Bram Moolenaar <Bram@vim.org>
parents:
31694
diff
changeset
|
2076 if (generate_LOAD(cctx, ISN_LOAD, 0, NULL, lhs->lhs_type) == FAIL) |
ad0712119bee
patch 9.0.1201: assignment with operator doesn't work in object method
Bram Moolenaar <Bram@vim.org>
parents:
31694
diff
changeset
|
2077 return FAIL; |
31754
48431422f766
patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31738
diff
changeset
|
2078 if (cl->class_flags & CLASS_INTERFACE) |
48431422f766
patch 9.0.1209: getting interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31738
diff
changeset
|
2079 return generate_GET_ITF_MEMBER(cctx, cl, lhs->lhs_member_idx, type); |
31738
ad0712119bee
patch 9.0.1201: assignment with operator doesn't work in object method
Bram Moolenaar <Bram@vim.org>
parents:
31694
diff
changeset
|
2080 return generate_GET_OBJ_MEMBER(cctx, lhs->lhs_member_idx, type); |
ad0712119bee
patch 9.0.1201: assignment with operator doesn't work in object method
Bram Moolenaar <Bram@vim.org>
parents:
31694
diff
changeset
|
2081 } |
ad0712119bee
patch 9.0.1201: assignment with operator doesn't work in object method
Bram Moolenaar <Bram@vim.org>
parents:
31694
diff
changeset
|
2082 |
24516
056f954c6fd2
patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents:
24512
diff
changeset
|
2083 compile_load_lhs(lhs, var_start, NULL, cctx); |
056f954c6fd2
patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents:
24512
diff
changeset
|
2084 |
056f954c6fd2
patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents:
24512
diff
changeset
|
2085 if (lhs->lhs_has_index) |
056f954c6fd2
patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents:
24512
diff
changeset
|
2086 { |
056f954c6fd2
patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents:
24512
diff
changeset
|
2087 int range = FALSE; |
056f954c6fd2
patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents:
24512
diff
changeset
|
2088 |
056f954c6fd2
patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents:
24512
diff
changeset
|
2089 // Get member from list or dict. First compile the |
056f954c6fd2
patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents:
24512
diff
changeset
|
2090 // index value. |
056f954c6fd2
patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents:
24512
diff
changeset
|
2091 if (compile_assign_index(var_start, lhs, &range, cctx) == FAIL) |
056f954c6fd2
patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents:
24512
diff
changeset
|
2092 return FAIL; |
056f954c6fd2
patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents:
24512
diff
changeset
|
2093 if (range) |
056f954c6fd2
patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents:
24512
diff
changeset
|
2094 { |
056f954c6fd2
patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents:
24512
diff
changeset
|
2095 semsg(_(e_cannot_use_range_with_assignment_operator_str), |
056f954c6fd2
patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents:
24512
diff
changeset
|
2096 var_start); |
056f954c6fd2
patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents:
24512
diff
changeset
|
2097 return FAIL; |
056f954c6fd2
patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents:
24512
diff
changeset
|
2098 } |
056f954c6fd2
patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents:
24512
diff
changeset
|
2099 |
056f954c6fd2
patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents:
24512
diff
changeset
|
2100 // Get the member. |
25800
fe8d153cb268
patch 8.2.3435: Vim9: dict is not passed to dict function
Bram Moolenaar <Bram@vim.org>
parents:
25776
diff
changeset
|
2101 if (compile_member(FALSE, NULL, cctx) == FAIL) |
24516
056f954c6fd2
patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents:
24512
diff
changeset
|
2102 return FAIL; |
056f954c6fd2
patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents:
24512
diff
changeset
|
2103 } |
056f954c6fd2
patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents:
24512
diff
changeset
|
2104 return OK; |
056f954c6fd2
patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents:
24512
diff
changeset
|
2105 } |
056f954c6fd2
patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents:
24512
diff
changeset
|
2106 |
056f954c6fd2
patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents:
24512
diff
changeset
|
2107 /* |
24357
108a6e2497f6
patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24339
diff
changeset
|
2108 * Assignment to a list or dict member, or ":unlet" for the item, using the |
108a6e2497f6
patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24339
diff
changeset
|
2109 * information in "lhs". |
108a6e2497f6
patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24339
diff
changeset
|
2110 * Returns OK or FAIL. |
108a6e2497f6
patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24339
diff
changeset
|
2111 */ |
26662
4b23672d1f0e
patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
26660
diff
changeset
|
2112 int |
24357
108a6e2497f6
patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24339
diff
changeset
|
2113 compile_assign_unlet( |
108a6e2497f6
patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24339
diff
changeset
|
2114 char_u *var_start, |
108a6e2497f6
patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24339
diff
changeset
|
2115 lhs_T *lhs, |
108a6e2497f6
patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24339
diff
changeset
|
2116 int is_assign, |
108a6e2497f6
patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24339
diff
changeset
|
2117 type_T *rhs_type, |
108a6e2497f6
patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24339
diff
changeset
|
2118 cctx_T *cctx) |
108a6e2497f6
patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24339
diff
changeset
|
2119 { |
108a6e2497f6
patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24339
diff
changeset
|
2120 vartype_T dest_type; |
108a6e2497f6
patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24339
diff
changeset
|
2121 int range = FALSE; |
108a6e2497f6
patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24339
diff
changeset
|
2122 |
24434
602e528a8e43
patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents:
24432
diff
changeset
|
2123 if (compile_assign_index(var_start, lhs, &range, cctx) == FAIL) |
602e528a8e43
patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents:
24432
diff
changeset
|
2124 return FAIL; |
25591
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25579
diff
changeset
|
2125 if (is_assign && range |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25579
diff
changeset
|
2126 && lhs->lhs_type->tt_type != VAR_LIST |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25579
diff
changeset
|
2127 && lhs->lhs_type != &t_blob |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25579
diff
changeset
|
2128 && lhs->lhs_type != &t_any) |
24434
602e528a8e43
patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents:
24432
diff
changeset
|
2129 { |
602e528a8e43
patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents:
24432
diff
changeset
|
2130 semsg(_(e_cannot_use_range_with_assignment_str), var_start); |
602e528a8e43
patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents:
24432
diff
changeset
|
2131 return FAIL; |
602e528a8e43
patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents:
24432
diff
changeset
|
2132 } |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2133 |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
2134 if (lhs->lhs_type == NULL || lhs->lhs_type == &t_any) |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2135 { |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2136 // Index on variable of unknown type: check at runtime. |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2137 dest_type = VAR_ANY; |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2138 } |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2139 else |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2140 { |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2141 dest_type = lhs->lhs_type->tt_type; |
23982
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
2142 if (dest_type == VAR_DICT && range) |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
2143 { |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
2144 emsg(e_cannot_use_range_with_dictionary); |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
2145 return FAIL; |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
2146 } |
24796
7c1375eb1636
patch 8.2.2936: Vim9: converting number to bool uses wrong stack offset
Bram Moolenaar <Bram@vim.org>
parents:
24776
diff
changeset
|
2147 if (dest_type == VAR_DICT |
7c1375eb1636
patch 8.2.2936: Vim9: converting number to bool uses wrong stack offset
Bram Moolenaar <Bram@vim.org>
parents:
24776
diff
changeset
|
2148 && may_generate_2STRING(-1, FALSE, cctx) == FAIL) |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2149 return FAIL; |
24475
96905804bf5a
patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents:
24471
diff
changeset
|
2150 if (dest_type == VAR_LIST || dest_type == VAR_BLOB) |
96905804bf5a
patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents:
24471
diff
changeset
|
2151 { |
96905804bf5a
patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents:
24471
diff
changeset
|
2152 type_T *type; |
96905804bf5a
patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents:
24471
diff
changeset
|
2153 |
96905804bf5a
patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents:
24471
diff
changeset
|
2154 if (range) |
96905804bf5a
patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents:
24471
diff
changeset
|
2155 { |
26935
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
2156 type = get_type_on_stack(cctx, 1); |
31551
67d9fbe516a3
patch 9.0.1108: type error when using "any" type and adding to float
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
2157 if (need_type(type, &t_number, FALSE, |
28131
d8bf200cd761
patch 8.2.4590: Vim9: range type check has wrong offset
Bram Moolenaar <Bram@vim.org>
parents:
28129
diff
changeset
|
2158 -2, 0, cctx, FALSE, FALSE) == FAIL) |
23982
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
2159 return FAIL; |
24475
96905804bf5a
patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents:
24471
diff
changeset
|
2160 } |
26935
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
2161 type = get_type_on_stack(cctx, 0); |
28029
0ed38a4e028d
patch 8.2.4539: when comparing special v:none and v:null are handled the same
Bram Moolenaar <Bram@vim.org>
parents:
28002
diff
changeset
|
2162 if ((dest_type != VAR_BLOB && type->tt_type != VAR_SPECIAL) |
31551
67d9fbe516a3
patch 9.0.1108: type error when using "any" type and adding to float
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
2163 && need_type(type, &t_number, FALSE, |
24475
96905804bf5a
patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents:
24471
diff
changeset
|
2164 -1, 0, cctx, FALSE, FALSE) == FAIL) |
23982
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
2165 return FAIL; |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
2166 } |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2167 } |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2168 |
29769
e0259a817d82
patch 9.0.0224: Using NULL pointer when skipping compiled code
Bram Moolenaar <Bram@vim.org>
parents:
29763
diff
changeset
|
2169 if (cctx->ctx_skip == SKIP_YES) |
e0259a817d82
patch 9.0.0224: Using NULL pointer when skipping compiled code
Bram Moolenaar <Bram@vim.org>
parents:
29763
diff
changeset
|
2170 return OK; |
e0259a817d82
patch 9.0.0224: Using NULL pointer when skipping compiled code
Bram Moolenaar <Bram@vim.org>
parents:
29763
diff
changeset
|
2171 |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2172 // Load the dict or list. On the stack we then have: |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2173 // - value (for assignment, not for :unlet) |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2174 // - index |
23982
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
2175 // - for [a : b] second index |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2176 // - variable |
24363
1a145eb83a28
patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents:
24361
diff
changeset
|
2177 if (compile_load_lhs(lhs, var_start, rhs_type, cctx) == FAIL) |
1a145eb83a28
patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents:
24361
diff
changeset
|
2178 return FAIL; |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2179 |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
2180 if (dest_type == VAR_LIST |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
2181 || dest_type == VAR_DICT |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
2182 || dest_type == VAR_BLOB |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
2183 || dest_type == VAR_CLASS |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
2184 || dest_type == VAR_OBJECT |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
2185 || dest_type == VAR_ANY) |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2186 { |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2187 if (is_assign) |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2188 { |
24434
602e528a8e43
patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents:
24432
diff
changeset
|
2189 if (range) |
602e528a8e43
patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents:
24432
diff
changeset
|
2190 { |
602e528a8e43
patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents:
24432
diff
changeset
|
2191 if (generate_instr_drop(cctx, ISN_STORERANGE, 4) == NULL) |
602e528a8e43
patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents:
24432
diff
changeset
|
2192 return FAIL; |
602e528a8e43
patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents:
24432
diff
changeset
|
2193 } |
602e528a8e43
patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents:
24432
diff
changeset
|
2194 else |
602e528a8e43
patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents:
24432
diff
changeset
|
2195 { |
602e528a8e43
patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents:
24432
diff
changeset
|
2196 isn_T *isn = generate_instr_drop(cctx, ISN_STOREINDEX, 3); |
602e528a8e43
patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents:
24432
diff
changeset
|
2197 |
602e528a8e43
patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents:
24432
diff
changeset
|
2198 if (isn == NULL) |
602e528a8e43
patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents:
24432
diff
changeset
|
2199 return FAIL; |
31758
85f93e094810
patch 9.0.1211: storing value in interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31754
diff
changeset
|
2200 isn->isn_arg.storeindex.si_vartype = dest_type; |
85f93e094810
patch 9.0.1211: storing value in interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31754
diff
changeset
|
2201 isn->isn_arg.storeindex.si_class = NULL; |
85f93e094810
patch 9.0.1211: storing value in interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31754
diff
changeset
|
2202 |
85f93e094810
patch 9.0.1211: storing value in interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31754
diff
changeset
|
2203 if (dest_type == VAR_OBJECT) |
85f93e094810
patch 9.0.1211: storing value in interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31754
diff
changeset
|
2204 { |
32005
ef644af2c330
patch 9.0.1334: using tt_member for the class leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents:
31980
diff
changeset
|
2205 class_T *cl = lhs->lhs_type->tt_class; |
31758
85f93e094810
patch 9.0.1211: storing value in interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31754
diff
changeset
|
2206 |
85f93e094810
patch 9.0.1211: storing value in interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31754
diff
changeset
|
2207 if (cl->class_flags & CLASS_INTERFACE) |
85f93e094810
patch 9.0.1211: storing value in interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31754
diff
changeset
|
2208 { |
85f93e094810
patch 9.0.1211: storing value in interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31754
diff
changeset
|
2209 // "this.value": load "this" object and get the value |
85f93e094810
patch 9.0.1211: storing value in interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31754
diff
changeset
|
2210 // at index for an object or class member get the type |
85f93e094810
patch 9.0.1211: storing value in interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31754
diff
changeset
|
2211 // of the member |
85f93e094810
patch 9.0.1211: storing value in interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31754
diff
changeset
|
2212 isn->isn_arg.storeindex.si_class = cl; |
85f93e094810
patch 9.0.1211: storing value in interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31754
diff
changeset
|
2213 ++cl->class_refcount; |
85f93e094810
patch 9.0.1211: storing value in interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31754
diff
changeset
|
2214 } |
85f93e094810
patch 9.0.1211: storing value in interface member does not always work
Bram Moolenaar <Bram@vim.org>
parents:
31754
diff
changeset
|
2215 } |
24434
602e528a8e43
patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents:
24432
diff
changeset
|
2216 } |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2217 } |
23982
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
2218 else if (range) |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
2219 { |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
2220 if (generate_instr_drop(cctx, ISN_UNLETRANGE, 3) == NULL) |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
2221 return FAIL; |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23980
diff
changeset
|
2222 } |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2223 else |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2224 { |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2225 if (generate_instr_drop(cctx, ISN_UNLETINDEX, 2) == NULL) |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2226 return FAIL; |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2227 } |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2228 } |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2229 else |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2230 { |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2231 emsg(_(e_indexable_type_required)); |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2232 return FAIL; |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2233 } |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2234 |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2235 return OK; |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2236 } |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2237 |
23054
df0548b649c1
patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents:
23052
diff
changeset
|
2238 /* |
31424
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2239 * Generate an instruction to push the default value for "vartype". |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2240 * if "dest_local" is TRUE then for some types no instruction is generated. |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2241 * "skip_store" is set to TRUE if no PUSH instruction is generated. |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2242 * Returns OK or FAIL. |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2243 */ |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2244 static int |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2245 push_default_value( |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2246 cctx_T *cctx, |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2247 vartype_T vartype, |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2248 int dest_is_local, |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2249 int *skip_store) |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2250 { |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2251 int r = OK; |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2252 |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2253 switch (vartype) |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2254 { |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2255 case VAR_BOOL: |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2256 r = generate_PUSHBOOL(cctx, VVAL_FALSE); |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2257 break; |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2258 case VAR_FLOAT: |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2259 r = generate_PUSHF(cctx, 0.0); |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2260 break; |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2261 case VAR_STRING: |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2262 r = generate_PUSHS(cctx, NULL); |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2263 break; |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2264 case VAR_BLOB: |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2265 r = generate_PUSHBLOB(cctx, blob_alloc()); |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2266 break; |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2267 case VAR_FUNC: |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2268 r = generate_PUSHFUNC(cctx, NULL, &t_func_void, TRUE); |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2269 break; |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2270 case VAR_LIST: |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2271 r = generate_NEWLIST(cctx, 0, FALSE); |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2272 break; |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2273 case VAR_DICT: |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2274 r = generate_NEWDICT(cctx, 0, FALSE); |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2275 break; |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2276 case VAR_JOB: |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2277 r = generate_PUSHJOB(cctx); |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2278 break; |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2279 case VAR_CHANNEL: |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2280 r = generate_PUSHCHANNEL(cctx); |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2281 break; |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2282 case VAR_NUMBER: |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2283 case VAR_UNKNOWN: |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2284 case VAR_ANY: |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2285 case VAR_PARTIAL: |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2286 case VAR_VOID: |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2287 case VAR_INSTR: |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2288 case VAR_CLASS: |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2289 case VAR_OBJECT: |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2290 case VAR_SPECIAL: // cannot happen |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2291 // This is skipped for local variables, they are always |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2292 // initialized to zero. But in a "for" or "while" loop |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2293 // the value may have been changed. |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2294 if (dest_is_local && !inside_loop_scope(cctx)) |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2295 *skip_store = TRUE; |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2296 else |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2297 r = generate_PUSHNR(cctx, 0); |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2298 break; |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2299 } |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2300 return r; |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2301 } |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2302 |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2303 /* |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2304 * Compile declaration and assignment: |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22381
diff
changeset
|
2305 * "let name" |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22381
diff
changeset
|
2306 * "var name = expr" |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22381
diff
changeset
|
2307 * "final name = expr" |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22381
diff
changeset
|
2308 * "const name = expr" |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22381
diff
changeset
|
2309 * "name = expr" |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22381
diff
changeset
|
2310 * "arg" points to "name". |
24533
9c404d78d767
patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents:
24531
diff
changeset
|
2311 * "++arg" and "--arg" |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2312 * Return NULL for an error. |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2313 * Return "arg" if it does not look like a variable list. |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2314 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2315 static char_u * |
31441
e572ff386670
patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents:
31424
diff
changeset
|
2316 compile_assignment( |
e572ff386670
patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents:
31424
diff
changeset
|
2317 char_u *arg_start, |
e572ff386670
patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents:
31424
diff
changeset
|
2318 exarg_T *eap, |
e572ff386670
patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents:
31424
diff
changeset
|
2319 cmdidx_T cmdidx, |
e572ff386670
patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents:
31424
diff
changeset
|
2320 cctx_T *cctx) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2321 { |
31441
e572ff386670
patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents:
31424
diff
changeset
|
2322 char_u *arg = arg_start; |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2323 char_u *var_start; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2324 char_u *p; |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
2325 char_u *end = arg; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2326 char_u *ret = NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2327 int var_count = 0; |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2328 int var_idx; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2329 int semicolon = 0; |
25034
8d660d1cca8d
patch 8.2.3054: Vim9: unpack assignment using "_" after semicolon fails
Bram Moolenaar <Bram@vim.org>
parents:
25032
diff
changeset
|
2330 int did_generate_slice = FALSE; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2331 garray_T *instr = &cctx->ctx_instr; |
31441
e572ff386670
patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents:
31424
diff
changeset
|
2332 int jump_instr_idx = instr->ga_len; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2333 char_u *op; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2334 int oplen = 0; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2335 int heredoc = FALSE; |
24533
9c404d78d767
patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents:
24531
diff
changeset
|
2336 int incdec = FALSE; |
23033
b98003d73150
patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents:
22975
diff
changeset
|
2337 type_T *rhs_type = &t_any; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2338 char_u *sp; |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2339 int is_decl = is_decl_command(cmdidx); |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2340 lhs_T lhs; |
31445
85d017b25e20
patch 9.0.1055: Coverity warns for using uninitialized memory
Bram Moolenaar <Bram@vim.org>
parents:
31441
diff
changeset
|
2341 CLEAR_FIELD(lhs); |
24329
cd9f77409393
patch 8.2.2705: Vim9: misleading reported line number for wrong type
Bram Moolenaar <Bram@vim.org>
parents:
24295
diff
changeset
|
2342 long start_lnum = SOURCING_LNUM; |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2343 |
31590
aee868b9229a
patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents:
31551
diff
changeset
|
2344 int has_arg_is_set_prefix = STRNCMP(arg, "ifargisset ", 11) == 0; |
31441
e572ff386670
patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents:
31424
diff
changeset
|
2345 if (has_arg_is_set_prefix) |
e572ff386670
patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents:
31424
diff
changeset
|
2346 { |
e572ff386670
patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents:
31424
diff
changeset
|
2347 arg += 11; |
e572ff386670
patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents:
31424
diff
changeset
|
2348 int def_idx = getdigits(&arg); |
e572ff386670
patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents:
31424
diff
changeset
|
2349 arg = skipwhite(arg); |
e572ff386670
patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents:
31424
diff
changeset
|
2350 |
e572ff386670
patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents:
31424
diff
changeset
|
2351 // Use a JUMP_IF_ARG_NOT_SET instruction to skip if the value was not |
e572ff386670
patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents:
31424
diff
changeset
|
2352 // given and the default value is "v:none". |
e572ff386670
patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents:
31424
diff
changeset
|
2353 int off = STACK_FRAME_SIZE + (cctx->ctx_ufunc->uf_va_name != NULL |
e572ff386670
patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents:
31424
diff
changeset
|
2354 ? 1 : 0); |
e572ff386670
patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents:
31424
diff
changeset
|
2355 int count = cctx->ctx_ufunc->uf_def_args.ga_len; |
e572ff386670
patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents:
31424
diff
changeset
|
2356 if (generate_JUMP_IF_ARG(cctx, ISN_JUMP_IF_ARG_NOT_SET, |
e572ff386670
patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents:
31424
diff
changeset
|
2357 def_idx - count - off) == FAIL) |
e572ff386670
patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents:
31424
diff
changeset
|
2358 goto theend; |
e572ff386670
patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents:
31424
diff
changeset
|
2359 } |
e572ff386670
patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents:
31424
diff
changeset
|
2360 |
27968
40c6e5f849dc
patch 8.2.4509: Vim9: can declare a variable with ":va"
Bram Moolenaar <Bram@vim.org>
parents:
27869
diff
changeset
|
2361 // Skip over the "varname" or "[varname, varname]" to get to any "=". |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2362 p = skip_var_list(arg, TRUE, &var_count, &semicolon, TRUE); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2363 if (p == NULL) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2364 return *arg == '[' ? arg : NULL; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2365 |
24533
9c404d78d767
patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents:
24531
diff
changeset
|
2366 if (eap->cmdidx == CMD_increment || eap->cmdidx == CMD_decrement) |
9c404d78d767
patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents:
24531
diff
changeset
|
2367 { |
25022
39551b6e0112
patch 8.2.3048: strange error for white space after ++ command
Bram Moolenaar <Bram@vim.org>
parents:
25004
diff
changeset
|
2368 if (VIM_ISWHITE(eap->cmd[2])) |
39551b6e0112
patch 8.2.3048: strange error for white space after ++ command
Bram Moolenaar <Bram@vim.org>
parents:
25004
diff
changeset
|
2369 { |
39551b6e0112
patch 8.2.3048: strange error for white space after ++ command
Bram Moolenaar <Bram@vim.org>
parents:
25004
diff
changeset
|
2370 semsg(_(e_no_white_space_allowed_after_str_str), |
39551b6e0112
patch 8.2.3048: strange error for white space after ++ command
Bram Moolenaar <Bram@vim.org>
parents:
25004
diff
changeset
|
2371 eap->cmdidx == CMD_increment ? "++" : "--", eap->cmd); |
39551b6e0112
patch 8.2.3048: strange error for white space after ++ command
Bram Moolenaar <Bram@vim.org>
parents:
25004
diff
changeset
|
2372 return NULL; |
39551b6e0112
patch 8.2.3048: strange error for white space after ++ command
Bram Moolenaar <Bram@vim.org>
parents:
25004
diff
changeset
|
2373 } |
24533
9c404d78d767
patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents:
24531
diff
changeset
|
2374 op = (char_u *)(eap->cmdidx == CMD_increment ? "+=" : "-="); |
9c404d78d767
patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents:
24531
diff
changeset
|
2375 oplen = 2; |
9c404d78d767
patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents:
24531
diff
changeset
|
2376 incdec = TRUE; |
9c404d78d767
patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents:
24531
diff
changeset
|
2377 } |
28747
fb86364889a4
patch 8.2.4898: Coverity complains about pointer usage
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
2378 else |
fb86364889a4
patch 8.2.4898: Coverity complains about pointer usage
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
2379 { |
fb86364889a4
patch 8.2.4898: Coverity complains about pointer usage
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
2380 sp = p; |
fb86364889a4
patch 8.2.4898: Coverity complains about pointer usage
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
2381 p = skipwhite(p); |
fb86364889a4
patch 8.2.4898: Coverity complains about pointer usage
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
2382 op = p; |
fb86364889a4
patch 8.2.4898: Coverity complains about pointer usage
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
2383 oplen = assignment_len(p, &heredoc); |
fb86364889a4
patch 8.2.4898: Coverity complains about pointer usage
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
2384 |
fb86364889a4
patch 8.2.4898: Coverity complains about pointer usage
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
2385 if (var_count > 0 && oplen == 0) |
fb86364889a4
patch 8.2.4898: Coverity complains about pointer usage
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
2386 // can be something like "[1, 2]->func()" |
fb86364889a4
patch 8.2.4898: Coverity complains about pointer usage
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
2387 return arg; |
fb86364889a4
patch 8.2.4898: Coverity complains about pointer usage
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
2388 |
fb86364889a4
patch 8.2.4898: Coverity complains about pointer usage
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
2389 if (oplen > 0 && (!VIM_ISWHITE(*sp) || !IS_WHITE_OR_NUL(op[oplen]))) |
fb86364889a4
patch 8.2.4898: Coverity complains about pointer usage
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
2390 { |
fb86364889a4
patch 8.2.4898: Coverity complains about pointer usage
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
2391 error_white_both(op, oplen); |
fb86364889a4
patch 8.2.4898: Coverity complains about pointer usage
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
2392 return NULL; |
fb86364889a4
patch 8.2.4898: Coverity complains about pointer usage
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
2393 } |
fb86364889a4
patch 8.2.4898: Coverity complains about pointer usage
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
2394 } |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
2395 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2396 if (heredoc) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2397 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2398 list_T *l; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2399 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2400 // [let] varname =<< [trim] {end} |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
2401 eap->getline = exarg_getline; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2402 eap->cookie = cctx; |
28560
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28281
diff
changeset
|
2403 l = heredoc_get(eap, op + 3, FALSE, TRUE); |
22413
66d1131a7eff
patch 8.2.1755: Vim9: crash when using invalid heredoc marker
Bram Moolenaar <Bram@vim.org>
parents:
22391
diff
changeset
|
2404 if (l == NULL) |
66d1131a7eff
patch 8.2.1755: Vim9: crash when using invalid heredoc marker
Bram Moolenaar <Bram@vim.org>
parents:
22391
diff
changeset
|
2405 return NULL; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2406 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2407 list_free(l); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2408 p += STRLEN(p); |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2409 end = p; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2410 } |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2411 else if (var_count > 0) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2412 { |
23052
9775df18916b
patch 8.2.2072: Vim9: list assign not well tested
Bram Moolenaar <Bram@vim.org>
parents:
23033
diff
changeset
|
2413 char_u *wp; |
9775df18916b
patch 8.2.2072: Vim9: list assign not well tested
Bram Moolenaar <Bram@vim.org>
parents:
23033
diff
changeset
|
2414 |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2415 // for "[var, var] = expr" evaluate the expression here, loop over the |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2416 // list of variables below. |
23052
9775df18916b
patch 8.2.2072: Vim9: list assign not well tested
Bram Moolenaar <Bram@vim.org>
parents:
23033
diff
changeset
|
2417 // A line break may follow the "=". |
9775df18916b
patch 8.2.2072: Vim9: list assign not well tested
Bram Moolenaar <Bram@vim.org>
parents:
23033
diff
changeset
|
2418 |
9775df18916b
patch 8.2.2072: Vim9: list assign not well tested
Bram Moolenaar <Bram@vim.org>
parents:
23033
diff
changeset
|
2419 wp = op + oplen; |
23122
60a0221beab0
patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents:
23114
diff
changeset
|
2420 if (may_get_next_line_error(wp, &p, cctx) == FAIL) |
23052
9775df18916b
patch 8.2.2072: Vim9: list assign not well tested
Bram Moolenaar <Bram@vim.org>
parents:
23033
diff
changeset
|
2421 return FAIL; |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2422 if (compile_expr0(&p, cctx) == FAIL) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2423 return NULL; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2424 end = p; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2425 |
20907
4eeda7139133
patch 8.2.1005: Vim9: using TRUE/FALSE/MAYBE for ctx_skip is confusing
Bram Moolenaar <Bram@vim.org>
parents:
20899
diff
changeset
|
2426 if (cctx->ctx_skip != SKIP_YES) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2427 { |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
2428 type_T *stacktype; |
26372
f5727e2603f0
patch 8.2.3717: Vim9: error for constant list size is only given at runtime
Bram Moolenaar <Bram@vim.org>
parents:
26370
diff
changeset
|
2429 int needed_list_len; |
f5727e2603f0
patch 8.2.3717: Vim9: error for constant list size is only given at runtime
Bram Moolenaar <Bram@vim.org>
parents:
26370
diff
changeset
|
2430 int did_check = FALSE; |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
2431 |
26935
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
2432 stacktype = cctx->ctx_type_stack.ga_len == 0 ? &t_void |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
2433 : get_type_on_stack(cctx, 0); |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2434 if (stacktype->tt_type == VAR_VOID) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2435 { |
21821
0deb6f96a5a3
patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
21811
diff
changeset
|
2436 emsg(_(e_cannot_use_void_value)); |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2437 goto theend; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2438 } |
31551
67d9fbe516a3
patch 9.0.1108: type error when using "any" type and adding to float
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
2439 if (need_type(stacktype, &t_list_any, FALSE, -1, 0, cctx, |
22631
59cd5f8b2ab2
patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents:
22627
diff
changeset
|
2440 FALSE, FALSE) == FAIL) |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2441 goto theend; |
26372
f5727e2603f0
patch 8.2.3717: Vim9: error for constant list size is only given at runtime
Bram Moolenaar <Bram@vim.org>
parents:
26370
diff
changeset
|
2442 // If a constant list was used we can check the length right here. |
f5727e2603f0
patch 8.2.3717: Vim9: error for constant list size is only given at runtime
Bram Moolenaar <Bram@vim.org>
parents:
26370
diff
changeset
|
2443 needed_list_len = semicolon ? var_count - 1 : var_count; |
f5727e2603f0
patch 8.2.3717: Vim9: error for constant list size is only given at runtime
Bram Moolenaar <Bram@vim.org>
parents:
26370
diff
changeset
|
2444 if (instr->ga_len > 0) |
f5727e2603f0
patch 8.2.3717: Vim9: error for constant list size is only given at runtime
Bram Moolenaar <Bram@vim.org>
parents:
26370
diff
changeset
|
2445 { |
f5727e2603f0
patch 8.2.3717: Vim9: error for constant list size is only given at runtime
Bram Moolenaar <Bram@vim.org>
parents:
26370
diff
changeset
|
2446 isn_T *isn = ((isn_T *)instr->ga_data) + instr->ga_len - 1; |
f5727e2603f0
patch 8.2.3717: Vim9: error for constant list size is only given at runtime
Bram Moolenaar <Bram@vim.org>
parents:
26370
diff
changeset
|
2447 |
f5727e2603f0
patch 8.2.3717: Vim9: error for constant list size is only given at runtime
Bram Moolenaar <Bram@vim.org>
parents:
26370
diff
changeset
|
2448 if (isn->isn_type == ISN_NEWLIST) |
f5727e2603f0
patch 8.2.3717: Vim9: error for constant list size is only given at runtime
Bram Moolenaar <Bram@vim.org>
parents:
26370
diff
changeset
|
2449 { |
f5727e2603f0
patch 8.2.3717: Vim9: error for constant list size is only given at runtime
Bram Moolenaar <Bram@vim.org>
parents:
26370
diff
changeset
|
2450 did_check = TRUE; |
f5727e2603f0
patch 8.2.3717: Vim9: error for constant list size is only given at runtime
Bram Moolenaar <Bram@vim.org>
parents:
26370
diff
changeset
|
2451 if (semicolon ? isn->isn_arg.number < needed_list_len |
f5727e2603f0
patch 8.2.3717: Vim9: error for constant list size is only given at runtime
Bram Moolenaar <Bram@vim.org>
parents:
26370
diff
changeset
|
2452 : isn->isn_arg.number != needed_list_len) |
f5727e2603f0
patch 8.2.3717: Vim9: error for constant list size is only given at runtime
Bram Moolenaar <Bram@vim.org>
parents:
26370
diff
changeset
|
2453 { |
f5727e2603f0
patch 8.2.3717: Vim9: error for constant list size is only given at runtime
Bram Moolenaar <Bram@vim.org>
parents:
26370
diff
changeset
|
2454 semsg(_(e_expected_nr_items_but_got_nr), |
27136
0e88b48575ee
patch 8.2.4097: wrong number in error message on 32 bit system
Bram Moolenaar <Bram@vim.org>
parents:
27114
diff
changeset
|
2455 needed_list_len, (int)isn->isn_arg.number); |
26372
f5727e2603f0
patch 8.2.3717: Vim9: error for constant list size is only given at runtime
Bram Moolenaar <Bram@vim.org>
parents:
26370
diff
changeset
|
2456 goto theend; |
f5727e2603f0
patch 8.2.3717: Vim9: error for constant list size is only given at runtime
Bram Moolenaar <Bram@vim.org>
parents:
26370
diff
changeset
|
2457 } |
f5727e2603f0
patch 8.2.3717: Vim9: error for constant list size is only given at runtime
Bram Moolenaar <Bram@vim.org>
parents:
26370
diff
changeset
|
2458 } |
f5727e2603f0
patch 8.2.3717: Vim9: error for constant list size is only given at runtime
Bram Moolenaar <Bram@vim.org>
parents:
26370
diff
changeset
|
2459 } |
f5727e2603f0
patch 8.2.3717: Vim9: error for constant list size is only given at runtime
Bram Moolenaar <Bram@vim.org>
parents:
26370
diff
changeset
|
2460 if (!did_check) |
f5727e2603f0
patch 8.2.3717: Vim9: error for constant list size is only given at runtime
Bram Moolenaar <Bram@vim.org>
parents:
26370
diff
changeset
|
2461 generate_CHECKLEN(cctx, needed_list_len, semicolon); |
23033
b98003d73150
patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents:
22975
diff
changeset
|
2462 if (stacktype->tt_member != NULL) |
b98003d73150
patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents:
22975
diff
changeset
|
2463 rhs_type = stacktype->tt_member; |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2464 } |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2465 } |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2466 |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2467 /* |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2468 * Loop over variables in "[var, var] = expr". |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2469 * For "var = expr" and "let var: type" this is done only once. |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2470 */ |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2471 if (var_count > 0) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2472 var_start = skipwhite(arg + 1); // skip over the "[" |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2473 else |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2474 var_start = arg; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2475 for (var_idx = 0; var_idx == 0 || var_idx < var_count; var_idx++) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2476 { |
25139
7fa520b85244
patch 8.2.3106: Vim9: confusing line number reported for error
Bram Moolenaar <Bram@vim.org>
parents:
25108
diff
changeset
|
2477 int instr_count = -1; |
7fa520b85244
patch 8.2.3106: Vim9: confusing line number reported for error
Bram Moolenaar <Bram@vim.org>
parents:
25108
diff
changeset
|
2478 int save_lnum; |
26729
b969fdb8cd46
patch 8.2.3893: Vim9: many local variables are initialized with an instruction
Bram Moolenaar <Bram@vim.org>
parents:
26680
diff
changeset
|
2479 int skip_store = FALSE; |
27728
fdc841530372
patch 8.2.4390: Vim9: list from declaration with inferred type not set
Bram Moolenaar <Bram@vim.org>
parents:
27716
diff
changeset
|
2480 type_T *inferred_type = NULL; |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2481 |
24426
78343859f42d
patch 8.2.2753: Vim9: cannot ignore an item in assignment unpack
Bram Moolenaar <Bram@vim.org>
parents:
24420
diff
changeset
|
2482 if (var_start[0] == '_' && !eval_isnamec(var_start[1])) |
78343859f42d
patch 8.2.2753: Vim9: cannot ignore an item in assignment unpack
Bram Moolenaar <Bram@vim.org>
parents:
24420
diff
changeset
|
2483 { |
78343859f42d
patch 8.2.2753: Vim9: cannot ignore an item in assignment unpack
Bram Moolenaar <Bram@vim.org>
parents:
24420
diff
changeset
|
2484 // Ignore underscore in "[a, _, b] = list". |
78343859f42d
patch 8.2.2753: Vim9: cannot ignore an item in assignment unpack
Bram Moolenaar <Bram@vim.org>
parents:
24420
diff
changeset
|
2485 if (var_count > 0) |
78343859f42d
patch 8.2.2753: Vim9: cannot ignore an item in assignment unpack
Bram Moolenaar <Bram@vim.org>
parents:
24420
diff
changeset
|
2486 { |
78343859f42d
patch 8.2.2753: Vim9: cannot ignore an item in assignment unpack
Bram Moolenaar <Bram@vim.org>
parents:
24420
diff
changeset
|
2487 var_start = skipwhite(var_start + 2); |
78343859f42d
patch 8.2.2753: Vim9: cannot ignore an item in assignment unpack
Bram Moolenaar <Bram@vim.org>
parents:
24420
diff
changeset
|
2488 continue; |
78343859f42d
patch 8.2.2753: Vim9: cannot ignore an item in assignment unpack
Bram Moolenaar <Bram@vim.org>
parents:
24420
diff
changeset
|
2489 } |
78343859f42d
patch 8.2.2753: Vim9: cannot ignore an item in assignment unpack
Bram Moolenaar <Bram@vim.org>
parents:
24420
diff
changeset
|
2490 emsg(_(e_cannot_use_underscore_here)); |
78343859f42d
patch 8.2.2753: Vim9: cannot ignore an item in assignment unpack
Bram Moolenaar <Bram@vim.org>
parents:
24420
diff
changeset
|
2491 goto theend; |
78343859f42d
patch 8.2.2753: Vim9: cannot ignore an item in assignment unpack
Bram Moolenaar <Bram@vim.org>
parents:
24420
diff
changeset
|
2492 } |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2493 vim_free(lhs.lhs_name); |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2494 |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2495 /* |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2496 * Figure out the LHS type and other properties. |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2497 */ |
24490
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24488
diff
changeset
|
2498 if (compile_assign_lhs(var_start, &lhs, cmdidx, |
28281
bd1dcc605e58
patch 8.2.4666: Vim9: assignment not recognized in skipped block
Bram Moolenaar <Bram@vim.org>
parents:
28217
diff
changeset
|
2499 is_decl, heredoc, var_start > eap->cmd, |
bd1dcc605e58
patch 8.2.4666: Vim9: assignment not recognized in skipped block
Bram Moolenaar <Bram@vim.org>
parents:
28217
diff
changeset
|
2500 oplen, cctx) == FAIL) |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2501 goto theend; |
25405
747ebbce2421
patch 8.2.3239: Vim9: no error using heredoc for a number variable
Bram Moolenaar <Bram@vim.org>
parents:
25403
diff
changeset
|
2502 if (heredoc) |
747ebbce2421
patch 8.2.3239: Vim9: no error using heredoc for a number variable
Bram Moolenaar <Bram@vim.org>
parents:
25403
diff
changeset
|
2503 { |
747ebbce2421
patch 8.2.3239: Vim9: no error using heredoc for a number variable
Bram Moolenaar <Bram@vim.org>
parents:
25403
diff
changeset
|
2504 SOURCING_LNUM = start_lnum; |
747ebbce2421
patch 8.2.3239: Vim9: no error using heredoc for a number variable
Bram Moolenaar <Bram@vim.org>
parents:
25403
diff
changeset
|
2505 if (lhs.lhs_has_type |
31551
67d9fbe516a3
patch 9.0.1108: type error when using "any" type and adding to float
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
2506 && need_type(&t_list_string, lhs.lhs_type, FALSE, |
25405
747ebbce2421
patch 8.2.3239: Vim9: no error using heredoc for a number variable
Bram Moolenaar <Bram@vim.org>
parents:
25403
diff
changeset
|
2507 -1, 0, cctx, FALSE, FALSE) == FAIL) |
747ebbce2421
patch 8.2.3239: Vim9: no error using heredoc for a number variable
Bram Moolenaar <Bram@vim.org>
parents:
25403
diff
changeset
|
2508 goto theend; |
747ebbce2421
patch 8.2.3239: Vim9: no error using heredoc for a number variable
Bram Moolenaar <Bram@vim.org>
parents:
25403
diff
changeset
|
2509 } |
747ebbce2421
patch 8.2.3239: Vim9: no error using heredoc for a number variable
Bram Moolenaar <Bram@vim.org>
parents:
25403
diff
changeset
|
2510 else |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2511 { |
20907
4eeda7139133
patch 8.2.1005: Vim9: using TRUE/FALSE/MAYBE for ctx_skip is confusing
Bram Moolenaar <Bram@vim.org>
parents:
20899
diff
changeset
|
2512 if (cctx->ctx_skip == SKIP_YES) |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2513 { |
20899
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
2514 if (oplen > 0 && var_count == 0) |
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
2515 { |
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
2516 // skip over the "=" and the expression |
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
2517 p = skipwhite(op + oplen); |
24510
b5786b4de9d1
patch 8.2.2795: Coverity warns for not using return value
Bram Moolenaar <Bram@vim.org>
parents:
24502
diff
changeset
|
2518 (void)compile_expr0(&p, cctx); |
20899
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
2519 } |
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
2520 } |
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
2521 else if (oplen > 0) |
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
2522 { |
22631
59cd5f8b2ab2
patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents:
22627
diff
changeset
|
2523 int is_const = FALSE; |
23070
6a70803f4cbe
patch 8.2.2081: Vim9: cannot handle a linebreak after "=" in assignment
Bram Moolenaar <Bram@vim.org>
parents:
23068
diff
changeset
|
2524 char_u *wp; |
20899
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
2525 |
24984
71b1e2ef0069
patch 8.2.3029: Vim9: crash when using operator and list unpack assignment
Bram Moolenaar <Bram@vim.org>
parents:
24956
diff
changeset
|
2526 // for "+=", "*=", "..=" etc. first load the current value |
71b1e2ef0069
patch 8.2.3029: Vim9: crash when using operator and list unpack assignment
Bram Moolenaar <Bram@vim.org>
parents:
24956
diff
changeset
|
2527 if (*op != '=' |
71b1e2ef0069
patch 8.2.3029: Vim9: crash when using operator and list unpack assignment
Bram Moolenaar <Bram@vim.org>
parents:
24956
diff
changeset
|
2528 && compile_load_lhs_with_index(&lhs, var_start, |
71b1e2ef0069
patch 8.2.3029: Vim9: crash when using operator and list unpack assignment
Bram Moolenaar <Bram@vim.org>
parents:
24956
diff
changeset
|
2529 cctx) == FAIL) |
71b1e2ef0069
patch 8.2.3029: Vim9: crash when using operator and list unpack assignment
Bram Moolenaar <Bram@vim.org>
parents:
24956
diff
changeset
|
2530 goto theend; |
71b1e2ef0069
patch 8.2.3029: Vim9: crash when using operator and list unpack assignment
Bram Moolenaar <Bram@vim.org>
parents:
24956
diff
changeset
|
2531 |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2532 // For "var = expr" evaluate the expression. |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2533 if (var_count == 0) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2534 { |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2535 int r; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2536 |
24533
9c404d78d767
patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents:
24531
diff
changeset
|
2537 // Compile the expression. |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2538 instr_count = instr->ga_len; |
24533
9c404d78d767
patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents:
24531
diff
changeset
|
2539 if (incdec) |
9c404d78d767
patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents:
24531
diff
changeset
|
2540 { |
9c404d78d767
patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents:
24531
diff
changeset
|
2541 r = generate_PUSHNR(cctx, 1); |
9c404d78d767
patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents:
24531
diff
changeset
|
2542 } |
9c404d78d767
patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents:
24531
diff
changeset
|
2543 else |
23082
2120e4b40e12
patch 8.2.2087: Vim9: memory leak when statement is truncated
Bram Moolenaar <Bram@vim.org>
parents:
23072
diff
changeset
|
2544 { |
24533
9c404d78d767
patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents:
24531
diff
changeset
|
2545 // Temporarily hide the new local variable here, it is |
9c404d78d767
patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents:
24531
diff
changeset
|
2546 // not available to this expression. |
9c404d78d767
patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents:
24531
diff
changeset
|
2547 if (lhs.lhs_new_local) |
9c404d78d767
patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents:
24531
diff
changeset
|
2548 --cctx->ctx_locals.ga_len; |
9c404d78d767
patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents:
24531
diff
changeset
|
2549 wp = op + oplen; |
9c404d78d767
patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents:
24531
diff
changeset
|
2550 if (may_get_next_line_error(wp, &p, cctx) == FAIL) |
9c404d78d767
patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents:
24531
diff
changeset
|
2551 { |
9c404d78d767
patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents:
24531
diff
changeset
|
2552 if (lhs.lhs_new_local) |
9c404d78d767
patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents:
24531
diff
changeset
|
2553 ++cctx->ctx_locals.ga_len; |
9c404d78d767
patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents:
24531
diff
changeset
|
2554 goto theend; |
9c404d78d767
patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents:
24531
diff
changeset
|
2555 } |
9c404d78d767
patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents:
24531
diff
changeset
|
2556 r = compile_expr0_ext(&p, cctx, &is_const); |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2557 if (lhs.lhs_new_local) |
23082
2120e4b40e12
patch 8.2.2087: Vim9: memory leak when statement is truncated
Bram Moolenaar <Bram@vim.org>
parents:
23072
diff
changeset
|
2558 ++cctx->ctx_locals.ga_len; |
2120e4b40e12
patch 8.2.2087: Vim9: memory leak when statement is truncated
Bram Moolenaar <Bram@vim.org>
parents:
23072
diff
changeset
|
2559 } |
30053
f5cbf8a4043d
patch 9.0.0364: clang static analyzer gives warnings
Bram Moolenaar <Bram@vim.org>
parents:
30025
diff
changeset
|
2560 if (r == FAIL) |
f5cbf8a4043d
patch 9.0.0364: clang static analyzer gives warnings
Bram Moolenaar <Bram@vim.org>
parents:
30025
diff
changeset
|
2561 goto theend; |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2562 } |
20871
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20859
diff
changeset
|
2563 else if (semicolon && var_idx == var_count - 1) |
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20859
diff
changeset
|
2564 { |
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20859
diff
changeset
|
2565 // For "[var; var] = expr" get the rest of the list |
25034
8d660d1cca8d
patch 8.2.3054: Vim9: unpack assignment using "_" after semicolon fails
Bram Moolenaar <Bram@vim.org>
parents:
25032
diff
changeset
|
2566 did_generate_slice = TRUE; |
20871
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20859
diff
changeset
|
2567 if (generate_SLICE(cctx, var_count - 1) == FAIL) |
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20859
diff
changeset
|
2568 goto theend; |
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20859
diff
changeset
|
2569 } |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
2570 else |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
2571 { |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2572 // For "[var, var] = expr" get the "var_idx" item from the |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2573 // list. |
24984
71b1e2ef0069
patch 8.2.3029: Vim9: crash when using operator and list unpack assignment
Bram Moolenaar <Bram@vim.org>
parents:
24956
diff
changeset
|
2574 if (generate_GETITEM(cctx, var_idx, *op != '=') == FAIL) |
23070
6a70803f4cbe
patch 8.2.2081: Vim9: cannot handle a linebreak after "=" in assignment
Bram Moolenaar <Bram@vim.org>
parents:
23068
diff
changeset
|
2575 goto theend; |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2576 } |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2577 |
26935
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
2578 rhs_type = cctx->ctx_type_stack.ga_len == 0 ? &t_void |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
2579 : get_type_on_stack(cctx, 0); |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2580 if (lhs.lhs_lvar != NULL && (is_decl || !lhs.lhs_has_type)) |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2581 { |
23033
b98003d73150
patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents:
22975
diff
changeset
|
2582 if ((rhs_type->tt_type == VAR_FUNC |
b98003d73150
patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents:
22975
diff
changeset
|
2583 || rhs_type->tt_type == VAR_PARTIAL) |
24154
6e8f49a4a193
patch 8.2.2618: Vim9: cannot use a normal list name to store function refs
Bram Moolenaar <Bram@vim.org>
parents:
24152
diff
changeset
|
2584 && !lhs.lhs_has_index |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2585 && var_wrong_func_name(lhs.lhs_name, TRUE)) |
22236
3d0632b260fd
patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents:
22216
diff
changeset
|
2586 goto theend; |
3d0632b260fd
patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents:
22216
diff
changeset
|
2587 |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2588 if (lhs.lhs_new_local && !lhs.lhs_has_type) |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
2589 { |
23033
b98003d73150
patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents:
22975
diff
changeset
|
2590 if (rhs_type->tt_type == VAR_VOID) |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2591 { |
21821
0deb6f96a5a3
patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
21811
diff
changeset
|
2592 emsg(_(e_cannot_use_void_value)); |
20899
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
2593 goto theend; |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2594 } |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2595 else |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2596 { |
30576
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30335
diff
changeset
|
2597 type_T *type; |
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30335
diff
changeset
|
2598 |
22363
6c3d15011081
patch 8.2.1730: Vim9: cannot use member of unknown type
Bram Moolenaar <Bram@vim.org>
parents:
22343
diff
changeset
|
2599 // An empty list or dict has a &t_unknown member, |
20899
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
2600 // for a variable that implies &t_any. |
23033
b98003d73150
patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents:
22975
diff
changeset
|
2601 if (rhs_type == &t_list_empty) |
30576
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30335
diff
changeset
|
2602 type = &t_list_any; |
23033
b98003d73150
patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents:
22975
diff
changeset
|
2603 else if (rhs_type == &t_dict_empty) |
30576
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30335
diff
changeset
|
2604 type = &t_dict_any; |
23033
b98003d73150
patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents:
22975
diff
changeset
|
2605 else if (rhs_type == &t_unknown) |
30576
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30335
diff
changeset
|
2606 type = &t_any; |
20899
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
2607 else |
27728
fdc841530372
patch 8.2.4390: Vim9: list from declaration with inferred type not set
Bram Moolenaar <Bram@vim.org>
parents:
27716
diff
changeset
|
2608 { |
30576
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30335
diff
changeset
|
2609 type = rhs_type; |
27728
fdc841530372
patch 8.2.4390: Vim9: list from declaration with inferred type not set
Bram Moolenaar <Bram@vim.org>
parents:
27716
diff
changeset
|
2610 inferred_type = rhs_type; |
fdc841530372
patch 8.2.4390: Vim9: list from declaration with inferred type not set
Bram Moolenaar <Bram@vim.org>
parents:
27716
diff
changeset
|
2611 } |
30576
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30335
diff
changeset
|
2612 set_var_type(lhs.lhs_lvar, type, cctx); |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2613 } |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
2614 } |
21881
675bf9475fff
patch 8.2.1490: Vim9: using /= with float and number doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
21835
diff
changeset
|
2615 else if (*op == '=') |
20899
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
2616 { |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2617 type_T *use_type = lhs.lhs_lvar->lv_type; |
25547
ec4df0b982da
patch 8.2.3310: Vim9: unpack assignment does not mention source of type error
Bram Moolenaar <Bram@vim.org>
parents:
25541
diff
changeset
|
2618 where_T where = WHERE_INIT; |
20899
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
2619 |
24329
cd9f77409393
patch 8.2.2705: Vim9: misleading reported line number for wrong type
Bram Moolenaar <Bram@vim.org>
parents:
24295
diff
changeset
|
2620 // Without operator check type here, otherwise below. |
cd9f77409393
patch 8.2.2705: Vim9: misleading reported line number for wrong type
Bram Moolenaar <Bram@vim.org>
parents:
24295
diff
changeset
|
2621 // Use the line number of the assignment. |
cd9f77409393
patch 8.2.2705: Vim9: misleading reported line number for wrong type
Bram Moolenaar <Bram@vim.org>
parents:
24295
diff
changeset
|
2622 SOURCING_LNUM = start_lnum; |
25547
ec4df0b982da
patch 8.2.3310: Vim9: unpack assignment does not mention source of type error
Bram Moolenaar <Bram@vim.org>
parents:
25541
diff
changeset
|
2623 where.wt_index = var_count > 0 ? var_idx + 1 : 0; |
ec4df0b982da
patch 8.2.3310: Vim9: unpack assignment does not mention source of type error
Bram Moolenaar <Bram@vim.org>
parents:
25541
diff
changeset
|
2624 where.wt_variable = var_count > 0; |
25591
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25579
diff
changeset
|
2625 // If assigning to a list or dict member, use the |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25579
diff
changeset
|
2626 // member type. Not for "list[:] =". |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25579
diff
changeset
|
2627 if (lhs.lhs_has_index |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25579
diff
changeset
|
2628 && !has_list_index(var_start + lhs.lhs_varlen, |
ea69398b40d1
patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents:
25579
diff
changeset
|
2629 cctx)) |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2630 use_type = lhs.lhs_member_type; |
31551
67d9fbe516a3
patch 9.0.1108: type error when using "any" type and adding to float
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
2631 if (need_type_where(rhs_type, use_type, FALSE, -1, |
67d9fbe516a3
patch 9.0.1108: type error when using "any" type and adding to float
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
2632 where, cctx, FALSE, is_const) == FAIL) |
20899
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
2633 goto theend; |
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
2634 } |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
2635 } |
24956
d0b6a8d82cef
patch 8.2.3015: Vim9: Assigning to @# requires a string
Bram Moolenaar <Bram@vim.org>
parents:
24948
diff
changeset
|
2636 else |
d0b6a8d82cef
patch 8.2.3015: Vim9: Assigning to @# requires a string
Bram Moolenaar <Bram@vim.org>
parents:
24948
diff
changeset
|
2637 { |
d0b6a8d82cef
patch 8.2.3015: Vim9: Assigning to @# requires a string
Bram Moolenaar <Bram@vim.org>
parents:
24948
diff
changeset
|
2638 type_T *lhs_type = lhs.lhs_member_type; |
d0b6a8d82cef
patch 8.2.3015: Vim9: Assigning to @# requires a string
Bram Moolenaar <Bram@vim.org>
parents:
24948
diff
changeset
|
2639 |
d0b6a8d82cef
patch 8.2.3015: Vim9: Assigning to @# requires a string
Bram Moolenaar <Bram@vim.org>
parents:
24948
diff
changeset
|
2640 // Special case: assigning to @# can use a number or a |
d0b6a8d82cef
patch 8.2.3015: Vim9: Assigning to @# requires a string
Bram Moolenaar <Bram@vim.org>
parents:
24948
diff
changeset
|
2641 // string. |
25519
f7db86111acd
patch 8.2.3296: Vim9: cannot add a number to a float
Bram Moolenaar <Bram@vim.org>
parents:
25507
diff
changeset
|
2642 // Also: can assign a number to a float. |
f7db86111acd
patch 8.2.3296: Vim9: cannot add a number to a float
Bram Moolenaar <Bram@vim.org>
parents:
25507
diff
changeset
|
2643 if ((lhs_type == &t_number_or_string |
f7db86111acd
patch 8.2.3296: Vim9: cannot add a number to a float
Bram Moolenaar <Bram@vim.org>
parents:
25507
diff
changeset
|
2644 || lhs_type == &t_float) |
f7db86111acd
patch 8.2.3296: Vim9: cannot add a number to a float
Bram Moolenaar <Bram@vim.org>
parents:
25507
diff
changeset
|
2645 && rhs_type->tt_type == VAR_NUMBER) |
24956
d0b6a8d82cef
patch 8.2.3015: Vim9: Assigning to @# requires a string
Bram Moolenaar <Bram@vim.org>
parents:
24948
diff
changeset
|
2646 lhs_type = &t_number; |
31551
67d9fbe516a3
patch 9.0.1108: type error when using "any" type and adding to float
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
2647 if (*p != '=' && need_type(rhs_type, lhs_type, FALSE, |
23640
8dcb2255ff9a
patch 8.2.2362: Vim9: check of builtin function argument type is incomplete
Bram Moolenaar <Bram@vim.org>
parents:
23614
diff
changeset
|
2648 -1, 0, cctx, FALSE, FALSE) == FAIL) |
20899
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
2649 goto theend; |
24956
d0b6a8d82cef
patch 8.2.3015: Vim9: Assigning to @# requires a string
Bram Moolenaar <Bram@vim.org>
parents:
24948
diff
changeset
|
2650 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2651 } |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22381
diff
changeset
|
2652 else if (cmdidx == CMD_final) |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22381
diff
changeset
|
2653 { |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22381
diff
changeset
|
2654 emsg(_(e_final_requires_a_value)); |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22381
diff
changeset
|
2655 goto theend; |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22381
diff
changeset
|
2656 } |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2657 else if (cmdidx == CMD_const) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2658 { |
21789
f84625b961a8
patch 8.2.1444: error messages are spread out and names can be confusing
Bram Moolenaar <Bram@vim.org>
parents:
21771
diff
changeset
|
2659 emsg(_(e_const_requires_a_value)); |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2660 goto theend; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2661 } |
26470
ff0310e6f889
patch 8.2.3765: Vim9: cannot use a lambda for 'opfunc' and others
Bram Moolenaar <Bram@vim.org>
parents:
26441
diff
changeset
|
2662 else if (!lhs.lhs_has_type || lhs.lhs_dest == dest_option |
ff0310e6f889
patch 8.2.3765: Vim9: cannot use a lambda for 'opfunc' and others
Bram Moolenaar <Bram@vim.org>
parents:
26441
diff
changeset
|
2663 || lhs.lhs_dest == dest_func_option) |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2664 { |
21789
f84625b961a8
patch 8.2.1444: error messages are spread out and names can be confusing
Bram Moolenaar <Bram@vim.org>
parents:
21771
diff
changeset
|
2665 emsg(_(e_type_or_initialization_required)); |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
19904
diff
changeset
|
2666 goto theend; |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2667 } |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2668 else |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2669 { |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2670 // variables are always initialized |
25477
a8f526c9b172
patch 8.2.3275: optimizer can use hints about ga_grow() normally succeeding
Bram Moolenaar <Bram@vim.org>
parents:
25469
diff
changeset
|
2671 if (GA_GROW_FAILS(instr, 1)) |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2672 goto theend; |
31424
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2673 instr_count = instr->ga_len; |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2674 int r = push_default_value(cctx, lhs.lhs_member_type->tt_type, |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
2675 lhs.lhs_dest == dest_local, &skip_store); |
28678
a16dae0be398
patch 8.2.4863: accessing freed memory in test without the +channel feature
Bram Moolenaar <Bram@vim.org>
parents:
28598
diff
changeset
|
2676 if (r == FAIL) |
a16dae0be398
patch 8.2.4863: accessing freed memory in test without the +channel feature
Bram Moolenaar <Bram@vim.org>
parents:
28598
diff
changeset
|
2677 goto theend; |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2678 } |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2679 if (var_count == 0) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2680 end = p; |
19336
1cd6eab65ce0
patch 8.2.0226: compiling for loop not tested
Bram Moolenaar <Bram@vim.org>
parents:
19332
diff
changeset
|
2681 } |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2682 |
20899
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
2683 // no need to parse more when skipping |
20907
4eeda7139133
patch 8.2.1005: Vim9: using TRUE/FALSE/MAYBE for ctx_skip is confusing
Bram Moolenaar <Bram@vim.org>
parents:
20899
diff
changeset
|
2684 if (cctx->ctx_skip == SKIP_YES) |
20899
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
2685 break; |
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
2686 |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2687 if (oplen > 0 && *op != '=') |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2688 { |
21881
675bf9475fff
patch 8.2.1490: Vim9: using /= with float and number doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
21835
diff
changeset
|
2689 type_T *expected; |
25481
a975e2b7ea31
patch 8.2.3277: Vim9: compiled has() does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
25479
diff
changeset
|
2690 type_T *stacktype = NULL; |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2691 |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2692 if (*op == '.') |
25453
21b70bab366c
patch 8.2.3263: Vim9: "..=" does not accept same types as the ".." operator
Bram Moolenaar <Bram@vim.org>
parents:
25405
diff
changeset
|
2693 { |
21b70bab366c
patch 8.2.3263: Vim9: "..=" does not accept same types as the ".." operator
Bram Moolenaar <Bram@vim.org>
parents:
25405
diff
changeset
|
2694 if (may_generate_2STRING(-1, FALSE, cctx) == FAIL) |
21b70bab366c
patch 8.2.3263: Vim9: "..=" does not accept same types as the ".." operator
Bram Moolenaar <Bram@vim.org>
parents:
25405
diff
changeset
|
2695 goto theend; |
21b70bab366c
patch 8.2.3263: Vim9: "..=" does not accept same types as the ".." operator
Bram Moolenaar <Bram@vim.org>
parents:
25405
diff
changeset
|
2696 } |
21881
675bf9475fff
patch 8.2.1490: Vim9: using /= with float and number doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
21835
diff
changeset
|
2697 else |
25453
21b70bab366c
patch 8.2.3263: Vim9: "..=" does not accept same types as the ".." operator
Bram Moolenaar <Bram@vim.org>
parents:
25405
diff
changeset
|
2698 { |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2699 expected = lhs.lhs_member_type; |
26935
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
2700 stacktype = get_type_on_stack(cctx, 0); |
25453
21b70bab366c
patch 8.2.3263: Vim9: "..=" does not accept same types as the ".." operator
Bram Moolenaar <Bram@vim.org>
parents:
25405
diff
changeset
|
2701 if ( |
21b70bab366c
patch 8.2.3263: Vim9: "..=" does not accept same types as the ".." operator
Bram Moolenaar <Bram@vim.org>
parents:
25405
diff
changeset
|
2702 // If variable is float operation with number is OK. |
25483
0160aff01c32
patch 8.2.3278: Vim9: error when adding 1 to float
Bram Moolenaar <Bram@vim.org>
parents:
25481
diff
changeset
|
2703 !(expected == &t_float && (stacktype == &t_number |
31551
67d9fbe516a3
patch 9.0.1108: type error when using "any" type and adding to float
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
2704 || stacktype == &t_number_bool)) |
67d9fbe516a3
patch 9.0.1108: type error when using "any" type and adding to float
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
2705 && need_type(stacktype, expected, TRUE, -1, 0, cctx, |
22631
59cd5f8b2ab2
patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents:
22627
diff
changeset
|
2706 FALSE, FALSE) == FAIL) |
25453
21b70bab366c
patch 8.2.3263: Vim9: "..=" does not accept same types as the ".." operator
Bram Moolenaar <Bram@vim.org>
parents:
25405
diff
changeset
|
2707 goto theend; |
21b70bab366c
patch 8.2.3263: Vim9: "..=" does not accept same types as the ".." operator
Bram Moolenaar <Bram@vim.org>
parents:
25405
diff
changeset
|
2708 } |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2709 |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2710 if (*op == '.') |
21677
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
2711 { |
28598
d550054e1328
patch 8.2.4823: concat more than 2 strings in :def function is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28560
diff
changeset
|
2712 if (generate_CONCAT(cctx, 2) == FAIL) |
21677
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
2713 goto theend; |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
2714 } |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
2715 else if (*op == '+') |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
2716 { |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
2717 if (generate_add_instr(cctx, |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2718 operator_type(lhs.lhs_member_type, stacktype), |
25776
f31cf0388eab
patch 8.2.3423: Vim9: list += list creates a new list in :def function
Bram Moolenaar <Bram@vim.org>
parents:
25680
diff
changeset
|
2719 lhs.lhs_member_type, stacktype, |
f31cf0388eab
patch 8.2.3423: Vim9: list += list creates a new list in :def function
Bram Moolenaar <Bram@vim.org>
parents:
25680
diff
changeset
|
2720 EXPR_APPEND) == FAIL) |
21677
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
2721 goto theend; |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
2722 } |
21881
675bf9475fff
patch 8.2.1490: Vim9: using /= with float and number doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
21835
diff
changeset
|
2723 else if (generate_two_op(cctx, op) == FAIL) |
675bf9475fff
patch 8.2.1490: Vim9: using /= with float and number doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
21835
diff
changeset
|
2724 goto theend; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2725 } |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2726 |
25139
7fa520b85244
patch 8.2.3106: Vim9: confusing line number reported for error
Bram Moolenaar <Bram@vim.org>
parents:
25108
diff
changeset
|
2727 // Use the line number of the assignment for store instruction. |
7fa520b85244
patch 8.2.3106: Vim9: confusing line number reported for error
Bram Moolenaar <Bram@vim.org>
parents:
25108
diff
changeset
|
2728 save_lnum = cctx->ctx_lnum; |
7fa520b85244
patch 8.2.3106: Vim9: confusing line number reported for error
Bram Moolenaar <Bram@vim.org>
parents:
25108
diff
changeset
|
2729 cctx->ctx_lnum = start_lnum - 1; |
7fa520b85244
patch 8.2.3106: Vim9: confusing line number reported for error
Bram Moolenaar <Bram@vim.org>
parents:
25108
diff
changeset
|
2730 |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2731 if (lhs.lhs_has_index) |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2732 { |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2733 // Use the info in "lhs" to store the value at the index in the |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2734 // list or dict. |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2735 if (compile_assign_unlet(var_start, &lhs, TRUE, rhs_type, cctx) |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2736 == FAIL) |
25139
7fa520b85244
patch 8.2.3106: Vim9: confusing line number reported for error
Bram Moolenaar <Bram@vim.org>
parents:
25108
diff
changeset
|
2737 { |
7fa520b85244
patch 8.2.3106: Vim9: confusing line number reported for error
Bram Moolenaar <Bram@vim.org>
parents:
25108
diff
changeset
|
2738 cctx->ctx_lnum = save_lnum; |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2739 goto theend; |
25139
7fa520b85244
patch 8.2.3106: Vim9: confusing line number reported for error
Bram Moolenaar <Bram@vim.org>
parents:
25108
diff
changeset
|
2740 } |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
2741 } |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
2742 else |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
2743 { |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2744 if (is_decl && cmdidx == CMD_const && (lhs.lhs_dest == dest_script |
24293
bbf4b3185554
patch 8.2.2687: Vim9: cannot use "const" for global variable in :def function
Bram Moolenaar <Bram@vim.org>
parents:
24283
diff
changeset
|
2745 || lhs.lhs_dest == dest_global |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2746 || lhs.lhs_dest == dest_local)) |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22381
diff
changeset
|
2747 // ":const var": lock the value, but not referenced variables |
22272
eb1f5f618c75
patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents:
22266
diff
changeset
|
2748 generate_LOCKCONST(cctx); |
eb1f5f618c75
patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents:
22266
diff
changeset
|
2749 |
26937
7045e9308ca3
patch 8.2.3997: Vim9: not enough testing for extend() and map()
Bram Moolenaar <Bram@vim.org>
parents:
26935
diff
changeset
|
2750 if ((lhs.lhs_type->tt_type == VAR_DICT |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2751 || lhs.lhs_type->tt_type == VAR_LIST) |
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2752 && lhs.lhs_type->tt_member != NULL |
27728
fdc841530372
patch 8.2.4390: Vim9: list from declaration with inferred type not set
Bram Moolenaar <Bram@vim.org>
parents:
27716
diff
changeset
|
2753 && lhs.lhs_type->tt_member != &t_any |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2754 && lhs.lhs_type->tt_member != &t_unknown) |
23458
d2b1269c2c68
patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents:
23450
diff
changeset
|
2755 // Set the type in the list or dict, so that it can be checked, |
26937
7045e9308ca3
patch 8.2.3997: Vim9: not enough testing for extend() and map()
Bram Moolenaar <Bram@vim.org>
parents:
26935
diff
changeset
|
2756 // also in legacy script. |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2757 generate_SETTYPE(cctx, lhs.lhs_type); |
27728
fdc841530372
patch 8.2.4390: Vim9: list from declaration with inferred type not set
Bram Moolenaar <Bram@vim.org>
parents:
27716
diff
changeset
|
2758 else if (inferred_type != NULL |
fdc841530372
patch 8.2.4390: Vim9: list from declaration with inferred type not set
Bram Moolenaar <Bram@vim.org>
parents:
27716
diff
changeset
|
2759 && (inferred_type->tt_type == VAR_DICT |
fdc841530372
patch 8.2.4390: Vim9: list from declaration with inferred type not set
Bram Moolenaar <Bram@vim.org>
parents:
27716
diff
changeset
|
2760 || inferred_type->tt_type == VAR_LIST) |
fdc841530372
patch 8.2.4390: Vim9: list from declaration with inferred type not set
Bram Moolenaar <Bram@vim.org>
parents:
27716
diff
changeset
|
2761 && inferred_type->tt_member != NULL |
fdc841530372
patch 8.2.4390: Vim9: list from declaration with inferred type not set
Bram Moolenaar <Bram@vim.org>
parents:
27716
diff
changeset
|
2762 && inferred_type->tt_member != &t_unknown |
fdc841530372
patch 8.2.4390: Vim9: list from declaration with inferred type not set
Bram Moolenaar <Bram@vim.org>
parents:
27716
diff
changeset
|
2763 && inferred_type->tt_member != &t_any) |
fdc841530372
patch 8.2.4390: Vim9: list from declaration with inferred type not set
Bram Moolenaar <Bram@vim.org>
parents:
27716
diff
changeset
|
2764 // Set the type in the list or dict, so that it can be checked, |
fdc841530372
patch 8.2.4390: Vim9: list from declaration with inferred type not set
Bram Moolenaar <Bram@vim.org>
parents:
27716
diff
changeset
|
2765 // also in legacy script. |
fdc841530372
patch 8.2.4390: Vim9: list from declaration with inferred type not set
Bram Moolenaar <Bram@vim.org>
parents:
27716
diff
changeset
|
2766 generate_SETTYPE(cctx, inferred_type); |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2767 |
26729
b969fdb8cd46
patch 8.2.3893: Vim9: many local variables are initialized with an instruction
Bram Moolenaar <Bram@vim.org>
parents:
26680
diff
changeset
|
2768 if (!skip_store && generate_store_lhs(cctx, &lhs, |
b969fdb8cd46
patch 8.2.3893: Vim9: many local variables are initialized with an instruction
Bram Moolenaar <Bram@vim.org>
parents:
26680
diff
changeset
|
2769 instr_count, is_decl) == FAIL) |
25139
7fa520b85244
patch 8.2.3106: Vim9: confusing line number reported for error
Bram Moolenaar <Bram@vim.org>
parents:
25108
diff
changeset
|
2770 { |
7fa520b85244
patch 8.2.3106: Vim9: confusing line number reported for error
Bram Moolenaar <Bram@vim.org>
parents:
25108
diff
changeset
|
2771 cctx->ctx_lnum = save_lnum; |
24490
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24488
diff
changeset
|
2772 goto theend; |
25139
7fa520b85244
patch 8.2.3106: Vim9: confusing line number reported for error
Bram Moolenaar <Bram@vim.org>
parents:
25108
diff
changeset
|
2773 } |
7fa520b85244
patch 8.2.3106: Vim9: confusing line number reported for error
Bram Moolenaar <Bram@vim.org>
parents:
25108
diff
changeset
|
2774 } |
7fa520b85244
patch 8.2.3106: Vim9: confusing line number reported for error
Bram Moolenaar <Bram@vim.org>
parents:
25108
diff
changeset
|
2775 cctx->ctx_lnum = save_lnum; |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2776 |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2777 if (var_idx + 1 < var_count) |
26346
8be6413a8e27
patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
26340
diff
changeset
|
2778 var_start = skipwhite(lhs.lhs_end + 1); |
31441
e572ff386670
patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents:
31424
diff
changeset
|
2779 |
e572ff386670
patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents:
31424
diff
changeset
|
2780 if (has_arg_is_set_prefix) |
e572ff386670
patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents:
31424
diff
changeset
|
2781 { |
e572ff386670
patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents:
31424
diff
changeset
|
2782 // set instruction index in JUMP_IF_ARG_SET to here |
e572ff386670
patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents:
31424
diff
changeset
|
2783 isn_T *isn = ((isn_T *)instr->ga_data) + jump_instr_idx; |
e572ff386670
patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents:
31424
diff
changeset
|
2784 isn->isn_arg.jumparg.jump_where = instr->ga_len; |
e572ff386670
patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents:
31424
diff
changeset
|
2785 } |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2786 } |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2787 |
25034
8d660d1cca8d
patch 8.2.3054: Vim9: unpack assignment using "_" after semicolon fails
Bram Moolenaar <Bram@vim.org>
parents:
25032
diff
changeset
|
2788 // For "[var, var] = expr" drop the "expr" value. |
8d660d1cca8d
patch 8.2.3054: Vim9: unpack assignment using "_" after semicolon fails
Bram Moolenaar <Bram@vim.org>
parents:
25032
diff
changeset
|
2789 // Also for "[var, var; _] = expr". |
8d660d1cca8d
patch 8.2.3054: Vim9: unpack assignment using "_" after semicolon fails
Bram Moolenaar <Bram@vim.org>
parents:
25032
diff
changeset
|
2790 if (var_count > 0 && (!semicolon || !did_generate_slice)) |
20871
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20859
diff
changeset
|
2791 { |
23195
75f35ae990ac
patch 8.2.2143: Vim9: dead code in compiling :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23187
diff
changeset
|
2792 if (generate_instr_drop(cctx, ISN_DROP, 1) == NULL) |
20871
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20859
diff
changeset
|
2793 goto theend; |
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20859
diff
changeset
|
2794 } |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
2795 |
21391
8b882afa8ed2
patch 8.2.1246: Vim9: comment after assignment doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
21387
diff
changeset
|
2796 ret = skipwhite(end); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2797 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2798 theend: |
23517
36bf9a6fbd4c
patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents:
23515
diff
changeset
|
2799 vim_free(lhs.lhs_name); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2800 return ret; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2801 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2802 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2803 /* |
23537
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2804 * Check for an assignment at "eap->cmd", compile it if found. |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2805 * Return NOTDONE if there is none, FAIL for failure, OK if done. |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2806 */ |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2807 static int |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2808 may_compile_assignment(exarg_T *eap, char_u **line, cctx_T *cctx) |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2809 { |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2810 char_u *pskip; |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2811 char_u *p; |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2812 |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2813 // Assuming the command starts with a variable or function name, |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2814 // find what follows. |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2815 // Skip over "var.member", "var[idx]" and the like. |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2816 // Also "&opt = val", "$ENV = val" and "@r = val". |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2817 pskip = (*eap->cmd == '&' || *eap->cmd == '$' || *eap->cmd == '@') |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2818 ? eap->cmd + 1 : eap->cmd; |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2819 p = to_name_end(pskip, TRUE); |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2820 if (p > eap->cmd && *p != NUL) |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2821 { |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2822 char_u *var_end; |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2823 int oplen; |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2824 int heredoc; |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2825 |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2826 if (eap->cmd[0] == '@') |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2827 var_end = eap->cmd + 2; |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2828 else |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2829 var_end = find_name_end(pskip, NULL, NULL, |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2830 FNE_CHECK_START | FNE_INCL_BR); |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2831 oplen = assignment_len(skipwhite(var_end), &heredoc); |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2832 if (oplen > 0) |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2833 { |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2834 size_t len = p - eap->cmd; |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2835 |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2836 // Recognize an assignment if we recognize the variable |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2837 // name: |
28129
dd2ed5345f20
patch 8.2.4589: cannot index the g: dictionary
Bram Moolenaar <Bram@vim.org>
parents:
28101
diff
changeset
|
2838 // "&opt = expr" |
dd2ed5345f20
patch 8.2.4589: cannot index the g: dictionary
Bram Moolenaar <Bram@vim.org>
parents:
28101
diff
changeset
|
2839 // "$ENV = expr" |
dd2ed5345f20
patch 8.2.4589: cannot index the g: dictionary
Bram Moolenaar <Bram@vim.org>
parents:
28101
diff
changeset
|
2840 // "@r = expr" |
23537
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2841 // "g:var = expr" |
28129
dd2ed5345f20
patch 8.2.4589: cannot index the g: dictionary
Bram Moolenaar <Bram@vim.org>
parents:
28101
diff
changeset
|
2842 // "g:[key] = expr" |
23537
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2843 // "local = expr" where "local" is a local var. |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2844 // "script = expr" where "script" is a script-local var. |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2845 // "import = expr" where "import" is an imported var |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2846 if (*eap->cmd == '&' |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2847 || *eap->cmd == '$' |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2848 || *eap->cmd == '@' |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2849 || ((len) > 2 && eap->cmd[1] == ':') |
28129
dd2ed5345f20
patch 8.2.4589: cannot index the g: dictionary
Bram Moolenaar <Bram@vim.org>
parents:
28101
diff
changeset
|
2850 || STRNCMP(eap->cmd, "g:[", 3) == 0 |
23966
09bde146adcb
patch 8.2.2525: Vim9: only local variables checked for a name
Bram Moolenaar <Bram@vim.org>
parents:
23948
diff
changeset
|
2851 || variable_exists(eap->cmd, len, cctx)) |
23537
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2852 { |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2853 *line = compile_assignment(eap->cmd, eap, CMD_SIZE, cctx); |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2854 if (*line == NULL || *line == eap->cmd) |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2855 return FAIL; |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2856 return OK; |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2857 } |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2858 } |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2859 } |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2860 |
31441
e572ff386670
patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents:
31424
diff
changeset
|
2861 // might be "[var, var] = expr" or "ifargisset this.member = expr" |
e572ff386670
patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents:
31424
diff
changeset
|
2862 if (*eap->cmd == '[' || STRNCMP(eap->cmd, "ifargisset ", 11) == 0) |
23537
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2863 { |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2864 *line = compile_assignment(eap->cmd, eap, CMD_SIZE, cctx); |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2865 if (*line == NULL) |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2866 return FAIL; |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2867 if (*line != eap->cmd) |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2868 return OK; |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2869 } |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2870 return NOTDONE; |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2871 } |
7f0fc2ab90e3
patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents:
23531
diff
changeset
|
2872 |
26851
15913ba6363e
patch 8.2.3954: Vim9: no error for shadowing if script var is declared later
Bram Moolenaar <Bram@vim.org>
parents:
26845
diff
changeset
|
2873 /* |
15913ba6363e
patch 8.2.3954: Vim9: no error for shadowing if script var is declared later
Bram Moolenaar <Bram@vim.org>
parents:
26845
diff
changeset
|
2874 * Check if arguments of "ufunc" shadow variables in "cctx". |
15913ba6363e
patch 8.2.3954: Vim9: no error for shadowing if script var is declared later
Bram Moolenaar <Bram@vim.org>
parents:
26845
diff
changeset
|
2875 * Return OK or FAIL. |
15913ba6363e
patch 8.2.3954: Vim9: no error for shadowing if script var is declared later
Bram Moolenaar <Bram@vim.org>
parents:
26845
diff
changeset
|
2876 */ |
15913ba6363e
patch 8.2.3954: Vim9: no error for shadowing if script var is declared later
Bram Moolenaar <Bram@vim.org>
parents:
26845
diff
changeset
|
2877 static int |
15913ba6363e
patch 8.2.3954: Vim9: no error for shadowing if script var is declared later
Bram Moolenaar <Bram@vim.org>
parents:
26845
diff
changeset
|
2878 check_args_shadowing(ufunc_T *ufunc, cctx_T *cctx) |
15913ba6363e
patch 8.2.3954: Vim9: no error for shadowing if script var is declared later
Bram Moolenaar <Bram@vim.org>
parents:
26845
diff
changeset
|
2879 { |
15913ba6363e
patch 8.2.3954: Vim9: no error for shadowing if script var is declared later
Bram Moolenaar <Bram@vim.org>
parents:
26845
diff
changeset
|
2880 int i; |
15913ba6363e
patch 8.2.3954: Vim9: no error for shadowing if script var is declared later
Bram Moolenaar <Bram@vim.org>
parents:
26845
diff
changeset
|
2881 char_u *arg; |
15913ba6363e
patch 8.2.3954: Vim9: no error for shadowing if script var is declared later
Bram Moolenaar <Bram@vim.org>
parents:
26845
diff
changeset
|
2882 int r = OK; |
15913ba6363e
patch 8.2.3954: Vim9: no error for shadowing if script var is declared later
Bram Moolenaar <Bram@vim.org>
parents:
26845
diff
changeset
|
2883 |
15913ba6363e
patch 8.2.3954: Vim9: no error for shadowing if script var is declared later
Bram Moolenaar <Bram@vim.org>
parents:
26845
diff
changeset
|
2884 // Make sure arguments are not found when compiling a second time. |
15913ba6363e
patch 8.2.3954: Vim9: no error for shadowing if script var is declared later
Bram Moolenaar <Bram@vim.org>
parents:
26845
diff
changeset
|
2885 ufunc->uf_args_visible = 0; |
15913ba6363e
patch 8.2.3954: Vim9: no error for shadowing if script var is declared later
Bram Moolenaar <Bram@vim.org>
parents:
26845
diff
changeset
|
2886 |
15913ba6363e
patch 8.2.3954: Vim9: no error for shadowing if script var is declared later
Bram Moolenaar <Bram@vim.org>
parents:
26845
diff
changeset
|
2887 // Check for arguments shadowing variables from the context. |
15913ba6363e
patch 8.2.3954: Vim9: no error for shadowing if script var is declared later
Bram Moolenaar <Bram@vim.org>
parents:
26845
diff
changeset
|
2888 for (i = 0; i < ufunc->uf_args.ga_len; ++i) |
15913ba6363e
patch 8.2.3954: Vim9: no error for shadowing if script var is declared later
Bram Moolenaar <Bram@vim.org>
parents:
26845
diff
changeset
|
2889 { |
15913ba6363e
patch 8.2.3954: Vim9: no error for shadowing if script var is declared later
Bram Moolenaar <Bram@vim.org>
parents:
26845
diff
changeset
|
2890 arg = ((char_u **)(ufunc->uf_args.ga_data))[i]; |
27611
e311a80f8cbe
patch 8.2.4332: Vim9: incomplete test for existing script variable in block
Bram Moolenaar <Bram@vim.org>
parents:
27595
diff
changeset
|
2891 if (check_defined(arg, STRLEN(arg), cctx, NULL, TRUE) == FAIL) |
26851
15913ba6363e
patch 8.2.3954: Vim9: no error for shadowing if script var is declared later
Bram Moolenaar <Bram@vim.org>
parents:
26845
diff
changeset
|
2892 { |
15913ba6363e
patch 8.2.3954: Vim9: no error for shadowing if script var is declared later
Bram Moolenaar <Bram@vim.org>
parents:
26845
diff
changeset
|
2893 r = FAIL; |
15913ba6363e
patch 8.2.3954: Vim9: no error for shadowing if script var is declared later
Bram Moolenaar <Bram@vim.org>
parents:
26845
diff
changeset
|
2894 break; |
15913ba6363e
patch 8.2.3954: Vim9: no error for shadowing if script var is declared later
Bram Moolenaar <Bram@vim.org>
parents:
26845
diff
changeset
|
2895 } |
15913ba6363e
patch 8.2.3954: Vim9: no error for shadowing if script var is declared later
Bram Moolenaar <Bram@vim.org>
parents:
26845
diff
changeset
|
2896 } |
15913ba6363e
patch 8.2.3954: Vim9: no error for shadowing if script var is declared later
Bram Moolenaar <Bram@vim.org>
parents:
26845
diff
changeset
|
2897 ufunc->uf_args_visible = ufunc->uf_args.ga_len; |
15913ba6363e
patch 8.2.3954: Vim9: no error for shadowing if script var is declared later
Bram Moolenaar <Bram@vim.org>
parents:
26845
diff
changeset
|
2898 return r; |
15913ba6363e
patch 8.2.3954: Vim9: no error for shadowing if script var is declared later
Bram Moolenaar <Bram@vim.org>
parents:
26845
diff
changeset
|
2899 } |
15913ba6363e
patch 8.2.3954: Vim9: no error for shadowing if script var is declared later
Bram Moolenaar <Bram@vim.org>
parents:
26845
diff
changeset
|
2900 |
30709
223865a5f0f0
patch 9.0.0689: compiler warning for unused function
Bram Moolenaar <Bram@vim.org>
parents:
30699
diff
changeset
|
2901 #ifdef HAS_MESSAGE_WINDOW |
28101
3bc0a639dfb0
patch 8.2.4575: Vim9: test for profiling still fails
Bram Moolenaar <Bram@vim.org>
parents:
28097
diff
changeset
|
2902 /* |
30697
d914a3812d5b
patch 9.0.0683: cannot specify a time for :echowindow
Bram Moolenaar <Bram@vim.org>
parents:
30584
diff
changeset
|
2903 * Get a count before a command. Can only be a number. |
d914a3812d5b
patch 9.0.0683: cannot specify a time for :echowindow
Bram Moolenaar <Bram@vim.org>
parents:
30584
diff
changeset
|
2904 * Returns zero if there is no count. |
d914a3812d5b
patch 9.0.0683: cannot specify a time for :echowindow
Bram Moolenaar <Bram@vim.org>
parents:
30584
diff
changeset
|
2905 * Returns -1 if there is something wrong. |
d914a3812d5b
patch 9.0.0683: cannot specify a time for :echowindow
Bram Moolenaar <Bram@vim.org>
parents:
30584
diff
changeset
|
2906 */ |
d914a3812d5b
patch 9.0.0683: cannot specify a time for :echowindow
Bram Moolenaar <Bram@vim.org>
parents:
30584
diff
changeset
|
2907 static long |
d914a3812d5b
patch 9.0.0683: cannot specify a time for :echowindow
Bram Moolenaar <Bram@vim.org>
parents:
30584
diff
changeset
|
2908 get_cmd_count(char_u *line, exarg_T *eap) |
d914a3812d5b
patch 9.0.0683: cannot specify a time for :echowindow
Bram Moolenaar <Bram@vim.org>
parents:
30584
diff
changeset
|
2909 { |
d914a3812d5b
patch 9.0.0683: cannot specify a time for :echowindow
Bram Moolenaar <Bram@vim.org>
parents:
30584
diff
changeset
|
2910 char_u *p; |
d914a3812d5b
patch 9.0.0683: cannot specify a time for :echowindow
Bram Moolenaar <Bram@vim.org>
parents:
30584
diff
changeset
|
2911 |
d914a3812d5b
patch 9.0.0683: cannot specify a time for :echowindow
Bram Moolenaar <Bram@vim.org>
parents:
30584
diff
changeset
|
2912 // skip over colons and white space |
d914a3812d5b
patch 9.0.0683: cannot specify a time for :echowindow
Bram Moolenaar <Bram@vim.org>
parents:
30584
diff
changeset
|
2913 for (p = line; *p == ':' || VIM_ISWHITE(*p); ++p) |
d914a3812d5b
patch 9.0.0683: cannot specify a time for :echowindow
Bram Moolenaar <Bram@vim.org>
parents:
30584
diff
changeset
|
2914 ; |
d914a3812d5b
patch 9.0.0683: cannot specify a time for :echowindow
Bram Moolenaar <Bram@vim.org>
parents:
30584
diff
changeset
|
2915 if (!isdigit(*p)) |
d914a3812d5b
patch 9.0.0683: cannot specify a time for :echowindow
Bram Moolenaar <Bram@vim.org>
parents:
30584
diff
changeset
|
2916 { |
30954
3e8aed429cc5
patch 9.0.0811: error if :echowin is preceded by a command modifier
Bram Moolenaar <Bram@vim.org>
parents:
30815
diff
changeset
|
2917 // The command or modifiers must be following. Assume a lower case |
3e8aed429cc5
patch 9.0.0811: error if :echowin is preceded by a command modifier
Bram Moolenaar <Bram@vim.org>
parents:
30815
diff
changeset
|
2918 // character means there is a modifier. |
3e8aed429cc5
patch 9.0.0811: error if :echowin is preceded by a command modifier
Bram Moolenaar <Bram@vim.org>
parents:
30815
diff
changeset
|
2919 if (p < eap->cmd && !vim_islower(*p)) |
30697
d914a3812d5b
patch 9.0.0683: cannot specify a time for :echowindow
Bram Moolenaar <Bram@vim.org>
parents:
30584
diff
changeset
|
2920 { |
d914a3812d5b
patch 9.0.0683: cannot specify a time for :echowindow
Bram Moolenaar <Bram@vim.org>
parents:
30584
diff
changeset
|
2921 emsg(_(e_invalid_range)); |
d914a3812d5b
patch 9.0.0683: cannot specify a time for :echowindow
Bram Moolenaar <Bram@vim.org>
parents:
30584
diff
changeset
|
2922 return -1; |
d914a3812d5b
patch 9.0.0683: cannot specify a time for :echowindow
Bram Moolenaar <Bram@vim.org>
parents:
30584
diff
changeset
|
2923 } |
d914a3812d5b
patch 9.0.0683: cannot specify a time for :echowindow
Bram Moolenaar <Bram@vim.org>
parents:
30584
diff
changeset
|
2924 return 0; |
d914a3812d5b
patch 9.0.0683: cannot specify a time for :echowindow
Bram Moolenaar <Bram@vim.org>
parents:
30584
diff
changeset
|
2925 } |
d914a3812d5b
patch 9.0.0683: cannot specify a time for :echowindow
Bram Moolenaar <Bram@vim.org>
parents:
30584
diff
changeset
|
2926 return atol((char *)p); |
d914a3812d5b
patch 9.0.0683: cannot specify a time for :echowindow
Bram Moolenaar <Bram@vim.org>
parents:
30584
diff
changeset
|
2927 } |
30709
223865a5f0f0
patch 9.0.0689: compiler warning for unused function
Bram Moolenaar <Bram@vim.org>
parents:
30699
diff
changeset
|
2928 #endif |
30697
d914a3812d5b
patch 9.0.0683: cannot specify a time for :echowindow
Bram Moolenaar <Bram@vim.org>
parents:
30584
diff
changeset
|
2929 |
d914a3812d5b
patch 9.0.0683: cannot specify a time for :echowindow
Bram Moolenaar <Bram@vim.org>
parents:
30584
diff
changeset
|
2930 /* |
28101
3bc0a639dfb0
patch 8.2.4575: Vim9: test for profiling still fails
Bram Moolenaar <Bram@vim.org>
parents:
28097
diff
changeset
|
2931 * Get the compilation type that should be used for "ufunc". |
3bc0a639dfb0
patch 8.2.4575: Vim9: test for profiling still fails
Bram Moolenaar <Bram@vim.org>
parents:
28097
diff
changeset
|
2932 * Keep in sync with INSTRUCTIONS(). |
3bc0a639dfb0
patch 8.2.4575: Vim9: test for profiling still fails
Bram Moolenaar <Bram@vim.org>
parents:
28097
diff
changeset
|
2933 */ |
3bc0a639dfb0
patch 8.2.4575: Vim9: test for profiling still fails
Bram Moolenaar <Bram@vim.org>
parents:
28097
diff
changeset
|
2934 compiletype_T |
3bc0a639dfb0
patch 8.2.4575: Vim9: test for profiling still fails
Bram Moolenaar <Bram@vim.org>
parents:
28097
diff
changeset
|
2935 get_compile_type(ufunc_T *ufunc) |
3bc0a639dfb0
patch 8.2.4575: Vim9: test for profiling still fails
Bram Moolenaar <Bram@vim.org>
parents:
28097
diff
changeset
|
2936 { |
3bc0a639dfb0
patch 8.2.4575: Vim9: test for profiling still fails
Bram Moolenaar <Bram@vim.org>
parents:
28097
diff
changeset
|
2937 // Update uf_has_breakpoint if needed. |
3bc0a639dfb0
patch 8.2.4575: Vim9: test for profiling still fails
Bram Moolenaar <Bram@vim.org>
parents:
28097
diff
changeset
|
2938 update_has_breakpoint(ufunc); |
3bc0a639dfb0
patch 8.2.4575: Vim9: test for profiling still fails
Bram Moolenaar <Bram@vim.org>
parents:
28097
diff
changeset
|
2939 |
3bc0a639dfb0
patch 8.2.4575: Vim9: test for profiling still fails
Bram Moolenaar <Bram@vim.org>
parents:
28097
diff
changeset
|
2940 if (debug_break_level > 0 || may_break_in_function(ufunc)) |
3bc0a639dfb0
patch 8.2.4575: Vim9: test for profiling still fails
Bram Moolenaar <Bram@vim.org>
parents:
28097
diff
changeset
|
2941 return CT_DEBUG; |
3bc0a639dfb0
patch 8.2.4575: Vim9: test for profiling still fails
Bram Moolenaar <Bram@vim.org>
parents:
28097
diff
changeset
|
2942 #ifdef FEAT_PROFILE |
3bc0a639dfb0
patch 8.2.4575: Vim9: test for profiling still fails
Bram Moolenaar <Bram@vim.org>
parents:
28097
diff
changeset
|
2943 if (do_profiling == PROF_YES) |
3bc0a639dfb0
patch 8.2.4575: Vim9: test for profiling still fails
Bram Moolenaar <Bram@vim.org>
parents:
28097
diff
changeset
|
2944 { |
3bc0a639dfb0
patch 8.2.4575: Vim9: test for profiling still fails
Bram Moolenaar <Bram@vim.org>
parents:
28097
diff
changeset
|
2945 if (!ufunc->uf_profiling && has_profiling(FALSE, ufunc->uf_name, NULL)) |
3bc0a639dfb0
patch 8.2.4575: Vim9: test for profiling still fails
Bram Moolenaar <Bram@vim.org>
parents:
28097
diff
changeset
|
2946 func_do_profile(ufunc); |
3bc0a639dfb0
patch 8.2.4575: Vim9: test for profiling still fails
Bram Moolenaar <Bram@vim.org>
parents:
28097
diff
changeset
|
2947 if (ufunc->uf_profiling) |
3bc0a639dfb0
patch 8.2.4575: Vim9: test for profiling still fails
Bram Moolenaar <Bram@vim.org>
parents:
28097
diff
changeset
|
2948 return CT_PROFILE; |
3bc0a639dfb0
patch 8.2.4575: Vim9: test for profiling still fails
Bram Moolenaar <Bram@vim.org>
parents:
28097
diff
changeset
|
2949 } |
3bc0a639dfb0
patch 8.2.4575: Vim9: test for profiling still fails
Bram Moolenaar <Bram@vim.org>
parents:
28097
diff
changeset
|
2950 #endif |
3bc0a639dfb0
patch 8.2.4575: Vim9: test for profiling still fails
Bram Moolenaar <Bram@vim.org>
parents:
28097
diff
changeset
|
2951 return CT_NONE; |
3bc0a639dfb0
patch 8.2.4575: Vim9: test for profiling still fails
Bram Moolenaar <Bram@vim.org>
parents:
28097
diff
changeset
|
2952 } |
3bc0a639dfb0
patch 8.2.4575: Vim9: test for profiling still fails
Bram Moolenaar <Bram@vim.org>
parents:
28097
diff
changeset
|
2953 |
25939
377a7686a52f
patch 8.2.3503: Vim9: using g:pat:cmd is confusing
Bram Moolenaar <Bram@vim.org>
parents:
25816
diff
changeset
|
2954 |
377a7686a52f
patch 8.2.3503: Vim9: using g:pat:cmd is confusing
Bram Moolenaar <Bram@vim.org>
parents:
25816
diff
changeset
|
2955 /* |
20339
7587d892c00c
patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20336
diff
changeset
|
2956 * Add a function to the list of :def functions. |
20943
1693ca876049
patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents:
20933
diff
changeset
|
2957 * This sets "ufunc->uf_dfunc_idx" but the function isn't compiled yet. |
20339
7587d892c00c
patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20336
diff
changeset
|
2958 */ |
20528
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20419
diff
changeset
|
2959 static int |
20339
7587d892c00c
patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20336
diff
changeset
|
2960 add_def_function(ufunc_T *ufunc) |
7587d892c00c
patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20336
diff
changeset
|
2961 { |
7587d892c00c
patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20336
diff
changeset
|
2962 dfunc_T *dfunc; |
7587d892c00c
patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20336
diff
changeset
|
2963 |
20943
1693ca876049
patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents:
20933
diff
changeset
|
2964 if (def_functions.ga_len == 0) |
1693ca876049
patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents:
20933
diff
changeset
|
2965 { |
1693ca876049
patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents:
20933
diff
changeset
|
2966 // The first position is not used, so that a zero uf_dfunc_idx means it |
1693ca876049
patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents:
20933
diff
changeset
|
2967 // wasn't set. |
25477
a8f526c9b172
patch 8.2.3275: optimizer can use hints about ga_grow() normally succeeding
Bram Moolenaar <Bram@vim.org>
parents:
25469
diff
changeset
|
2968 if (GA_GROW_FAILS(&def_functions, 1)) |
20943
1693ca876049
patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents:
20933
diff
changeset
|
2969 return FAIL; |
1693ca876049
patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents:
20933
diff
changeset
|
2970 ++def_functions.ga_len; |
1693ca876049
patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents:
20933
diff
changeset
|
2971 } |
1693ca876049
patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents:
20933
diff
changeset
|
2972 |
20339
7587d892c00c
patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20336
diff
changeset
|
2973 // Add the function to "def_functions". |
25477
a8f526c9b172
patch 8.2.3275: optimizer can use hints about ga_grow() normally succeeding
Bram Moolenaar <Bram@vim.org>
parents:
25469
diff
changeset
|
2974 if (GA_GROW_FAILS(&def_functions, 1)) |
20339
7587d892c00c
patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20336
diff
changeset
|
2975 return FAIL; |
7587d892c00c
patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20336
diff
changeset
|
2976 dfunc = ((dfunc_T *)def_functions.ga_data) + def_functions.ga_len; |
7587d892c00c
patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20336
diff
changeset
|
2977 CLEAR_POINTER(dfunc); |
7587d892c00c
patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20336
diff
changeset
|
2978 dfunc->df_idx = def_functions.ga_len; |
7587d892c00c
patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20336
diff
changeset
|
2979 ufunc->uf_dfunc_idx = dfunc->df_idx; |
7587d892c00c
patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20336
diff
changeset
|
2980 dfunc->df_ufunc = ufunc; |
23285
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23266
diff
changeset
|
2981 dfunc->df_name = vim_strsave(ufunc->uf_name); |
24918
f11779c1d123
patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents:
24914
diff
changeset
|
2982 ga_init2(&dfunc->df_var_names, sizeof(char_u *), 10); |
23285
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23266
diff
changeset
|
2983 ++dfunc->df_refcount; |
20339
7587d892c00c
patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20336
diff
changeset
|
2984 ++def_functions.ga_len; |
7587d892c00c
patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20336
diff
changeset
|
2985 return OK; |
7587d892c00c
patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20336
diff
changeset
|
2986 } |
7587d892c00c
patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20336
diff
changeset
|
2987 |
7587d892c00c
patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20336
diff
changeset
|
2988 /* |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2989 * After ex_function() has collected all the function lines: parse and compile |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2990 * the lines into instructions. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2991 * Adds the function to "def_functions". |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23330
diff
changeset
|
2992 * When "check_return_type" is set then set ufunc->uf_ret_type to the type of |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23330
diff
changeset
|
2993 * the return statement (used for lambda). When uf_ret_type is already set |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23330
diff
changeset
|
2994 * then check that it matches. |
23717
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23697
diff
changeset
|
2995 * When "profiling" is true add ISN_PROF_START instructions. |
20244
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
2996 * "outer_cctx" is set for a nested function. |
19864
8288884fdfe1
patch 8.2.0488: Vim9: compiling can break when using a lambda inside :def
Bram Moolenaar <Bram@vim.org>
parents:
19862
diff
changeset
|
2997 * This can be used recursively through compile_lambda(), which may reallocate |
8288884fdfe1
patch 8.2.0488: Vim9: compiling can break when using a lambda inside :def
Bram Moolenaar <Bram@vim.org>
parents:
19862
diff
changeset
|
2998 * "def_functions". |
20528
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20419
diff
changeset
|
2999 * Returns OK or FAIL. |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3000 */ |
20528
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20419
diff
changeset
|
3001 int |
23717
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23697
diff
changeset
|
3002 compile_def_function( |
24895
e61a2085c89b
patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents:
24893
diff
changeset
|
3003 ufunc_T *ufunc, |
e61a2085c89b
patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents:
24893
diff
changeset
|
3004 int check_return_type, |
e61a2085c89b
patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents:
24893
diff
changeset
|
3005 compiletype_T compile_type, |
e61a2085c89b
patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents:
24893
diff
changeset
|
3006 cctx_T *outer_cctx) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3007 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3008 char_u *line = NULL; |
27022
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26980
diff
changeset
|
3009 garray_T lines_to_free; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3010 char_u *p; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3011 char *errormsg = NULL; // error message |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3012 cctx_T cctx; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3013 garray_T *instr; |
22758
48feb3dd0d25
patch 8.2.1927: Vim9: get unknown error with an error in a timer function
Bram Moolenaar <Bram@vim.org>
parents:
22734
diff
changeset
|
3014 int did_emsg_before = did_emsg; |
24406
a26f0fa12845
patch 8.2.2743: Vim9: function state stuck when compiling with ":silent!"
Bram Moolenaar <Bram@vim.org>
parents:
24404
diff
changeset
|
3015 int did_emsg_silent_before = did_emsg_silent; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3016 int ret = FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3017 sctx_T save_current_sctx = current_sctx; |
22584
c271498e03b2
patch 8.2.1840: Vim9: error message is not clear about compilation error
Bram Moolenaar <Bram@vim.org>
parents:
22537
diff
changeset
|
3018 int save_estack_compiling = estack_compiling; |
24539
3a290891a015
patch 8.2.2809: Vim9: :def function compilation fails when using :legacy
Bram Moolenaar <Bram@vim.org>
parents:
24533
diff
changeset
|
3019 int save_cmod_flags = cmdmod.cmod_flags; |
20538
9f921ba86d05
patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents:
20534
diff
changeset
|
3020 int do_estack_push; |
21463
7f36d36f7195
patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents:
21455
diff
changeset
|
3021 int new_def_function = FALSE; |
23719
1a7c2685d780
patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents:
23717
diff
changeset
|
3022 #ifdef FEAT_PROFILE |
23717
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23697
diff
changeset
|
3023 int prof_lnum = -1; |
23719
1a7c2685d780
patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents:
23717
diff
changeset
|
3024 #endif |
24895
e61a2085c89b
patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents:
24893
diff
changeset
|
3025 int debug_lnum = -1; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3026 |
27022
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26980
diff
changeset
|
3027 // allocated lines are freed at the end |
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26980
diff
changeset
|
3028 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:
26980
diff
changeset
|
3029 |
20538
9f921ba86d05
patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents:
20534
diff
changeset
|
3030 // When using a function that was compiled before: Free old instructions. |
23360
eb7d8f39363c
patch 8.2.2223: Vim9: Reloading marks a :def function as deleted
Bram Moolenaar <Bram@vim.org>
parents:
23352
diff
changeset
|
3031 // The index is reused. Otherwise add a new entry in "def_functions". |
20943
1693ca876049
patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents:
20933
diff
changeset
|
3032 if (ufunc->uf_dfunc_idx > 0) |
20339
7587d892c00c
patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20336
diff
changeset
|
3033 { |
7587d892c00c
patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20336
diff
changeset
|
3034 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data) |
7587d892c00c
patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20336
diff
changeset
|
3035 + ufunc->uf_dfunc_idx; |
24926
e20d34db7cf4
patch 8.2.3000: Vim9: warning for uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
24918
diff
changeset
|
3036 isn_T *instr_dest = NULL; |
24918
f11779c1d123
patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents:
24914
diff
changeset
|
3037 |
f11779c1d123
patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents:
24914
diff
changeset
|
3038 switch (compile_type) |
f11779c1d123
patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents:
24914
diff
changeset
|
3039 { |
f11779c1d123
patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents:
24914
diff
changeset
|
3040 case CT_PROFILE: |
f11779c1d123
patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents:
24914
diff
changeset
|
3041 #ifdef FEAT_PROFILE |
f11779c1d123
patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents:
24914
diff
changeset
|
3042 instr_dest = dfunc->df_instr_prof; break; |
f11779c1d123
patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents:
24914
diff
changeset
|
3043 #endif |
f11779c1d123
patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents:
24914
diff
changeset
|
3044 case CT_NONE: instr_dest = dfunc->df_instr; break; |
f11779c1d123
patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents:
24914
diff
changeset
|
3045 case CT_DEBUG: instr_dest = dfunc->df_instr_debug; break; |
f11779c1d123
patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents:
24914
diff
changeset
|
3046 } |
f11779c1d123
patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents:
24914
diff
changeset
|
3047 if (instr_dest != NULL) |
f11779c1d123
patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents:
24914
diff
changeset
|
3048 // Was compiled in this mode before: Free old instructions. |
f11779c1d123
patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents:
24914
diff
changeset
|
3049 delete_def_function_contents(dfunc, FALSE); |
f11779c1d123
patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents:
24914
diff
changeset
|
3050 ga_clear_strings(&dfunc->df_var_names); |
30065
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
30053
diff
changeset
|
3051 dfunc->df_defer_var_idx = 0; |
20339
7587d892c00c
patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20336
diff
changeset
|
3052 } |
21463
7f36d36f7195
patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents:
21455
diff
changeset
|
3053 else |
7f36d36f7195
patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents:
21455
diff
changeset
|
3054 { |
7f36d36f7195
patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents:
21455
diff
changeset
|
3055 if (add_def_function(ufunc) == FAIL) |
7f36d36f7195
patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents:
21455
diff
changeset
|
3056 return FAIL; |
7f36d36f7195
patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents:
21455
diff
changeset
|
3057 new_def_function = TRUE; |
7f36d36f7195
patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents:
21455
diff
changeset
|
3058 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3059 |
28097
632a84e2ce92
patch 8.2.4573: a nested function is compiled for debugging without context
Bram Moolenaar <Bram@vim.org>
parents:
28063
diff
changeset
|
3060 if ((ufunc->uf_flags & FC_CLOSURE) && outer_cctx == NULL) |
632a84e2ce92
patch 8.2.4573: a nested function is compiled for debugging without context
Bram Moolenaar <Bram@vim.org>
parents:
28063
diff
changeset
|
3061 { |
632a84e2ce92
patch 8.2.4573: a nested function is compiled for debugging without context
Bram Moolenaar <Bram@vim.org>
parents:
28063
diff
changeset
|
3062 semsg(_(e_compiling_closure_without_context_str), |
632a84e2ce92
patch 8.2.4573: a nested function is compiled for debugging without context
Bram Moolenaar <Bram@vim.org>
parents:
28063
diff
changeset
|
3063 printable_func_name(ufunc)); |
632a84e2ce92
patch 8.2.4573: a nested function is compiled for debugging without context
Bram Moolenaar <Bram@vim.org>
parents:
28063
diff
changeset
|
3064 return FAIL; |
632a84e2ce92
patch 8.2.4573: a nested function is compiled for debugging without context
Bram Moolenaar <Bram@vim.org>
parents:
28063
diff
changeset
|
3065 } |
632a84e2ce92
patch 8.2.4573: a nested function is compiled for debugging without context
Bram Moolenaar <Bram@vim.org>
parents:
28063
diff
changeset
|
3066 |
21281
13b1567ae0c6
patch 8.2.1191: Vim9: crash when function calls itself
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
3067 ufunc->uf_def_status = UF_COMPILING; |
13b1567ae0c6
patch 8.2.1191: Vim9: crash when function calls itself
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
3068 |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
20005
diff
changeset
|
3069 CLEAR_FIELD(cctx); |
23717
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23697
diff
changeset
|
3070 |
24895
e61a2085c89b
patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents:
24893
diff
changeset
|
3071 cctx.ctx_compile_type = compile_type; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3072 cctx.ctx_ufunc = ufunc; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3073 cctx.ctx_lnum = -1; |
20244
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
3074 cctx.ctx_outer = outer_cctx; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3075 ga_init2(&cctx.ctx_locals, sizeof(lvar_T), 10); |
26935
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
3076 // Each entry on the type stack consists of two type pointers. |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
3077 ga_init2(&cctx.ctx_type_stack, sizeof(type2_T), 50); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3078 cctx.ctx_type_list = &ufunc->uf_type_list; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3079 ga_init2(&cctx.ctx_instr, sizeof(isn_T), 50); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3080 instr = &cctx.ctx_instr; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3081 |
20538
9f921ba86d05
patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents:
20534
diff
changeset
|
3082 // Set the context to the function, it may be compiled when called from |
9f921ba86d05
patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents:
20534
diff
changeset
|
3083 // another script. Set the script version to the most modern one. |
9f921ba86d05
patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents:
20534
diff
changeset
|
3084 // The line number will be set in next_line_from_context(). |
9f921ba86d05
patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents:
20534
diff
changeset
|
3085 current_sctx = ufunc->uf_script_ctx; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3086 current_sctx.sc_version = SCRIPT_VERSION_VIM9; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3087 |
24539
3a290891a015
patch 8.2.2809: Vim9: :def function compilation fails when using :legacy
Bram Moolenaar <Bram@vim.org>
parents:
24533
diff
changeset
|
3088 // Don't use the flag from ":legacy" here. |
3a290891a015
patch 8.2.2809: Vim9: :def function compilation fails when using :legacy
Bram Moolenaar <Bram@vim.org>
parents:
24533
diff
changeset
|
3089 cmdmod.cmod_flags &= ~CMOD_LEGACY; |
3a290891a015
patch 8.2.2809: Vim9: :def function compilation fails when using :legacy
Bram Moolenaar <Bram@vim.org>
parents:
24533
diff
changeset
|
3090 |
20538
9f921ba86d05
patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents:
20534
diff
changeset
|
3091 // Make sure error messages are OK. |
9f921ba86d05
patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents:
20534
diff
changeset
|
3092 do_estack_push = !estack_top_is_ufunc(ufunc, 1); |
9f921ba86d05
patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents:
20534
diff
changeset
|
3093 if (do_estack_push) |
9f921ba86d05
patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents:
20534
diff
changeset
|
3094 estack_push_ufunc(ufunc, 1); |
22584
c271498e03b2
patch 8.2.1840: Vim9: error message is not clear about compilation error
Bram Moolenaar <Bram@vim.org>
parents:
22537
diff
changeset
|
3095 estack_compiling = TRUE; |
20538
9f921ba86d05
patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents:
20534
diff
changeset
|
3096 |
26851
15913ba6363e
patch 8.2.3954: Vim9: no error for shadowing if script var is declared later
Bram Moolenaar <Bram@vim.org>
parents:
26845
diff
changeset
|
3097 if (check_args_shadowing(ufunc, &cctx) == FAIL) |
15913ba6363e
patch 8.2.3954: Vim9: no error for shadowing if script var is declared later
Bram Moolenaar <Bram@vim.org>
parents:
26845
diff
changeset
|
3098 goto erret; |
15913ba6363e
patch 8.2.3954: Vim9: no error for shadowing if script var is declared later
Bram Moolenaar <Bram@vim.org>
parents:
26845
diff
changeset
|
3099 |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
3100 // For an object method and constructor "this" is the first local variable. |
31616
0eb51cec2154
patch 9.0.1140: cannot call an object method in a compiled function
Bram Moolenaar <Bram@vim.org>
parents:
31602
diff
changeset
|
3101 if (ufunc->uf_flags & (FC_OBJECT|FC_NEW)) |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
3102 { |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
3103 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data) |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
3104 + ufunc->uf_dfunc_idx; |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
3105 if (GA_GROW_FAILS(&dfunc->df_var_names, 1)) |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
3106 goto erret; |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
3107 ((char_u **)dfunc->df_var_names.ga_data)[0] = |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
3108 vim_strsave((char_u *)"this"); |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
3109 ++dfunc->df_var_names.ga_len; |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
3110 |
31424
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
3111 // In the constructor allocate memory for the object and initialize the |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
3112 // object members. |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
3113 if ((ufunc->uf_flags & FC_NEW) == FC_NEW) |
31424
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
3114 { |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
3115 generate_CONSTRUCT(&cctx, ufunc->uf_class); |
31424
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
3116 |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
3117 for (int i = 0; i < ufunc->uf_class->class_obj_member_count; ++i) |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
3118 { |
31483
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31445
diff
changeset
|
3119 ocmember_T *m = &ufunc->uf_class->class_obj_members[i]; |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31445
diff
changeset
|
3120 if (m->ocm_init != NULL) |
31424
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
3121 { |
31483
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31445
diff
changeset
|
3122 char_u *expr = m->ocm_init; |
31424
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
3123 if (compile_expr0(&expr, &cctx) == FAIL) |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
3124 goto erret; |
31483
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31445
diff
changeset
|
3125 if (!ends_excmd2(m->ocm_init, expr)) |
31424
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
3126 { |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
3127 semsg(_(e_trailing_characters_str), expr); |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
3128 goto erret; |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
3129 } |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
3130 } |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
3131 else |
31483
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31445
diff
changeset
|
3132 push_default_value(&cctx, m->ocm_type->tt_type, |
31424
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
3133 FALSE, NULL); |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
3134 generate_STORE_THIS(&cctx, i); |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
3135 } |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
3136 } |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
3137 } |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
3138 |
19328
e99e6d794597
patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents:
19316
diff
changeset
|
3139 if (ufunc->uf_def_args.ga_len > 0) |
e99e6d794597
patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents:
19316
diff
changeset
|
3140 { |
e99e6d794597
patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents:
19316
diff
changeset
|
3141 int count = ufunc->uf_def_args.ga_len; |
19946
8466e62a2481
patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents:
19944
diff
changeset
|
3142 int first_def_arg = ufunc->uf_args.ga_len - count; |
19328
e99e6d794597
patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents:
19316
diff
changeset
|
3143 int i; |
e99e6d794597
patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents:
19316
diff
changeset
|
3144 int off = STACK_FRAME_SIZE + (ufunc->uf_va_name != NULL ? 1 : 0); |
21469
4d156aead799
patch 8.2.1285: Vim9: argument types are not checked on assignment
Bram Moolenaar <Bram@vim.org>
parents:
21467
diff
changeset
|
3145 int did_set_arg_type = FALSE; |
19328
e99e6d794597
patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents:
19316
diff
changeset
|
3146 |
e99e6d794597
patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents:
19316
diff
changeset
|
3147 // Produce instructions for the default values of optional arguments. |
24097
26d3c1539bcc
patch 8.2.2590: Vim9: default argument value may cause internal error
Bram Moolenaar <Bram@vim.org>
parents:
24087
diff
changeset
|
3148 SOURCING_LNUM = 0; // line number unknown |
19328
e99e6d794597
patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents:
19316
diff
changeset
|
3149 for (i = 0; i < count; ++i) |
e99e6d794597
patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents:
19316
diff
changeset
|
3150 { |
31441
e572ff386670
patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents:
31424
diff
changeset
|
3151 char_u *arg = ((char_u **)(ufunc->uf_def_args.ga_data))[i]; |
e572ff386670
patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents:
31424
diff
changeset
|
3152 if (STRCMP(arg, "v:none") == 0) |
e572ff386670
patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents:
31424
diff
changeset
|
3153 // "arg = v:none" means the argument is optional without |
e572ff386670
patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents:
31424
diff
changeset
|
3154 // setting a value when the argument is missing. |
e572ff386670
patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents:
31424
diff
changeset
|
3155 continue; |
e572ff386670
patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents:
31424
diff
changeset
|
3156 |
19946
8466e62a2481
patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents:
19944
diff
changeset
|
3157 type_T *val_type; |
8466e62a2481
patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents:
19944
diff
changeset
|
3158 int arg_idx = first_def_arg + i; |
25326
cfbf40f749b0
patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents:
25320
diff
changeset
|
3159 where_T where = WHERE_INIT; |
24272
cabed216cc2f
patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents:
24262
diff
changeset
|
3160 int jump_instr_idx = instr->ga_len; |
cabed216cc2f
patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents:
24262
diff
changeset
|
3161 isn_T *isn; |
cabed216cc2f
patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents:
24262
diff
changeset
|
3162 |
cabed216cc2f
patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents:
24262
diff
changeset
|
3163 // Use a JUMP_IF_ARG_SET instruction to skip if the value was given. |
31441
e572ff386670
patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents:
31424
diff
changeset
|
3164 if (generate_JUMP_IF_ARG(&cctx, ISN_JUMP_IF_ARG_SET, |
e572ff386670
patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents:
31424
diff
changeset
|
3165 i - count - off) == FAIL) |
24272
cabed216cc2f
patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents:
24262
diff
changeset
|
3166 goto erret; |
24097
26d3c1539bcc
patch 8.2.2590: Vim9: default argument value may cause internal error
Bram Moolenaar <Bram@vim.org>
parents:
24087
diff
changeset
|
3167 |
26d3c1539bcc
patch 8.2.2590: Vim9: default argument value may cause internal error
Bram Moolenaar <Bram@vim.org>
parents:
24087
diff
changeset
|
3168 // Make sure later arguments are not found. |
25108
de29f9a76233
patch 8.2.3091: Vim9: default argument expr. cannot use previous argument
Bram Moolenaar <Bram@vim.org>
parents:
25098
diff
changeset
|
3169 ufunc->uf_args_visible = arg_idx; |
19946
8466e62a2481
patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents:
19944
diff
changeset
|
3170 |
31441
e572ff386670
patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents:
31424
diff
changeset
|
3171 int r = compile_expr0(&arg, &cctx); |
24097
26d3c1539bcc
patch 8.2.2590: Vim9: default argument value may cause internal error
Bram Moolenaar <Bram@vim.org>
parents:
24087
diff
changeset
|
3172 if (r == FAIL) |
19946
8466e62a2481
patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents:
19944
diff
changeset
|
3173 goto erret; |
8466e62a2481
patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents:
19944
diff
changeset
|
3174 |
8466e62a2481
patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents:
19944
diff
changeset
|
3175 // If no type specified use the type of the default value. |
8466e62a2481
patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents:
19944
diff
changeset
|
3176 // Otherwise check that the default value type matches the |
8466e62a2481
patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents:
19944
diff
changeset
|
3177 // specified type. |
26935
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
3178 val_type = get_type_on_stack(&cctx, 0); |
23917
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
3179 where.wt_index = arg_idx + 1; |
19946
8466e62a2481
patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents:
19944
diff
changeset
|
3180 if (ufunc->uf_arg_types[arg_idx] == &t_unknown) |
21469
4d156aead799
patch 8.2.1285: Vim9: argument types are not checked on assignment
Bram Moolenaar <Bram@vim.org>
parents:
21467
diff
changeset
|
3181 { |
4d156aead799
patch 8.2.1285: Vim9: argument types are not checked on assignment
Bram Moolenaar <Bram@vim.org>
parents:
21467
diff
changeset
|
3182 did_set_arg_type = TRUE; |
19946
8466e62a2481
patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents:
19944
diff
changeset
|
3183 ufunc->uf_arg_types[arg_idx] = val_type; |
21469
4d156aead799
patch 8.2.1285: Vim9: argument types are not checked on assignment
Bram Moolenaar <Bram@vim.org>
parents:
21467
diff
changeset
|
3184 } |
26680
1b288eb2fcdc
patch 8.2.3869: Vim9: type checking for "any" is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
26662
diff
changeset
|
3185 else if (need_type_where(val_type, ufunc->uf_arg_types[arg_idx], |
31551
67d9fbe516a3
patch 9.0.1108: type error when using "any" type and adding to float
Bram Moolenaar <Bram@vim.org>
parents:
31517
diff
changeset
|
3186 FALSE, -1, where, &cctx, FALSE, FALSE) == FAIL) |
19946
8466e62a2481
patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents:
19944
diff
changeset
|
3187 goto erret; |
8466e62a2481
patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents:
19944
diff
changeset
|
3188 |
8466e62a2481
patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents:
19944
diff
changeset
|
3189 if (generate_STORE(&cctx, ISN_STORE, i - count - off, NULL) == FAIL) |
19328
e99e6d794597
patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents:
19316
diff
changeset
|
3190 goto erret; |
24272
cabed216cc2f
patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents:
24262
diff
changeset
|
3191 |
cabed216cc2f
patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents:
24262
diff
changeset
|
3192 // set instruction index in JUMP_IF_ARG_SET to here |
cabed216cc2f
patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents:
24262
diff
changeset
|
3193 isn = ((isn_T *)instr->ga_data) + jump_instr_idx; |
cabed216cc2f
patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents:
24262
diff
changeset
|
3194 isn->isn_arg.jumparg.jump_where = instr->ga_len; |
cabed216cc2f
patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents:
24262
diff
changeset
|
3195 } |
21469
4d156aead799
patch 8.2.1285: Vim9: argument types are not checked on assignment
Bram Moolenaar <Bram@vim.org>
parents:
21467
diff
changeset
|
3196 |
4d156aead799
patch 8.2.1285: Vim9: argument types are not checked on assignment
Bram Moolenaar <Bram@vim.org>
parents:
21467
diff
changeset
|
3197 if (did_set_arg_type) |
4d156aead799
patch 8.2.1285: Vim9: argument types are not checked on assignment
Bram Moolenaar <Bram@vim.org>
parents:
21467
diff
changeset
|
3198 set_function_type(ufunc); |
19328
e99e6d794597
patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents:
19316
diff
changeset
|
3199 } |
25108
de29f9a76233
patch 8.2.3091: Vim9: default argument expr. cannot use previous argument
Bram Moolenaar <Bram@vim.org>
parents:
25098
diff
changeset
|
3200 ufunc->uf_args_visible = ufunc->uf_args.ga_len; |
19328
e99e6d794597
patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents:
19316
diff
changeset
|
3201 |
31865
86ed5031ff2b
patch 9.0.1265: using an interface method may give a compilation error
Bram Moolenaar <Bram@vim.org>
parents:
31827
diff
changeset
|
3202 // Compiling a function in an interface is done to get the function type. |
86ed5031ff2b
patch 9.0.1265: using an interface method may give a compilation error
Bram Moolenaar <Bram@vim.org>
parents:
31827
diff
changeset
|
3203 // No code is actually compiled. |
86ed5031ff2b
patch 9.0.1265: using an interface method may give a compilation error
Bram Moolenaar <Bram@vim.org>
parents:
31827
diff
changeset
|
3204 if (ufunc->uf_class != NULL |
86ed5031ff2b
patch 9.0.1265: using an interface method may give a compilation error
Bram Moolenaar <Bram@vim.org>
parents:
31827
diff
changeset
|
3205 && (ufunc->uf_class->class_flags & CLASS_INTERFACE)) |
86ed5031ff2b
patch 9.0.1265: using an interface method may give a compilation error
Bram Moolenaar <Bram@vim.org>
parents:
31827
diff
changeset
|
3206 { |
86ed5031ff2b
patch 9.0.1265: using an interface method may give a compilation error
Bram Moolenaar <Bram@vim.org>
parents:
31827
diff
changeset
|
3207 ufunc->uf_def_status = UF_NOT_COMPILED; |
86ed5031ff2b
patch 9.0.1265: using an interface method may give a compilation error
Bram Moolenaar <Bram@vim.org>
parents:
31827
diff
changeset
|
3208 ret = OK; |
86ed5031ff2b
patch 9.0.1265: using an interface method may give a compilation error
Bram Moolenaar <Bram@vim.org>
parents:
31827
diff
changeset
|
3209 goto erret; |
86ed5031ff2b
patch 9.0.1265: using an interface method may give a compilation error
Bram Moolenaar <Bram@vim.org>
parents:
31827
diff
changeset
|
3210 } |
86ed5031ff2b
patch 9.0.1265: using an interface method may give a compilation error
Bram Moolenaar <Bram@vim.org>
parents:
31827
diff
changeset
|
3211 |
19328
e99e6d794597
patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents:
19316
diff
changeset
|
3212 /* |
e99e6d794597
patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents:
19316
diff
changeset
|
3213 * Loop over all the lines of the function and generate instructions. |
e99e6d794597
patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents:
19316
diff
changeset
|
3214 */ |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3215 for (;;) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3216 { |
21689
10866fd07595
patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents:
21683
diff
changeset
|
3217 exarg_T ea; |
10866fd07595
patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents:
21683
diff
changeset
|
3218 int starts_with_colon = FALSE; |
10866fd07595
patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents:
21683
diff
changeset
|
3219 char_u *cmd; |
22703
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
3220 cmdmod_T local_cmdmod; |
19473
b09afbebffee
patch 8.2.0294: cannot use Ex command that is also a function name
Bram Moolenaar <Bram@vim.org>
parents:
19467
diff
changeset
|
3221 |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
19904
diff
changeset
|
3222 // Bail out on the first error to avoid a flood of errors and report |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
19904
diff
changeset
|
3223 // the right line number when inside try/catch. |
22758
48feb3dd0d25
patch 8.2.1927: Vim9: get unknown error with an error in a timer function
Bram Moolenaar <Bram@vim.org>
parents:
22734
diff
changeset
|
3224 if (did_emsg_before != did_emsg) |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
19904
diff
changeset
|
3225 goto erret; |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
19904
diff
changeset
|
3226 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3227 if (line != NULL && *line == '|') |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3228 // the line continues after a '|' |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3229 ++line; |
20949
62912ad41aff
patch 8.2.1026: Vim9: cannot break the line after "->"
Bram Moolenaar <Bram@vim.org>
parents:
20945
diff
changeset
|
3230 else if (line != NULL && *skipwhite(line) != NUL |
20059
de756b3f4dee
patch 8.2.0585: Vim9: # comment not recognized after :vim9script
Bram Moolenaar <Bram@vim.org>
parents:
20055
diff
changeset
|
3231 && !(*line == '#' && (line == cctx.ctx_line_start |
de756b3f4dee
patch 8.2.0585: Vim9: # comment not recognized after :vim9script
Bram Moolenaar <Bram@vim.org>
parents:
20055
diff
changeset
|
3232 || VIM_ISWHITE(line[-1])))) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3233 { |
26883
7f150a4936f2
patch 8.2.3970: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26879
diff
changeset
|
3234 semsg(_(e_trailing_characters_str), line); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3235 goto erret; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3236 } |
24158
93e69703a290
patch 8.2.2620: Vim9: Using #{ for a dictionary gives strange errors
Bram Moolenaar <Bram@vim.org>
parents:
24154
diff
changeset
|
3237 else if (line != NULL && vim9_bad_comment(skipwhite(line))) |
93e69703a290
patch 8.2.2620: Vim9: Using #{ for a dictionary gives strange errors
Bram Moolenaar <Bram@vim.org>
parents:
24154
diff
changeset
|
3238 goto erret; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3239 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3240 { |
20955
396fe712eb0f
patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
3241 line = next_line_from_context(&cctx, FALSE); |
19999
844c7646f61b
patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents:
19993
diff
changeset
|
3242 if (cctx.ctx_lnum >= ufunc->uf_lines.ga_len) |
23717
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23697
diff
changeset
|
3243 { |
20055
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
3244 // beyond the last line |
23719
1a7c2685d780
patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents:
23717
diff
changeset
|
3245 #ifdef FEAT_PROFILE |
23723
14e92f4c98c9
patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents:
23719
diff
changeset
|
3246 if (cctx.ctx_skip != SKIP_YES) |
14e92f4c98c9
patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents:
23719
diff
changeset
|
3247 may_generate_prof_end(&cctx, prof_lnum); |
23719
1a7c2685d780
patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents:
23717
diff
changeset
|
3248 #endif |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3249 break; |
23717
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23697
diff
changeset
|
3250 } |
24444
b5fbe8280853
patch 8.2.2762: Vim9: function line truncated when compiling
Bram Moolenaar <Bram@vim.org>
parents:
24440
diff
changeset
|
3251 // Make a copy, splitting off nextcmd and removing trailing spaces |
b5fbe8280853
patch 8.2.2762: Vim9: function line truncated when compiling
Bram Moolenaar <Bram@vim.org>
parents:
24440
diff
changeset
|
3252 // may change it. |
b5fbe8280853
patch 8.2.2762: Vim9: function line truncated when compiling
Bram Moolenaar <Bram@vim.org>
parents:
24440
diff
changeset
|
3253 if (line != NULL) |
b5fbe8280853
patch 8.2.2762: Vim9: function line truncated when compiling
Bram Moolenaar <Bram@vim.org>
parents:
24440
diff
changeset
|
3254 { |
b5fbe8280853
patch 8.2.2762: Vim9: function line truncated when compiling
Bram Moolenaar <Bram@vim.org>
parents:
24440
diff
changeset
|
3255 line = vim_strsave(line); |
27022
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26980
diff
changeset
|
3256 if (ga_add_string(&lines_to_free, line) == FAIL) |
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26980
diff
changeset
|
3257 goto erret; |
24444
b5fbe8280853
patch 8.2.2762: Vim9: function line truncated when compiling
Bram Moolenaar <Bram@vim.org>
parents:
24440
diff
changeset
|
3258 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3259 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3260 |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
20005
diff
changeset
|
3261 CLEAR_FIELD(ea); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3262 ea.cmdlinep = &line; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3263 ea.cmd = skipwhite(line); |
28281
bd1dcc605e58
patch 8.2.4666: Vim9: assignment not recognized in skipped block
Bram Moolenaar <Bram@vim.org>
parents:
28217
diff
changeset
|
3264 ea.skip = cctx.ctx_skip == SKIP_YES; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3265 |
23717
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23697
diff
changeset
|
3266 if (*ea.cmd == '#') |
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23697
diff
changeset
|
3267 { |
29668
495dc54392fa
patch 9.0.0174: no error for using "#{ comment" in a compiled function
Bram Moolenaar <Bram@vim.org>
parents:
29475
diff
changeset
|
3268 // "#" starts a comment, but "#{" is an error |
495dc54392fa
patch 9.0.0174: no error for using "#{ comment" in a compiled function
Bram Moolenaar <Bram@vim.org>
parents:
29475
diff
changeset
|
3269 if (vim9_bad_comment(ea.cmd)) |
495dc54392fa
patch 9.0.0174: no error for using "#{ comment" in a compiled function
Bram Moolenaar <Bram@vim.org>
parents:
29475
diff
changeset
|
3270 goto erret; |
23717
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23697
diff
changeset
|
3271 line = (char_u *)""; |
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23697
diff
changeset
|
3272 continue; |
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23697
diff
changeset
|
3273 } |
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23697
diff
changeset
|
3274 |
23719
1a7c2685d780
patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents:
23717
diff
changeset
|
3275 #ifdef FEAT_PROFILE |
24895
e61a2085c89b
patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents:
24893
diff
changeset
|
3276 if (cctx.ctx_compile_type == CT_PROFILE && cctx.ctx_lnum != prof_lnum |
e61a2085c89b
patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents:
24893
diff
changeset
|
3277 && cctx.ctx_skip != SKIP_YES) |
23717
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23697
diff
changeset
|
3278 { |
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23697
diff
changeset
|
3279 may_generate_prof_end(&cctx, prof_lnum); |
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23697
diff
changeset
|
3280 |
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23697
diff
changeset
|
3281 prof_lnum = cctx.ctx_lnum; |
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23697
diff
changeset
|
3282 generate_instr(&cctx, ISN_PROF_START); |
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23697
diff
changeset
|
3283 } |
23719
1a7c2685d780
patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents:
23717
diff
changeset
|
3284 #endif |
24895
e61a2085c89b
patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents:
24893
diff
changeset
|
3285 if (cctx.ctx_compile_type == CT_DEBUG && cctx.ctx_lnum != debug_lnum |
e61a2085c89b
patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents:
24893
diff
changeset
|
3286 && cctx.ctx_skip != SKIP_YES) |
e61a2085c89b
patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents:
24893
diff
changeset
|
3287 { |
e61a2085c89b
patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents:
24893
diff
changeset
|
3288 debug_lnum = cctx.ctx_lnum; |
24918
f11779c1d123
patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents:
24914
diff
changeset
|
3289 generate_instr_debug(&cctx); |
24895
e61a2085c89b
patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents:
24893
diff
changeset
|
3290 } |
25004
70f55a30f03c
patch 8.2.3039: Vim9: breakpoint at a comment line does not work
Bram Moolenaar <Bram@vim.org>
parents:
24984
diff
changeset
|
3291 cctx.ctx_prev_lnum = cctx.ctx_lnum + 1; |
23717
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23697
diff
changeset
|
3292 |
20055
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
3293 // Some things can be recognized by the first character. |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
3294 switch (*ea.cmd) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3295 { |
20055
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
3296 case '}': |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
3297 { |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
3298 // "}" ends a block scope |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
3299 scopetype_T stype = cctx.ctx_scope == NULL |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
3300 ? NO_SCOPE : cctx.ctx_scope->se_type; |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
3301 |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
3302 if (stype == BLOCK_SCOPE) |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
3303 { |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
3304 compile_endblock(&cctx); |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
3305 line = ea.cmd; |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
3306 } |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
3307 else |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
3308 { |
21821
0deb6f96a5a3
patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
21811
diff
changeset
|
3309 emsg(_(e_using_rcurly_outside_if_block_scope)); |
20055
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
3310 goto erret; |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
3311 } |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
3312 if (line != NULL) |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
3313 line = skipwhite(ea.cmd + 1); |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
3314 continue; |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
3315 } |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
3316 |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
3317 case '{': |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
3318 // "{" starts a block scope |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
3319 // "{'a': 1}->func() is something else |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
3320 if (ends_excmd(*skipwhite(ea.cmd + 1))) |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
3321 { |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
3322 line = compile_block(ea.cmd, &cctx); |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
3323 continue; |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
3324 } |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
3325 break; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3326 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3327 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3328 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3329 * COMMAND MODIFIERS |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3330 */ |
22703
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
3331 cctx.ctx_has_cmdmod = FALSE; |
22699
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
22697
diff
changeset
|
3332 if (parse_command_modifiers(&ea, &errormsg, &local_cmdmod, FALSE) |
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
22697
diff
changeset
|
3333 == FAIL) |
27716
4097434c7c67
patch 8.2.4384: Vim9: error message not tested, some code not tested
Bram Moolenaar <Bram@vim.org>
parents:
27714
diff
changeset
|
3334 goto erret; |
22699
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
22697
diff
changeset
|
3335 generate_cmdmods(&cctx, &local_cmdmod); |
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
22697
diff
changeset
|
3336 undo_cmdmod(&local_cmdmod); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3337 |
22772
82a7aff951d2
patch 8.2.1934: Vim9: command modifiers in :def function not tested
Bram Moolenaar <Bram@vim.org>
parents:
22758
diff
changeset
|
3338 // Check if there was a colon after the last command modifier or before |
82a7aff951d2
patch 8.2.1934: Vim9: command modifiers in :def function not tested
Bram Moolenaar <Bram@vim.org>
parents:
22758
diff
changeset
|
3339 // the current position. |
82a7aff951d2
patch 8.2.1934: Vim9: command modifiers in :def function not tested
Bram Moolenaar <Bram@vim.org>
parents:
22758
diff
changeset
|
3340 for (p = ea.cmd; p >= line; --p) |
82a7aff951d2
patch 8.2.1934: Vim9: command modifiers in :def function not tested
Bram Moolenaar <Bram@vim.org>
parents:
22758
diff
changeset
|
3341 { |
82a7aff951d2
patch 8.2.1934: Vim9: command modifiers in :def function not tested
Bram Moolenaar <Bram@vim.org>
parents:
22758
diff
changeset
|
3342 if (*p == ':') |
82a7aff951d2
patch 8.2.1934: Vim9: command modifiers in :def function not tested
Bram Moolenaar <Bram@vim.org>
parents:
22758
diff
changeset
|
3343 starts_with_colon = TRUE; |
82a7aff951d2
patch 8.2.1934: Vim9: command modifiers in :def function not tested
Bram Moolenaar <Bram@vim.org>
parents:
22758
diff
changeset
|
3344 if (p < ea.cmd && !VIM_ISWHITE(*p)) |
82a7aff951d2
patch 8.2.1934: Vim9: command modifiers in :def function not tested
Bram Moolenaar <Bram@vim.org>
parents:
22758
diff
changeset
|
3345 break; |
82a7aff951d2
patch 8.2.1934: Vim9: command modifiers in :def function not tested
Bram Moolenaar <Bram@vim.org>
parents:
22758
diff
changeset
|
3346 } |
82a7aff951d2
patch 8.2.1934: Vim9: command modifiers in :def function not tested
Bram Moolenaar <Bram@vim.org>
parents:
22758
diff
changeset
|
3347 |
25030
214fddf4c765
patch 8.2.3052: Vim9: "legacy call" does not work
Bram Moolenaar <Bram@vim.org>
parents:
25028
diff
changeset
|
3348 // Skip ":call" to get to the function name, unless using :legacy |
21751
cc8188c22a47
patch 8.2.1425: Vim9: cannot use call() without :call
Bram Moolenaar <Bram@vim.org>
parents:
21743
diff
changeset
|
3349 p = ea.cmd; |
25030
214fddf4c765
patch 8.2.3052: Vim9: "legacy call" does not work
Bram Moolenaar <Bram@vim.org>
parents:
25028
diff
changeset
|
3350 if (!(local_cmdmod.cmod_flags & CMOD_LEGACY)) |
214fddf4c765
patch 8.2.3052: Vim9: "legacy call" does not work
Bram Moolenaar <Bram@vim.org>
parents:
25028
diff
changeset
|
3351 { |
214fddf4c765
patch 8.2.3052: Vim9: "legacy call" does not work
Bram Moolenaar <Bram@vim.org>
parents:
25028
diff
changeset
|
3352 if (checkforcmd(&ea.cmd, "call", 3)) |
214fddf4c765
patch 8.2.3052: Vim9: "legacy call" does not work
Bram Moolenaar <Bram@vim.org>
parents:
25028
diff
changeset
|
3353 { |
214fddf4c765
patch 8.2.3052: Vim9: "legacy call" does not work
Bram Moolenaar <Bram@vim.org>
parents:
25028
diff
changeset
|
3354 if (*ea.cmd == '(') |
214fddf4c765
patch 8.2.3052: Vim9: "legacy call" does not work
Bram Moolenaar <Bram@vim.org>
parents:
25028
diff
changeset
|
3355 // not for "call()" |
214fddf4c765
patch 8.2.3052: Vim9: "legacy call" does not work
Bram Moolenaar <Bram@vim.org>
parents:
25028
diff
changeset
|
3356 ea.cmd = p; |
214fddf4c765
patch 8.2.3052: Vim9: "legacy call" does not work
Bram Moolenaar <Bram@vim.org>
parents:
25028
diff
changeset
|
3357 else |
214fddf4c765
patch 8.2.3052: Vim9: "legacy call" does not work
Bram Moolenaar <Bram@vim.org>
parents:
25028
diff
changeset
|
3358 ea.cmd = skipwhite(ea.cmd); |
214fddf4c765
patch 8.2.3052: Vim9: "legacy call" does not work
Bram Moolenaar <Bram@vim.org>
parents:
25028
diff
changeset
|
3359 } |
214fddf4c765
patch 8.2.3052: Vim9: "legacy call" does not work
Bram Moolenaar <Bram@vim.org>
parents:
25028
diff
changeset
|
3360 |
214fddf4c765
patch 8.2.3052: Vim9: "legacy call" does not work
Bram Moolenaar <Bram@vim.org>
parents:
25028
diff
changeset
|
3361 if (!starts_with_colon) |
214fddf4c765
patch 8.2.3052: Vim9: "legacy call" does not work
Bram Moolenaar <Bram@vim.org>
parents:
25028
diff
changeset
|
3362 { |
214fddf4c765
patch 8.2.3052: Vim9: "legacy call" does not work
Bram Moolenaar <Bram@vim.org>
parents:
25028
diff
changeset
|
3363 int assign; |
214fddf4c765
patch 8.2.3052: Vim9: "legacy call" does not work
Bram Moolenaar <Bram@vim.org>
parents:
25028
diff
changeset
|
3364 |
214fddf4c765
patch 8.2.3052: Vim9: "legacy call" does not work
Bram Moolenaar <Bram@vim.org>
parents:
25028
diff
changeset
|
3365 // Check for assignment after command modifiers. |
214fddf4c765
patch 8.2.3052: Vim9: "legacy call" does not work
Bram Moolenaar <Bram@vim.org>
parents:
25028
diff
changeset
|
3366 assign = may_compile_assignment(&ea, &line, &cctx); |
214fddf4c765
patch 8.2.3052: Vim9: "legacy call" does not work
Bram Moolenaar <Bram@vim.org>
parents:
25028
diff
changeset
|
3367 if (assign == OK) |
214fddf4c765
patch 8.2.3052: Vim9: "legacy call" does not work
Bram Moolenaar <Bram@vim.org>
parents:
25028
diff
changeset
|
3368 goto nextline; |
214fddf4c765
patch 8.2.3052: Vim9: "legacy call" does not work
Bram Moolenaar <Bram@vim.org>
parents:
25028
diff
changeset
|
3369 if (assign == FAIL) |
214fddf4c765
patch 8.2.3052: Vim9: "legacy call" does not work
Bram Moolenaar <Bram@vim.org>
parents:
25028
diff
changeset
|
3370 goto erret; |
214fddf4c765
patch 8.2.3052: Vim9: "legacy call" does not work
Bram Moolenaar <Bram@vim.org>
parents:
25028
diff
changeset
|
3371 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3372 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3373 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3374 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3375 * COMMAND after range |
21335
af3663df42bf
patch 8.2.1218: Vim9: cannot use 'text'->func()
Bram Moolenaar <Bram@vim.org>
parents:
21301
diff
changeset
|
3376 * 'text'->func() should not be confused with 'a mark |
27800
6e5d378919c4
patch 8.2.4426: map() function on string and blob does not check types
Bram Moolenaar <Bram@vim.org>
parents:
27738
diff
changeset
|
3377 * 0z1234->func() should not be confused with a zero line number |
24533
9c404d78d767
patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents:
24531
diff
changeset
|
3378 * "++nr" and "--nr" are eval commands |
25670
812c75fd255c
patch 8.2.3371: Vim9: :$ENV cannot be followed by ->func() in next line
Bram Moolenaar <Bram@vim.org>
parents:
25660
diff
changeset
|
3379 * in "$ENV->func()" the "$" is not a range |
29008
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28992
diff
changeset
|
3380 * "123->func()" is a method call |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3381 */ |
20982
bb49b5090a9c
patch 8.2.1042: Vim9: cannot put an operator on the next line
Bram Moolenaar <Bram@vim.org>
parents:
20972
diff
changeset
|
3382 cmd = ea.cmd; |
26404
1bbb884c8561
patch 8.2.3733: Vim9: using "legacy" before range does not work
Bram Moolenaar <Bram@vim.org>
parents:
26372
diff
changeset
|
3383 if ((*cmd != '$' || starts_with_colon) |
27800
6e5d378919c4
patch 8.2.4426: map() function on string and blob does not check types
Bram Moolenaar <Bram@vim.org>
parents:
27738
diff
changeset
|
3384 && (starts_with_colon |
6e5d378919c4
patch 8.2.4426: map() function on string and blob does not check types
Bram Moolenaar <Bram@vim.org>
parents:
27738
diff
changeset
|
3385 || !(*cmd == '\'' |
6e5d378919c4
patch 8.2.4426: map() function on string and blob does not check types
Bram Moolenaar <Bram@vim.org>
parents:
27738
diff
changeset
|
3386 || (cmd[0] == '0' && cmd[1] == 'z') |
6e5d378919c4
patch 8.2.4426: map() function on string and blob does not check types
Bram Moolenaar <Bram@vim.org>
parents:
27738
diff
changeset
|
3387 || (cmd[0] != NUL && cmd[0] == cmd[1] |
29008
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28992
diff
changeset
|
3388 && (*cmd == '+' || *cmd == '-')) |
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28992
diff
changeset
|
3389 || number_method(cmd)))) |
20982
bb49b5090a9c
patch 8.2.1042: Vim9: cannot put an operator on the next line
Bram Moolenaar <Bram@vim.org>
parents:
20972
diff
changeset
|
3390 { |
22260
d7c1e3efa88e
patch 8.2.1679: Vim9: ":*" is not recognized as a range
Bram Moolenaar <Bram@vim.org>
parents:
22236
diff
changeset
|
3391 ea.cmd = skip_range(ea.cmd, TRUE, NULL); |
21901
1ebcce655dd3
patch 8.2.1500: Vim9: error when using address without a command
Bram Moolenaar <Bram@vim.org>
parents:
21893
diff
changeset
|
3392 if (ea.cmd > cmd) |
21335
af3663df42bf
patch 8.2.1218: Vim9: cannot use 'text'->func()
Bram Moolenaar <Bram@vim.org>
parents:
21301
diff
changeset
|
3393 { |
26404
1bbb884c8561
patch 8.2.3733: Vim9: using "legacy" before range does not work
Bram Moolenaar <Bram@vim.org>
parents:
26372
diff
changeset
|
3394 if (!starts_with_colon |
1bbb884c8561
patch 8.2.3733: Vim9: using "legacy" before range does not work
Bram Moolenaar <Bram@vim.org>
parents:
26372
diff
changeset
|
3395 && !(local_cmdmod.cmod_flags & CMOD_LEGACY)) |
21901
1ebcce655dd3
patch 8.2.1500: Vim9: error when using address without a command
Bram Moolenaar <Bram@vim.org>
parents:
21893
diff
changeset
|
3396 { |
23346
2060f53b7c17
patch 8.2.2216: Vim9: range with missing colon can be hard to spot
Bram Moolenaar <Bram@vim.org>
parents:
23344
diff
changeset
|
3397 semsg(_(e_colon_required_before_range_str), cmd); |
21901
1ebcce655dd3
patch 8.2.1500: Vim9: error when using address without a command
Bram Moolenaar <Bram@vim.org>
parents:
21893
diff
changeset
|
3398 goto erret; |
1ebcce655dd3
patch 8.2.1500: Vim9: error when using address without a command
Bram Moolenaar <Bram@vim.org>
parents:
21893
diff
changeset
|
3399 } |
23980
bee8c78c0c6a
patch 8.2.2532: Vim9: confusing error if :k is used with a range
Bram Moolenaar <Bram@vim.org>
parents:
23978
diff
changeset
|
3400 ea.addr_count = 1; |
21901
1ebcce655dd3
patch 8.2.1500: Vim9: error when using address without a command
Bram Moolenaar <Bram@vim.org>
parents:
21893
diff
changeset
|
3401 if (ends_excmd2(line, ea.cmd)) |
1ebcce655dd3
patch 8.2.1500: Vim9: error when using address without a command
Bram Moolenaar <Bram@vim.org>
parents:
21893
diff
changeset
|
3402 { |
1ebcce655dd3
patch 8.2.1500: Vim9: error when using address without a command
Bram Moolenaar <Bram@vim.org>
parents:
21893
diff
changeset
|
3403 // A range without a command: jump to the line. |
26370
a3a0885d9dd8
patch 8.2.3716: Vim9: range without a command is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
26360
diff
changeset
|
3404 generate_EXEC(&cctx, ISN_EXECRANGE, |
26404
1bbb884c8561
patch 8.2.3733: Vim9: using "legacy" before range does not work
Bram Moolenaar <Bram@vim.org>
parents:
26372
diff
changeset
|
3405 vim_strnsave(cmd, ea.cmd - cmd)); |
26370
a3a0885d9dd8
patch 8.2.3716: Vim9: range without a command is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
26360
diff
changeset
|
3406 line = ea.cmd; |
21901
1ebcce655dd3
patch 8.2.1500: Vim9: error when using address without a command
Bram Moolenaar <Bram@vim.org>
parents:
21893
diff
changeset
|
3407 goto nextline; |
1ebcce655dd3
patch 8.2.1500: Vim9: error when using address without a command
Bram Moolenaar <Bram@vim.org>
parents:
21893
diff
changeset
|
3408 } |
21335
af3663df42bf
patch 8.2.1218: Vim9: cannot use 'text'->func()
Bram Moolenaar <Bram@vim.org>
parents:
21301
diff
changeset
|
3409 } |
20982
bb49b5090a9c
patch 8.2.1042: Vim9: cannot put an operator on the next line
Bram Moolenaar <Bram@vim.org>
parents:
20972
diff
changeset
|
3410 } |
25274
84d5cda23b34
patch 8.2.3174: Vim9: "legacy undo" finds "undo" variable
Bram Moolenaar <Bram@vim.org>
parents:
25263
diff
changeset
|
3411 p = find_ex_command(&ea, NULL, |
84d5cda23b34
patch 8.2.3174: Vim9: "legacy undo" finds "undo" variable
Bram Moolenaar <Bram@vim.org>
parents:
25263
diff
changeset
|
3412 starts_with_colon || (local_cmdmod.cmod_flags & CMOD_LEGACY) |
24124
f4061617c438
patch 8.2.2603: Vim9: no effect if user command is also a function
Bram Moolenaar <Bram@vim.org>
parents:
24116
diff
changeset
|
3413 ? NULL : item_exists, &cctx); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3414 |
23513
872239543313
patch 8.2.2299: Vim9: invalid memory access making error message flaky
Bram Moolenaar <Bram@vim.org>
parents:
23505
diff
changeset
|
3415 if (p == NULL) |
872239543313
patch 8.2.2299: Vim9: invalid memory access making error message flaky
Bram Moolenaar <Bram@vim.org>
parents:
23505
diff
changeset
|
3416 { |
872239543313
patch 8.2.2299: Vim9: invalid memory access making error message flaky
Bram Moolenaar <Bram@vim.org>
parents:
23505
diff
changeset
|
3417 if (cctx.ctx_skip != SKIP_YES) |
27237
44cb142c8615
patch 8.2.4147: E464 does not always include the offending command
Bram Moolenaar <Bram@vim.org>
parents:
27148
diff
changeset
|
3418 semsg(_(e_ambiguous_use_of_user_defined_command_str), ea.cmd); |
23513
872239543313
patch 8.2.2299: Vim9: invalid memory access making error message flaky
Bram Moolenaar <Bram@vim.org>
parents:
23505
diff
changeset
|
3419 goto erret; |
872239543313
patch 8.2.2299: Vim9: invalid memory access making error message flaky
Bram Moolenaar <Bram@vim.org>
parents:
23505
diff
changeset
|
3420 } |
872239543313
patch 8.2.2299: Vim9: invalid memory access making error message flaky
Bram Moolenaar <Bram@vim.org>
parents:
23505
diff
changeset
|
3421 |
24531
3bfec39ce31c
patch 8.2.2805: Vim9: cannot use legacy syntax in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
24516
diff
changeset
|
3422 // When using ":legacy cmd" always use compile_exec(). |
3bfec39ce31c
patch 8.2.2805: Vim9: cannot use legacy syntax in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
24516
diff
changeset
|
3423 if (local_cmdmod.cmod_flags & CMOD_LEGACY) |
24645
668df21d8bc6
patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents:
24637
diff
changeset
|
3424 { |
668df21d8bc6
patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents:
24637
diff
changeset
|
3425 char_u *start = ea.cmd; |
668df21d8bc6
patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents:
24637
diff
changeset
|
3426 |
24776
7464d4c927f5
patch 8.2.2926: Vim9: no good error for using :legacy in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24717
diff
changeset
|
3427 switch (ea.cmdidx) |
7464d4c927f5
patch 8.2.2926: Vim9: no good error for using :legacy in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24717
diff
changeset
|
3428 { |
7464d4c927f5
patch 8.2.2926: Vim9: no good error for using :legacy in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24717
diff
changeset
|
3429 case CMD_if: |
7464d4c927f5
patch 8.2.2926: Vim9: no good error for using :legacy in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24717
diff
changeset
|
3430 case CMD_elseif: |
7464d4c927f5
patch 8.2.2926: Vim9: no good error for using :legacy in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24717
diff
changeset
|
3431 case CMD_else: |
7464d4c927f5
patch 8.2.2926: Vim9: no good error for using :legacy in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24717
diff
changeset
|
3432 case CMD_endif: |
7464d4c927f5
patch 8.2.2926: Vim9: no good error for using :legacy in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24717
diff
changeset
|
3433 case CMD_for: |
7464d4c927f5
patch 8.2.2926: Vim9: no good error for using :legacy in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24717
diff
changeset
|
3434 case CMD_endfor: |
7464d4c927f5
patch 8.2.2926: Vim9: no good error for using :legacy in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24717
diff
changeset
|
3435 case CMD_continue: |
7464d4c927f5
patch 8.2.2926: Vim9: no good error for using :legacy in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24717
diff
changeset
|
3436 case CMD_break: |
7464d4c927f5
patch 8.2.2926: Vim9: no good error for using :legacy in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24717
diff
changeset
|
3437 case CMD_while: |
7464d4c927f5
patch 8.2.2926: Vim9: no good error for using :legacy in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24717
diff
changeset
|
3438 case CMD_endwhile: |
7464d4c927f5
patch 8.2.2926: Vim9: no good error for using :legacy in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24717
diff
changeset
|
3439 case CMD_try: |
7464d4c927f5
patch 8.2.2926: Vim9: no good error for using :legacy in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24717
diff
changeset
|
3440 case CMD_catch: |
7464d4c927f5
patch 8.2.2926: Vim9: no good error for using :legacy in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24717
diff
changeset
|
3441 case CMD_finally: |
7464d4c927f5
patch 8.2.2926: Vim9: no good error for using :legacy in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24717
diff
changeset
|
3442 case CMD_endtry: |
7464d4c927f5
patch 8.2.2926: Vim9: no good error for using :legacy in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24717
diff
changeset
|
3443 semsg(_(e_cannot_use_legacy_with_command_str), ea.cmd); |
7464d4c927f5
patch 8.2.2926: Vim9: no good error for using :legacy in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24717
diff
changeset
|
3444 goto erret; |
7464d4c927f5
patch 8.2.2926: Vim9: no good error for using :legacy in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24717
diff
changeset
|
3445 default: break; |
7464d4c927f5
patch 8.2.2926: Vim9: no good error for using :legacy in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24717
diff
changeset
|
3446 } |
7464d4c927f5
patch 8.2.2926: Vim9: no good error for using :legacy in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24717
diff
changeset
|
3447 |
24645
668df21d8bc6
patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents:
24637
diff
changeset
|
3448 // ":legacy return expr" needs to be handled differently. |
668df21d8bc6
patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents:
24637
diff
changeset
|
3449 if (checkforcmd(&start, "return", 4)) |
668df21d8bc6
patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents:
24637
diff
changeset
|
3450 ea.cmdidx = CMD_return; |
668df21d8bc6
patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents:
24637
diff
changeset
|
3451 else |
668df21d8bc6
patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents:
24637
diff
changeset
|
3452 ea.cmdidx = CMD_legacy; |
668df21d8bc6
patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents:
24637
diff
changeset
|
3453 } |
24531
3bfec39ce31c
patch 8.2.2805: Vim9: cannot use legacy syntax in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
24516
diff
changeset
|
3454 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3455 if (p == ea.cmd && ea.cmdidx != CMD_SIZE) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3456 { |
28281
bd1dcc605e58
patch 8.2.4666: Vim9: assignment not recognized in skipped block
Bram Moolenaar <Bram@vim.org>
parents:
28217
diff
changeset
|
3457 // "eval" is used for "val->func()" and "var" for "var = val", then |
bd1dcc605e58
patch 8.2.4666: Vim9: assignment not recognized in skipped block
Bram Moolenaar <Bram@vim.org>
parents:
28217
diff
changeset
|
3458 // "p" is equal to "ea.cmd" for a valid command. |
bd1dcc605e58
patch 8.2.4666: Vim9: assignment not recognized in skipped block
Bram Moolenaar <Bram@vim.org>
parents:
28217
diff
changeset
|
3459 if (ea.cmdidx == CMD_eval || ea.cmdidx == CMD_var) |
bd1dcc605e58
patch 8.2.4666: Vim9: assignment not recognized in skipped block
Bram Moolenaar <Bram@vim.org>
parents:
28217
diff
changeset
|
3460 ; |
bd1dcc605e58
patch 8.2.4666: Vim9: assignment not recognized in skipped block
Bram Moolenaar <Bram@vim.org>
parents:
28217
diff
changeset
|
3461 else if (cctx.ctx_skip == SKIP_YES) |
19253
a8d2d3c8f0b3
patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
3462 { |
a8d2d3c8f0b3
patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
3463 line += STRLEN(line); |
23100
9c3a6c33c0e5
patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents:
23088
diff
changeset
|
3464 goto nextline; |
19253
a8d2d3c8f0b3
patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
3465 } |
28281
bd1dcc605e58
patch 8.2.4666: Vim9: assignment not recognized in skipped block
Bram Moolenaar <Bram@vim.org>
parents:
28217
diff
changeset
|
3466 else |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3467 { |
23254
4b7e996354e0
patch 8.2.2173: Vim9: get internal error when assigning to undefined variable
Bram Moolenaar <Bram@vim.org>
parents:
23245
diff
changeset
|
3468 semsg(_(e_command_not_recognized_str), ea.cmd); |
21196
f45ce1ce284c
patch 8.2.1149: Vim9: :eval command not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
21194
diff
changeset
|
3469 goto erret; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3470 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3471 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3472 |
21957
4343657b49fa
patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents:
21937
diff
changeset
|
3473 if (cctx.ctx_had_return |
19253
a8d2d3c8f0b3
patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
3474 && ea.cmdidx != CMD_elseif |
a8d2d3c8f0b3
patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
3475 && ea.cmdidx != CMD_else |
20909
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
3476 && ea.cmdidx != CMD_endif |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
3477 && ea.cmdidx != CMD_endfor |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
3478 && ea.cmdidx != CMD_endwhile |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
3479 && ea.cmdidx != CMD_catch |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
3480 && ea.cmdidx != CMD_finally |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
3481 && ea.cmdidx != CMD_endtry) |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
3482 { |
21957
4343657b49fa
patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents:
21937
diff
changeset
|
3483 emsg(_(e_unreachable_code_after_return)); |
4343657b49fa
patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents:
21937
diff
changeset
|
3484 goto erret; |
20909
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
3485 } |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
3486 |
22272
eb1f5f618c75
patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents:
22266
diff
changeset
|
3487 p = skipwhite(p); |
eb1f5f618c75
patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents:
22266
diff
changeset
|
3488 if (ea.cmdidx != CMD_SIZE |
eb1f5f618c75
patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents:
22266
diff
changeset
|
3489 && ea.cmdidx != CMD_write && ea.cmdidx != CMD_read) |
eb1f5f618c75
patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents:
22266
diff
changeset
|
3490 { |
22276
753452747ae5
patch 8.2.1687: Vim9: out of bounds error
Bram Moolenaar <Bram@vim.org>
parents:
22274
diff
changeset
|
3491 if (ea.cmdidx >= 0) |
753452747ae5
patch 8.2.1687: Vim9: out of bounds error
Bram Moolenaar <Bram@vim.org>
parents:
22274
diff
changeset
|
3492 ea.argt = excmd_get_argt(ea.cmdidx); |
22272
eb1f5f618c75
patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents:
22266
diff
changeset
|
3493 if ((ea.argt & EX_BANG) && *p == '!') |
eb1f5f618c75
patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents:
22266
diff
changeset
|
3494 { |
eb1f5f618c75
patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents:
22266
diff
changeset
|
3495 ea.forceit = TRUE; |
eb1f5f618c75
patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents:
22266
diff
changeset
|
3496 p = skipwhite(p + 1); |
eb1f5f618c75
patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents:
22266
diff
changeset
|
3497 } |
28694
7f12fe85ed8b
patch 8.2.4871: Vim9: in :def function no error for misplaced range
Bram Moolenaar <Bram@vim.org>
parents:
28678
diff
changeset
|
3498 if ((ea.argt & EX_RANGE) == 0 && ea.addr_count > 0) |
7f12fe85ed8b
patch 8.2.4871: Vim9: in :def function no error for misplaced range
Bram Moolenaar <Bram@vim.org>
parents:
28678
diff
changeset
|
3499 { |
7f12fe85ed8b
patch 8.2.4871: Vim9: in :def function no error for misplaced range
Bram Moolenaar <Bram@vim.org>
parents:
28678
diff
changeset
|
3500 emsg(_(e_no_range_allowed)); |
7f12fe85ed8b
patch 8.2.4871: Vim9: in :def function no error for misplaced range
Bram Moolenaar <Bram@vim.org>
parents:
28678
diff
changeset
|
3501 goto erret; |
7f12fe85ed8b
patch 8.2.4871: Vim9: in :def function no error for misplaced range
Bram Moolenaar <Bram@vim.org>
parents:
28678
diff
changeset
|
3502 } |
22272
eb1f5f618c75
patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents:
22266
diff
changeset
|
3503 } |
eb1f5f618c75
patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents:
22266
diff
changeset
|
3504 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3505 switch (ea.cmdidx) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3506 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3507 case CMD_def: |
26323
3841da4eac23
patch 8.2.3692: Vim9: cannot use :func inside a :def function
Bram Moolenaar <Bram@vim.org>
parents:
26248
diff
changeset
|
3508 case CMD_function: |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
3509 ea.arg = p; |
27022
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26980
diff
changeset
|
3510 line = compile_nested_function(&ea, &cctx, &lines_to_free); |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
3511 break; |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
3512 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3513 case CMD_return: |
24645
668df21d8bc6
patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents:
24637
diff
changeset
|
3514 line = compile_return(p, check_return_type, |
668df21d8bc6
patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents:
24637
diff
changeset
|
3515 local_cmdmod.cmod_flags & CMOD_LEGACY, &cctx); |
20909
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
3516 cctx.ctx_had_return = TRUE; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3517 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3518 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3519 case CMD_let: |
22667
87987c783087
patch 8.2.1882: Vim9: v:disallow_let is no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
22663
diff
changeset
|
3520 emsg(_(e_cannot_use_let_in_vim9_script)); |
87987c783087
patch 8.2.1882: Vim9: v:disallow_let is no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
22663
diff
changeset
|
3521 break; |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22381
diff
changeset
|
3522 case CMD_var: |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22381
diff
changeset
|
3523 case CMD_final: |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3524 case CMD_const: |
24533
9c404d78d767
patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents:
24531
diff
changeset
|
3525 case CMD_increment: |
9c404d78d767
patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents:
24531
diff
changeset
|
3526 case CMD_decrement: |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3527 line = compile_assignment(p, &ea, ea.cmdidx, &cctx); |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
3528 if (line == p) |
27738
d754ac2f5ac5
patch 8.2.4395: some code lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
27728
diff
changeset
|
3529 { |
d754ac2f5ac5
patch 8.2.4395: some code lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
27728
diff
changeset
|
3530 emsg(_(e_invalid_assignment)); |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
3531 line = NULL; |
27738
d754ac2f5ac5
patch 8.2.4395: some code lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
27728
diff
changeset
|
3532 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3533 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3534 |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
3535 case CMD_unlet: |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
3536 case CMD_unlockvar: |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
3537 case CMD_lockvar: |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
3538 line = compile_unletlock(p, &ea, &cctx); |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
3539 break; |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
3540 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3541 case CMD_import: |
25282
9bce044c7643
patch 8.2.3178: Vim9: the file name of an :import cannot be an expression
Bram Moolenaar <Bram@vim.org>
parents:
25274
diff
changeset
|
3542 emsg(_(e_import_can_only_be_used_in_script)); |
9bce044c7643
patch 8.2.3178: Vim9: the file name of an :import cannot be an expression
Bram Moolenaar <Bram@vim.org>
parents:
25274
diff
changeset
|
3543 line = NULL; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3544 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3545 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3546 case CMD_if: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3547 line = compile_if(p, &cctx); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3548 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3549 case CMD_elseif: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3550 line = compile_elseif(p, &cctx); |
20909
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
3551 cctx.ctx_had_return = FALSE; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3552 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3553 case CMD_else: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3554 line = compile_else(p, &cctx); |
20909
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
3555 cctx.ctx_had_return = FALSE; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3556 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3557 case CMD_endif: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3558 line = compile_endif(p, &cctx); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3559 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3560 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3561 case CMD_while: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3562 line = compile_while(p, &cctx); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3563 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3564 case CMD_endwhile: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3565 line = compile_endwhile(p, &cctx); |
20909
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
3566 cctx.ctx_had_return = FALSE; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3567 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3568 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3569 case CMD_for: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3570 line = compile_for(p, &cctx); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3571 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3572 case CMD_endfor: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3573 line = compile_endfor(p, &cctx); |
20909
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
3574 cctx.ctx_had_return = FALSE; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3575 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3576 case CMD_continue: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3577 line = compile_continue(p, &cctx); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3578 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3579 case CMD_break: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3580 line = compile_break(p, &cctx); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3581 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3582 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3583 case CMD_try: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3584 line = compile_try(p, &cctx); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3585 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3586 case CMD_catch: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3587 line = compile_catch(p, &cctx); |
20909
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
3588 cctx.ctx_had_return = FALSE; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3589 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3590 case CMD_finally: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3591 line = compile_finally(p, &cctx); |
20909
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
3592 cctx.ctx_had_return = FALSE; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3593 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3594 case CMD_endtry: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3595 line = compile_endtry(p, &cctx); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3596 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3597 case CMD_throw: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3598 line = compile_throw(p, &cctx); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3599 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3600 |
21196
f45ce1ce284c
patch 8.2.1149: Vim9: :eval command not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
21194
diff
changeset
|
3601 case CMD_eval: |
25202
e5d85e83a887
patch 8.2.3137: Vim9: no error when a line only has a variable name
Bram Moolenaar <Bram@vim.org>
parents:
25164
diff
changeset
|
3602 line = compile_eval(p, &cctx); |
21196
f45ce1ce284c
patch 8.2.1149: Vim9: :eval command not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
21194
diff
changeset
|
3603 break; |
f45ce1ce284c
patch 8.2.1149: Vim9: :eval command not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
21194
diff
changeset
|
3604 |
30065
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
30053
diff
changeset
|
3605 case CMD_defer: |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
30053
diff
changeset
|
3606 line = compile_defer(p, &cctx); |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
30053
diff
changeset
|
3607 break; |
6cf788ab844c
patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents:
30053
diff
changeset
|
3608 |
30697
d914a3812d5b
patch 9.0.0683: cannot specify a time for :echowindow
Bram Moolenaar <Bram@vim.org>
parents:
30584
diff
changeset
|
3609 #ifdef HAS_MESSAGE_WINDOW |
d914a3812d5b
patch 9.0.0683: cannot specify a time for :echowindow
Bram Moolenaar <Bram@vim.org>
parents:
30584
diff
changeset
|
3610 case CMD_echowindow: |
d914a3812d5b
patch 9.0.0683: cannot specify a time for :echowindow
Bram Moolenaar <Bram@vim.org>
parents:
30584
diff
changeset
|
3611 { |
d914a3812d5b
patch 9.0.0683: cannot specify a time for :echowindow
Bram Moolenaar <Bram@vim.org>
parents:
30584
diff
changeset
|
3612 long cmd_count = get_cmd_count(line, &ea); |
30699
f60315945f4a
patch 9.0.0684: skipped :exe command fails compilation on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
30697
diff
changeset
|
3613 if (cmd_count < 0) |
f60315945f4a
patch 9.0.0684: skipped :exe command fails compilation on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
30697
diff
changeset
|
3614 line = NULL; |
f60315945f4a
patch 9.0.0684: skipped :exe command fails compilation on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
30697
diff
changeset
|
3615 else |
30697
d914a3812d5b
patch 9.0.0683: cannot specify a time for :echowindow
Bram Moolenaar <Bram@vim.org>
parents:
30584
diff
changeset
|
3616 line = compile_mult_expr(p, ea.cmdidx, |
d914a3812d5b
patch 9.0.0683: cannot specify a time for :echowindow
Bram Moolenaar <Bram@vim.org>
parents:
30584
diff
changeset
|
3617 cmd_count, &cctx); |
d914a3812d5b
patch 9.0.0683: cannot specify a time for :echowindow
Bram Moolenaar <Bram@vim.org>
parents:
30584
diff
changeset
|
3618 } |
d914a3812d5b
patch 9.0.0683: cannot specify a time for :echowindow
Bram Moolenaar <Bram@vim.org>
parents:
30584
diff
changeset
|
3619 break; |
d914a3812d5b
patch 9.0.0683: cannot specify a time for :echowindow
Bram Moolenaar <Bram@vim.org>
parents:
30584
diff
changeset
|
3620 #endif |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3621 case CMD_echo: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3622 case CMD_echon: |
30025
d269dd3cd31d
patch 9.0.0350: :echowindow does not work in a compiled function
Bram Moolenaar <Bram@vim.org>
parents:
29828
diff
changeset
|
3623 case CMD_echoconsole: |
d269dd3cd31d
patch 9.0.0350: :echowindow does not work in a compiled function
Bram Moolenaar <Bram@vim.org>
parents:
29828
diff
changeset
|
3624 case CMD_echoerr: |
20142
fe8d0a4344df
patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20140
diff
changeset
|
3625 case CMD_echomsg: |
30025
d269dd3cd31d
patch 9.0.0350: :echowindow does not work in a compiled function
Bram Moolenaar <Bram@vim.org>
parents:
29828
diff
changeset
|
3626 case CMD_execute: |
30697
d914a3812d5b
patch 9.0.0683: cannot specify a time for :echowindow
Bram Moolenaar <Bram@vim.org>
parents:
30584
diff
changeset
|
3627 line = compile_mult_expr(p, ea.cmdidx, 0, &cctx); |
19528
3b026343f398
patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents:
19521
diff
changeset
|
3628 break; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3629 |
22176
6941d3205be9
patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
22021
diff
changeset
|
3630 case CMD_put: |
6941d3205be9
patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
22021
diff
changeset
|
3631 ea.cmd = cmd; |
6941d3205be9
patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
22021
diff
changeset
|
3632 line = compile_put(p, &ea, &cctx); |
6941d3205be9
patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
22021
diff
changeset
|
3633 break; |
6941d3205be9
patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
22021
diff
changeset
|
3634 |
24488
f293bb501b30
patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents:
24480
diff
changeset
|
3635 case CMD_substitute: |
25939
377a7686a52f
patch 8.2.3503: Vim9: using g:pat:cmd is confusing
Bram Moolenaar <Bram@vim.org>
parents:
25816
diff
changeset
|
3636 if (check_global_and_subst(ea.cmd, p) == FAIL) |
377a7686a52f
patch 8.2.3503: Vim9: using g:pat:cmd is confusing
Bram Moolenaar <Bram@vim.org>
parents:
25816
diff
changeset
|
3637 goto erret; |
24488
f293bb501b30
patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents:
24480
diff
changeset
|
3638 if (cctx.ctx_skip == SKIP_YES) |
f293bb501b30
patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents:
24480
diff
changeset
|
3639 line = (char_u *)""; |
f293bb501b30
patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents:
24480
diff
changeset
|
3640 else |
f293bb501b30
patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents:
24480
diff
changeset
|
3641 { |
f293bb501b30
patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents:
24480
diff
changeset
|
3642 ea.arg = p; |
f293bb501b30
patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents:
24480
diff
changeset
|
3643 line = compile_substitute(line, &ea, &cctx); |
f293bb501b30
patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents:
24480
diff
changeset
|
3644 } |
f293bb501b30
patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents:
24480
diff
changeset
|
3645 break; |
f293bb501b30
patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents:
24480
diff
changeset
|
3646 |
24490
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24488
diff
changeset
|
3647 case CMD_redir: |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24488
diff
changeset
|
3648 ea.arg = p; |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24488
diff
changeset
|
3649 line = compile_redir(line, &ea, &cctx); |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24488
diff
changeset
|
3650 break; |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24488
diff
changeset
|
3651 |
24590
2818f846f099
patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents:
24539
diff
changeset
|
3652 case CMD_cexpr: |
2818f846f099
patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents:
24539
diff
changeset
|
3653 case CMD_lexpr: |
2818f846f099
patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents:
24539
diff
changeset
|
3654 case CMD_caddexpr: |
2818f846f099
patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents:
24539
diff
changeset
|
3655 case CMD_laddexpr: |
2818f846f099
patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents:
24539
diff
changeset
|
3656 case CMD_cgetexpr: |
2818f846f099
patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents:
24539
diff
changeset
|
3657 case CMD_lgetexpr: |
24594
5c456a88f651
patch 8.2.2836: build failure without the +quickfix feature
Bram Moolenaar <Bram@vim.org>
parents:
24592
diff
changeset
|
3658 #ifdef FEAT_QUICKFIX |
24590
2818f846f099
patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents:
24539
diff
changeset
|
3659 ea.arg = p; |
2818f846f099
patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents:
24539
diff
changeset
|
3660 line = compile_cexpr(line, &ea, &cctx); |
24594
5c456a88f651
patch 8.2.2836: build failure without the +quickfix feature
Bram Moolenaar <Bram@vim.org>
parents:
24592
diff
changeset
|
3661 #else |
5c456a88f651
patch 8.2.2836: build failure without the +quickfix feature
Bram Moolenaar <Bram@vim.org>
parents:
24592
diff
changeset
|
3662 ex_ni(&ea); |
5c456a88f651
patch 8.2.2836: build failure without the +quickfix feature
Bram Moolenaar <Bram@vim.org>
parents:
24592
diff
changeset
|
3663 line = NULL; |
5c456a88f651
patch 8.2.2836: build failure without the +quickfix feature
Bram Moolenaar <Bram@vim.org>
parents:
24592
diff
changeset
|
3664 #endif |
24590
2818f846f099
patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents:
24539
diff
changeset
|
3665 break; |
2818f846f099
patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents:
24539
diff
changeset
|
3666 |
21516
c7b2ce90c2de
patch 8.2.1308: Vim9: accidentally using "x" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents:
21512
diff
changeset
|
3667 case CMD_append: |
c7b2ce90c2de
patch 8.2.1308: Vim9: accidentally using "x" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents:
21512
diff
changeset
|
3668 case CMD_change: |
c7b2ce90c2de
patch 8.2.1308: Vim9: accidentally using "x" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents:
21512
diff
changeset
|
3669 case CMD_insert: |
23978
54b2aa1f0d42
patch 8.2.2531: Vim9: the :k command is obscure
Bram Moolenaar <Bram@vim.org>
parents:
23966
diff
changeset
|
3670 case CMD_k: |
21584
d0c76ce48326
patch 8.2.1342: Vim9: accidentally using "t" gives a confusing error
Bram Moolenaar <Bram@vim.org>
parents:
21578
diff
changeset
|
3671 case CMD_t: |
21516
c7b2ce90c2de
patch 8.2.1308: Vim9: accidentally using "x" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents:
21512
diff
changeset
|
3672 case CMD_xit: |
c7b2ce90c2de
patch 8.2.1308: Vim9: accidentally using "x" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents:
21512
diff
changeset
|
3673 not_in_vim9(&ea); |
c7b2ce90c2de
patch 8.2.1308: Vim9: accidentally using "x" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents:
21512
diff
changeset
|
3674 goto erret; |
c7b2ce90c2de
patch 8.2.1308: Vim9: accidentally using "x" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents:
21512
diff
changeset
|
3675 |
21210
44611891e22c
patch 8.2.1156: Vim9: No error for invalid command in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
21208
diff
changeset
|
3676 case CMD_SIZE: |
21957
4343657b49fa
patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents:
21937
diff
changeset
|
3677 if (cctx.ctx_skip != SKIP_YES) |
4343657b49fa
patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents:
21937
diff
changeset
|
3678 { |
4343657b49fa
patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents:
21937
diff
changeset
|
3679 semsg(_(e_invalid_command_str), ea.cmd); |
4343657b49fa
patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents:
21937
diff
changeset
|
3680 goto erret; |
4343657b49fa
patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents:
21937
diff
changeset
|
3681 } |
4343657b49fa
patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents:
21937
diff
changeset
|
3682 // We don't check for a next command here. |
4343657b49fa
patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents:
21937
diff
changeset
|
3683 line = (char_u *)""; |
4343657b49fa
patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents:
21937
diff
changeset
|
3684 break; |
21210
44611891e22c
patch 8.2.1156: Vim9: No error for invalid command in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
21208
diff
changeset
|
3685 |
24826
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24796
diff
changeset
|
3686 case CMD_lua: |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24796
diff
changeset
|
3687 case CMD_mzscheme: |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24796
diff
changeset
|
3688 case CMD_perl: |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24796
diff
changeset
|
3689 case CMD_py3: |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24796
diff
changeset
|
3690 case CMD_python3: |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24796
diff
changeset
|
3691 case CMD_python: |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24796
diff
changeset
|
3692 case CMD_pythonx: |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24796
diff
changeset
|
3693 case CMD_ruby: |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24796
diff
changeset
|
3694 case CMD_tcl: |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24796
diff
changeset
|
3695 ea.arg = p; |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24796
diff
changeset
|
3696 if (vim_strchr(line, '\n') == NULL) |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24796
diff
changeset
|
3697 line = compile_exec(line, &ea, &cctx); |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24796
diff
changeset
|
3698 else |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24796
diff
changeset
|
3699 // heredoc lines have been concatenated with NL |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24796
diff
changeset
|
3700 // characters in get_function_body() |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24796
diff
changeset
|
3701 line = compile_script(line, &cctx); |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24796
diff
changeset
|
3702 break; |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24796
diff
changeset
|
3703 |
27571
55f0ac079829
patch 8.2.4312: no error for using :vim9script in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
27515
diff
changeset
|
3704 case CMD_vim9script: |
27575
9f70df0b2967
patch 8.2.4314: test fails where lines are skipped
Bram Moolenaar <Bram@vim.org>
parents:
27571
diff
changeset
|
3705 if (cctx.ctx_skip != SKIP_YES) |
9f70df0b2967
patch 8.2.4314: test fails where lines are skipped
Bram Moolenaar <Bram@vim.org>
parents:
27571
diff
changeset
|
3706 { |
9f70df0b2967
patch 8.2.4314: test fails where lines are skipped
Bram Moolenaar <Bram@vim.org>
parents:
27571
diff
changeset
|
3707 emsg(_(e_vim9script_can_only_be_used_in_script)); |
9f70df0b2967
patch 8.2.4314: test fails where lines are skipped
Bram Moolenaar <Bram@vim.org>
parents:
27571
diff
changeset
|
3708 goto erret; |
9f70df0b2967
patch 8.2.4314: test fails where lines are skipped
Bram Moolenaar <Bram@vim.org>
parents:
27571
diff
changeset
|
3709 } |
9f70df0b2967
patch 8.2.4314: test fails where lines are skipped
Bram Moolenaar <Bram@vim.org>
parents:
27571
diff
changeset
|
3710 line = (char_u *)""; |
9f70df0b2967
patch 8.2.4314: test fails where lines are skipped
Bram Moolenaar <Bram@vim.org>
parents:
27571
diff
changeset
|
3711 break; |
27571
55f0ac079829
patch 8.2.4312: no error for using :vim9script in a :def function
Bram Moolenaar <Bram@vim.org>
parents:
27515
diff
changeset
|
3712 |
25939
377a7686a52f
patch 8.2.3503: Vim9: using g:pat:cmd is confusing
Bram Moolenaar <Bram@vim.org>
parents:
25816
diff
changeset
|
3713 case CMD_global: |
377a7686a52f
patch 8.2.3503: Vim9: using g:pat:cmd is confusing
Bram Moolenaar <Bram@vim.org>
parents:
25816
diff
changeset
|
3714 if (check_global_and_subst(ea.cmd, p) == FAIL) |
377a7686a52f
patch 8.2.3503: Vim9: using g:pat:cmd is confusing
Bram Moolenaar <Bram@vim.org>
parents:
25816
diff
changeset
|
3715 goto erret; |
377a7686a52f
patch 8.2.3503: Vim9: using g:pat:cmd is confusing
Bram Moolenaar <Bram@vim.org>
parents:
25816
diff
changeset
|
3716 // FALLTHROUGH |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3717 default: |
24826
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24796
diff
changeset
|
3718 // Not recognized, execute with do_cmdline_cmd(). |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24796
diff
changeset
|
3719 ea.arg = p; |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24796
diff
changeset
|
3720 line = compile_exec(line, &ea, &cctx); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3721 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3722 } |
21901
1ebcce655dd3
patch 8.2.1500: Vim9: error when using address without a command
Bram Moolenaar <Bram@vim.org>
parents:
21893
diff
changeset
|
3723 nextline: |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3724 if (line == NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3725 goto erret; |
19894
ea4f8e789627
patch 8.2.0503: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
19892
diff
changeset
|
3726 line = skipwhite(line); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3727 |
22691
dda110a14be4
patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents:
22685
diff
changeset
|
3728 // Undo any command modifiers. |
22703
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
3729 generate_undo_cmdmods(&cctx); |
22691
dda110a14be4
patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents:
22685
diff
changeset
|
3730 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3731 if (cctx.ctx_type_stack.ga_len < 0) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3732 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3733 iemsg("Type stack underflow"); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3734 goto erret; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3735 } |
31865
86ed5031ff2b
patch 9.0.1265: using an interface method may give a compilation error
Bram Moolenaar <Bram@vim.org>
parents:
31827
diff
changeset
|
3736 } // END of the loop over all the function body lines. |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3737 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3738 if (cctx.ctx_scope != NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3739 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3740 if (cctx.ctx_scope->se_type == IF_SCOPE) |
26857
2aeea8611342
patch 8.2.3957: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26851
diff
changeset
|
3741 emsg(_(e_missing_endif)); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3742 else if (cctx.ctx_scope->se_type == WHILE_SCOPE) |
26857
2aeea8611342
patch 8.2.3957: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26851
diff
changeset
|
3743 emsg(_(e_missing_endwhile)); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3744 else if (cctx.ctx_scope->se_type == FOR_SCOPE) |
26857
2aeea8611342
patch 8.2.3957: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26851
diff
changeset
|
3745 emsg(_(e_missing_endfor)); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3746 else |
21821
0deb6f96a5a3
patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
21811
diff
changeset
|
3747 emsg(_(e_missing_rcurly)); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3748 goto erret; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3749 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3750 |
20909
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
3751 if (!cctx.ctx_had_return) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3752 { |
24893
1d6242cf1163
patch 8.2.2984: Vim9: test fails because of missing return statement
Bram Moolenaar <Bram@vim.org>
parents:
24890
diff
changeset
|
3753 if (ufunc->uf_ret_type->tt_type == VAR_UNKNOWN) |
1d6242cf1163
patch 8.2.2984: Vim9: test fails because of missing return statement
Bram Moolenaar <Bram@vim.org>
parents:
24890
diff
changeset
|
3754 ufunc->uf_ret_type = &t_void; |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
3755 else if (ufunc->uf_ret_type->tt_type != VAR_VOID |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
3756 && (ufunc->uf_flags & FC_NEW) != FC_NEW) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3757 { |
21821
0deb6f96a5a3
patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
21811
diff
changeset
|
3758 emsg(_(e_missing_return_statement)); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3759 goto erret; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3760 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3761 |
24936
345619f35112
patch 8.2.3005: Vim9: using a void value does not give a proper error message
Bram Moolenaar <Bram@vim.org>
parents:
24928
diff
changeset
|
3762 // Return void if there is no return at the end. |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
3763 // For a constructor return the object. |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
3764 if ((ufunc->uf_flags & FC_NEW) == FC_NEW) |
31424
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
3765 { |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
3766 generate_instr(&cctx, ISN_RETURN_OBJECT); |
31424
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
3767 ufunc->uf_ret_type = &ufunc->uf_class->class_object_type; |
e31fc75f6aff
patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
3768 } |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
3769 else |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31172
diff
changeset
|
3770 generate_instr(&cctx, ISN_RETURN_VOID); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3771 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3772 |
24406
a26f0fa12845
patch 8.2.2743: Vim9: function state stuck when compiling with ":silent!"
Bram Moolenaar <Bram@vim.org>
parents:
24404
diff
changeset
|
3773 // When compiled with ":silent!" and there was an error don't consider the |
a26f0fa12845
patch 8.2.2743: Vim9: function state stuck when compiling with ":silent!"
Bram Moolenaar <Bram@vim.org>
parents:
24404
diff
changeset
|
3774 // function compiled. |
a26f0fa12845
patch 8.2.2743: Vim9: function state stuck when compiling with ":silent!"
Bram Moolenaar <Bram@vim.org>
parents:
24404
diff
changeset
|
3775 if (emsg_silent == 0 || did_emsg_silent == did_emsg_silent_before) |
19864
8288884fdfe1
patch 8.2.0488: Vim9: compiling can break when using a lambda inside :def
Bram Moolenaar <Bram@vim.org>
parents:
19862
diff
changeset
|
3776 { |
8288884fdfe1
patch 8.2.0488: Vim9: compiling can break when using a lambda inside :def
Bram Moolenaar <Bram@vim.org>
parents:
19862
diff
changeset
|
3777 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data) |
8288884fdfe1
patch 8.2.0488: Vim9: compiling can break when using a lambda inside :def
Bram Moolenaar <Bram@vim.org>
parents:
19862
diff
changeset
|
3778 + ufunc->uf_dfunc_idx; |
8288884fdfe1
patch 8.2.0488: Vim9: compiling can break when using a lambda inside :def
Bram Moolenaar <Bram@vim.org>
parents:
19862
diff
changeset
|
3779 dfunc->df_deleted = FALSE; |
23330
e8eb4fd44902
patch 8.2.2208: Vim9: after reloading a script variable index may be invalid
Bram Moolenaar <Bram@vim.org>
parents:
23318
diff
changeset
|
3780 dfunc->df_script_seq = current_sctx.sc_seq; |
23719
1a7c2685d780
patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents:
23717
diff
changeset
|
3781 #ifdef FEAT_PROFILE |
24895
e61a2085c89b
patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents:
24893
diff
changeset
|
3782 if (cctx.ctx_compile_type == CT_PROFILE) |
23717
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23697
diff
changeset
|
3783 { |
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23697
diff
changeset
|
3784 dfunc->df_instr_prof = instr->ga_data; |
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23697
diff
changeset
|
3785 dfunc->df_instr_prof_count = instr->ga_len; |
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23697
diff
changeset
|
3786 } |
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23697
diff
changeset
|
3787 else |
23719
1a7c2685d780
patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents:
23717
diff
changeset
|
3788 #endif |
24895
e61a2085c89b
patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents:
24893
diff
changeset
|
3789 if (cctx.ctx_compile_type == CT_DEBUG) |
e61a2085c89b
patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents:
24893
diff
changeset
|
3790 { |
e61a2085c89b
patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents:
24893
diff
changeset
|
3791 dfunc->df_instr_debug = instr->ga_data; |
e61a2085c89b
patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents:
24893
diff
changeset
|
3792 dfunc->df_instr_debug_count = instr->ga_len; |
e61a2085c89b
patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents:
24893
diff
changeset
|
3793 } |
e61a2085c89b
patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents:
24893
diff
changeset
|
3794 else |
23717
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23697
diff
changeset
|
3795 { |
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23697
diff
changeset
|
3796 dfunc->df_instr = instr->ga_data; |
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23697
diff
changeset
|
3797 dfunc->df_instr_count = instr->ga_len; |
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23697
diff
changeset
|
3798 } |
24918
f11779c1d123
patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents:
24914
diff
changeset
|
3799 dfunc->df_varcount = dfunc->df_var_names.ga_len; |
22371
15003353a464
patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents:
22369
diff
changeset
|
3800 dfunc->df_has_closure = cctx.ctx_has_closure; |
30269
42a6345b91fd
patch 9.0.0470: in :def function all closures in loop get the same variables
Bram Moolenaar <Bram@vim.org>
parents:
30249
diff
changeset
|
3801 |
20244
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
3802 if (cctx.ctx_outer_used) |
30269
42a6345b91fd
patch 9.0.0470: in :def function all closures in loop get the same variables
Bram Moolenaar <Bram@vim.org>
parents:
30249
diff
changeset
|
3803 { |
20244
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
3804 ufunc->uf_flags |= FC_CLOSURE; |
30269
42a6345b91fd
patch 9.0.0470: in :def function all closures in loop get the same variables
Bram Moolenaar <Bram@vim.org>
parents:
30249
diff
changeset
|
3805 if (outer_cctx != NULL) |
42a6345b91fd
patch 9.0.0470: in :def function all closures in loop get the same variables
Bram Moolenaar <Bram@vim.org>
parents:
30249
diff
changeset
|
3806 ++outer_cctx->ctx_closure_count; |
42a6345b91fd
patch 9.0.0470: in :def function all closures in loop get the same variables
Bram Moolenaar <Bram@vim.org>
parents:
30249
diff
changeset
|
3807 } |
42a6345b91fd
patch 9.0.0470: in :def function all closures in loop get the same variables
Bram Moolenaar <Bram@vim.org>
parents:
30249
diff
changeset
|
3808 |
20943
1693ca876049
patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents:
20933
diff
changeset
|
3809 ufunc->uf_def_status = UF_COMPILED; |
19864
8288884fdfe1
patch 8.2.0488: Vim9: compiling can break when using a lambda inside :def
Bram Moolenaar <Bram@vim.org>
parents:
19862
diff
changeset
|
3810 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3811 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3812 ret = OK; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3813 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3814 erret: |
24406
a26f0fa12845
patch 8.2.2743: Vim9: function state stuck when compiling with ":silent!"
Bram Moolenaar <Bram@vim.org>
parents:
24404
diff
changeset
|
3815 if (ufunc->uf_def_status == UF_COMPILING) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3816 { |
19864
8288884fdfe1
patch 8.2.0488: Vim9: compiling can break when using a lambda inside :def
Bram Moolenaar <Bram@vim.org>
parents:
19862
diff
changeset
|
3817 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data) |
8288884fdfe1
patch 8.2.0488: Vim9: compiling can break when using a lambda inside :def
Bram Moolenaar <Bram@vim.org>
parents:
19862
diff
changeset
|
3818 + ufunc->uf_dfunc_idx; |
19726
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
3819 |
24928
cf4bc18a3931
patch 8.2.3001: Vim9: memory leak when compilation fails
Bram Moolenaar <Bram@vim.org>
parents:
24926
diff
changeset
|
3820 // Compiling aborted, free the generated instructions. |
24498
bfa495227ac6
patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents:
24492
diff
changeset
|
3821 clear_instr_ga(instr); |
23285
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23266
diff
changeset
|
3822 VIM_CLEAR(dfunc->df_name); |
24928
cf4bc18a3931
patch 8.2.3001: Vim9: memory leak when compilation fails
Bram Moolenaar <Bram@vim.org>
parents:
24926
diff
changeset
|
3823 ga_clear_strings(&dfunc->df_var_names); |
19726
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
3824 |
21463
7f36d36f7195
patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents:
21455
diff
changeset
|
3825 // If using the last entry in the table and it was added above, we |
7f36d36f7195
patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents:
21455
diff
changeset
|
3826 // might as well remove it. |
7f36d36f7195
patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents:
21455
diff
changeset
|
3827 if (!dfunc->df_deleted && new_def_function |
20534
ae758aa4ee5e
patch 8.2.0821: Vim9: memory leak in expr test
Bram Moolenaar <Bram@vim.org>
parents:
20532
diff
changeset
|
3828 && ufunc->uf_dfunc_idx == def_functions.ga_len - 1) |
21463
7f36d36f7195
patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents:
21455
diff
changeset
|
3829 { |
20534
ae758aa4ee5e
patch 8.2.0821: Vim9: memory leak in expr test
Bram Moolenaar <Bram@vim.org>
parents:
20532
diff
changeset
|
3830 --def_functions.ga_len; |
21463
7f36d36f7195
patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents:
21455
diff
changeset
|
3831 ufunc->uf_dfunc_idx = 0; |
7f36d36f7195
patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents:
21455
diff
changeset
|
3832 } |
24404
a2a7d2d6e724
patch 8.2.2742: Vim9: when compiling a function fails it is cleared
Bram Moolenaar <Bram@vim.org>
parents:
24402
diff
changeset
|
3833 ufunc->uf_def_status = UF_COMPILE_ERROR; |
19726
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
3834 |
19896
92177b596695
patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents:
19894
diff
changeset
|
3835 while (cctx.ctx_scope != NULL) |
92177b596695
patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents:
19894
diff
changeset
|
3836 drop_scope(&cctx); |
92177b596695
patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents:
19894
diff
changeset
|
3837 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3838 if (errormsg != NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3839 emsg(errormsg); |
22758
48feb3dd0d25
patch 8.2.1927: Vim9: get unknown error with an error in a timer function
Bram Moolenaar <Bram@vim.org>
parents:
22734
diff
changeset
|
3840 else if (did_emsg == did_emsg_before) |
22614
048a3033d19c
patch 8.2.1855: Vim9: get error message when nothing is wrong
Bram Moolenaar <Bram@vim.org>
parents:
22606
diff
changeset
|
3841 emsg(_(e_compiling_def_function_failed)); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3842 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3843 |
24490
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24488
diff
changeset
|
3844 if (cctx.ctx_redir_lhs.lhs_name != NULL) |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24488
diff
changeset
|
3845 { |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24488
diff
changeset
|
3846 if (ret == OK) |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24488
diff
changeset
|
3847 { |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24488
diff
changeset
|
3848 emsg(_(e_missing_redir_end)); |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24488
diff
changeset
|
3849 ret = FAIL; |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24488
diff
changeset
|
3850 } |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24488
diff
changeset
|
3851 vim_free(cctx.ctx_redir_lhs.lhs_name); |
24512
53871095bb65
patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents:
24510
diff
changeset
|
3852 vim_free(cctx.ctx_redir_lhs.lhs_whole); |
24490
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24488
diff
changeset
|
3853 } |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24488
diff
changeset
|
3854 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3855 current_sctx = save_current_sctx; |
22584
c271498e03b2
patch 8.2.1840: Vim9: error message is not clear about compilation error
Bram Moolenaar <Bram@vim.org>
parents:
22537
diff
changeset
|
3856 estack_compiling = save_estack_compiling; |
24539
3a290891a015
patch 8.2.2809: Vim9: :def function compilation fails when using :legacy
Bram Moolenaar <Bram@vim.org>
parents:
24533
diff
changeset
|
3857 cmdmod.cmod_flags = save_cmod_flags; |
20538
9f921ba86d05
patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents:
20534
diff
changeset
|
3858 if (do_estack_push) |
9f921ba86d05
patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents:
20534
diff
changeset
|
3859 estack_pop(); |
9f921ba86d05
patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents:
20534
diff
changeset
|
3860 |
27022
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26980
diff
changeset
|
3861 ga_clear_strings(&lines_to_free); |
20239
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
3862 free_locals(&cctx); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3863 ga_clear(&cctx.ctx_type_stack); |
20528
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20419
diff
changeset
|
3864 return ret; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3865 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3866 |
20532
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
3867 void |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
3868 set_function_type(ufunc_T *ufunc) |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
3869 { |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
3870 int varargs = ufunc->uf_va_name != NULL; |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
3871 int argcount = ufunc->uf_args.ga_len; |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
3872 |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
3873 // Create a type for the function, with the return type and any |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
3874 // argument types. |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
3875 // A vararg is included in uf_args.ga_len but not in uf_arg_types. |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
3876 // The type is included in "tt_args". |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
3877 if (argcount > 0 || varargs) |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
3878 { |
24061
d6489b4eb14e
patch 8.2.2572: Vim9: crash when getting the types for a legacy function
Bram Moolenaar <Bram@vim.org>
parents:
24033
diff
changeset
|
3879 if (ufunc->uf_type_list.ga_itemsize == 0) |
d6489b4eb14e
patch 8.2.2572: Vim9: crash when getting the types for a legacy function
Bram Moolenaar <Bram@vim.org>
parents:
24033
diff
changeset
|
3880 ga_init2(&ufunc->uf_type_list, sizeof(type_T *), 10); |
20532
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
3881 ufunc->uf_func_type = alloc_func_type(ufunc->uf_ret_type, |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
3882 argcount, &ufunc->uf_type_list); |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
3883 // Add argument types to the function type. |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
3884 if (func_type_add_arg_types(ufunc->uf_func_type, |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
3885 argcount + varargs, |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
3886 &ufunc->uf_type_list) == FAIL) |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
3887 return; |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
3888 ufunc->uf_func_type->tt_argcount = argcount + varargs; |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
3889 ufunc->uf_func_type->tt_min_argcount = |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
3890 argcount - ufunc->uf_def_args.ga_len; |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
3891 if (ufunc->uf_arg_types == NULL) |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
3892 { |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
3893 int i; |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
3894 |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
3895 // lambda does not have argument types. |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
3896 for (i = 0; i < argcount; ++i) |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
3897 ufunc->uf_func_type->tt_args[i] = &t_any; |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
3898 } |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
3899 else |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
3900 mch_memmove(ufunc->uf_func_type->tt_args, |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
3901 ufunc->uf_arg_types, sizeof(type_T *) * argcount); |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
3902 if (varargs) |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
3903 { |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
3904 ufunc->uf_func_type->tt_args[argcount] = |
24400
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24390
diff
changeset
|
3905 ufunc->uf_va_type == NULL ? &t_list_any : ufunc->uf_va_type; |
20532
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
3906 ufunc->uf_func_type->tt_flags = TTFLAG_VARARGS; |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
3907 } |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
3908 } |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
3909 else |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
3910 // No arguments, can use a predefined type. |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
3911 ufunc->uf_func_type = get_func_type(ufunc->uf_ret_type, |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
3912 argcount, &ufunc->uf_type_list); |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
3913 } |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
3914 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3915 /* |
23285
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23266
diff
changeset
|
3916 * Free all instructions for "dfunc" except df_name. |
19726
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
3917 */ |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
3918 static void |
23360
eb7d8f39363c
patch 8.2.2223: Vim9: Reloading marks a :def function as deleted
Bram Moolenaar <Bram@vim.org>
parents:
23352
diff
changeset
|
3919 delete_def_function_contents(dfunc_T *dfunc, int mark_deleted) |
19726
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
3920 { |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
3921 int idx; |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
3922 |
31483
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31445
diff
changeset
|
3923 // In same cases the instructions may refer to a class in which the |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31445
diff
changeset
|
3924 // function is defined and unreferencing the class may call back here |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31445
diff
changeset
|
3925 // recursively. Set the df_delete_busy to avoid problems. |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31445
diff
changeset
|
3926 if (dfunc->df_delete_busy) |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31445
diff
changeset
|
3927 return; |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31445
diff
changeset
|
3928 dfunc->df_delete_busy = TRUE; |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31445
diff
changeset
|
3929 |
19726
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
3930 ga_clear(&dfunc->df_def_args_isn); |
24918
f11779c1d123
patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents:
24914
diff
changeset
|
3931 ga_clear_strings(&dfunc->df_var_names); |
19726
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
3932 |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
3933 if (dfunc->df_instr != NULL) |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
3934 { |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
3935 for (idx = 0; idx < dfunc->df_instr_count; ++idx) |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
3936 delete_instr(dfunc->df_instr + idx); |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
3937 VIM_CLEAR(dfunc->df_instr); |
23360
eb7d8f39363c
patch 8.2.2223: Vim9: Reloading marks a :def function as deleted
Bram Moolenaar <Bram@vim.org>
parents:
23352
diff
changeset
|
3938 } |
24903
99324f6b535a
patch 8.2.2989: Vim9: memory leak when debugging a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24897
diff
changeset
|
3939 if (dfunc->df_instr_debug != NULL) |
99324f6b535a
patch 8.2.2989: Vim9: memory leak when debugging a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24897
diff
changeset
|
3940 { |
99324f6b535a
patch 8.2.2989: Vim9: memory leak when debugging a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24897
diff
changeset
|
3941 for (idx = 0; idx < dfunc->df_instr_debug_count; ++idx) |
99324f6b535a
patch 8.2.2989: Vim9: memory leak when debugging a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24897
diff
changeset
|
3942 delete_instr(dfunc->df_instr_debug + idx); |
99324f6b535a
patch 8.2.2989: Vim9: memory leak when debugging a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24897
diff
changeset
|
3943 VIM_CLEAR(dfunc->df_instr_debug); |
99324f6b535a
patch 8.2.2989: Vim9: memory leak when debugging a :def function
Bram Moolenaar <Bram@vim.org>
parents:
24897
diff
changeset
|
3944 } |
23729
7eef04861034
patch 8.2.2406: Vim9: profiled :def function leaks memory
Bram Moolenaar <Bram@vim.org>
parents:
23725
diff
changeset
|
3945 #ifdef FEAT_PROFILE |
7eef04861034
patch 8.2.2406: Vim9: profiled :def function leaks memory
Bram Moolenaar <Bram@vim.org>
parents:
23725
diff
changeset
|
3946 if (dfunc->df_instr_prof != NULL) |
7eef04861034
patch 8.2.2406: Vim9: profiled :def function leaks memory
Bram Moolenaar <Bram@vim.org>
parents:
23725
diff
changeset
|
3947 { |
7eef04861034
patch 8.2.2406: Vim9: profiled :def function leaks memory
Bram Moolenaar <Bram@vim.org>
parents:
23725
diff
changeset
|
3948 for (idx = 0; idx < dfunc->df_instr_prof_count; ++idx) |
7eef04861034
patch 8.2.2406: Vim9: profiled :def function leaks memory
Bram Moolenaar <Bram@vim.org>
parents:
23725
diff
changeset
|
3949 delete_instr(dfunc->df_instr_prof + idx); |
7eef04861034
patch 8.2.2406: Vim9: profiled :def function leaks memory
Bram Moolenaar <Bram@vim.org>
parents:
23725
diff
changeset
|
3950 VIM_CLEAR(dfunc->df_instr_prof); |
7eef04861034
patch 8.2.2406: Vim9: profiled :def function leaks memory
Bram Moolenaar <Bram@vim.org>
parents:
23725
diff
changeset
|
3951 } |
7eef04861034
patch 8.2.2406: Vim9: profiled :def function leaks memory
Bram Moolenaar <Bram@vim.org>
parents:
23725
diff
changeset
|
3952 #endif |
23360
eb7d8f39363c
patch 8.2.2223: Vim9: Reloading marks a :def function as deleted
Bram Moolenaar <Bram@vim.org>
parents:
23352
diff
changeset
|
3953 |
eb7d8f39363c
patch 8.2.2223: Vim9: Reloading marks a :def function as deleted
Bram Moolenaar <Bram@vim.org>
parents:
23352
diff
changeset
|
3954 if (mark_deleted) |
eb7d8f39363c
patch 8.2.2223: Vim9: Reloading marks a :def function as deleted
Bram Moolenaar <Bram@vim.org>
parents:
23352
diff
changeset
|
3955 dfunc->df_deleted = TRUE; |
eb7d8f39363c
patch 8.2.2223: Vim9: Reloading marks a :def function as deleted
Bram Moolenaar <Bram@vim.org>
parents:
23352
diff
changeset
|
3956 if (dfunc->df_ufunc != NULL) |
eb7d8f39363c
patch 8.2.2223: Vim9: Reloading marks a :def function as deleted
Bram Moolenaar <Bram@vim.org>
parents:
23352
diff
changeset
|
3957 dfunc->df_ufunc->uf_def_status = UF_NOT_COMPILED; |
31483
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31445
diff
changeset
|
3958 |
1bebc2093e6b
patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents:
31445
diff
changeset
|
3959 dfunc->df_delete_busy = FALSE; |
19726
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
3960 } |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
3961 |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
3962 /* |
20943
1693ca876049
patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents:
20933
diff
changeset
|
3963 * When a user function is deleted, clear the contents of any associated def |
23285
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23266
diff
changeset
|
3964 * function, unless another user function still uses it. |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23266
diff
changeset
|
3965 * The position in def_functions can be re-used. |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3966 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3967 void |
23285
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23266
diff
changeset
|
3968 unlink_def_function(ufunc_T *ufunc) |
20943
1693ca876049
patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents:
20933
diff
changeset
|
3969 { |
31827
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31770
diff
changeset
|
3970 if (ufunc->uf_dfunc_idx <= 0) |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31770
diff
changeset
|
3971 return; |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31770
diff
changeset
|
3972 |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31770
diff
changeset
|
3973 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data) |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31770
diff
changeset
|
3974 + ufunc->uf_dfunc_idx; |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31770
diff
changeset
|
3975 |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31770
diff
changeset
|
3976 if (--dfunc->df_refcount <= 0) |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31770
diff
changeset
|
3977 delete_def_function_contents(dfunc, TRUE); |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31770
diff
changeset
|
3978 ufunc->uf_def_status = UF_NOT_COMPILED; |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31770
diff
changeset
|
3979 ufunc->uf_dfunc_idx = 0; |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31770
diff
changeset
|
3980 if (dfunc->df_ufunc == ufunc) |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31770
diff
changeset
|
3981 dfunc->df_ufunc = NULL; |
23285
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23266
diff
changeset
|
3982 } |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23266
diff
changeset
|
3983 |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23266
diff
changeset
|
3984 /* |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23266
diff
changeset
|
3985 * Used when a user function refers to an existing dfunc. |
22324
a4ed0de125d9
patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents:
22318
diff
changeset
|
3986 */ |
a4ed0de125d9
patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents:
22318
diff
changeset
|
3987 void |
23285
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23266
diff
changeset
|
3988 link_def_function(ufunc_T *ufunc) |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23266
diff
changeset
|
3989 { |
31827
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31770
diff
changeset
|
3990 if (ufunc->uf_dfunc_idx <= 0) |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31770
diff
changeset
|
3991 return; |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31770
diff
changeset
|
3992 |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31770
diff
changeset
|
3993 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data) |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31770
diff
changeset
|
3994 + ufunc->uf_dfunc_idx; |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31770
diff
changeset
|
3995 |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31770
diff
changeset
|
3996 ++dfunc->df_refcount; |
22324
a4ed0de125d9
patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents:
22318
diff
changeset
|
3997 } |
a4ed0de125d9
patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents:
22318
diff
changeset
|
3998 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3999 #if defined(EXITFREE) || defined(PROTO) |
19726
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
4000 /* |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
4001 * Free all functions defined with ":def". |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
4002 */ |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4003 void |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4004 free_def_functions(void) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4005 { |
19726
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
4006 int idx; |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
4007 |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
4008 for (idx = 0; idx < def_functions.ga_len; ++idx) |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
4009 { |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
4010 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data) + idx; |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
4011 |
23360
eb7d8f39363c
patch 8.2.2223: Vim9: Reloading marks a :def function as deleted
Bram Moolenaar <Bram@vim.org>
parents:
23352
diff
changeset
|
4012 delete_def_function_contents(dfunc, TRUE); |
23285
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23266
diff
changeset
|
4013 vim_free(dfunc->df_name); |
19726
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
4014 } |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
4015 |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
4016 ga_clear(&def_functions); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4017 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4018 #endif |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4019 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4020 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4021 #endif // FEAT_EVAL |