annotate src/vim9compile.c @ 32669:448aef880252

normalize line endings
author Christian Brabandt <cb@256bit.org>
date Mon, 26 Jun 2023 09:54:34 +0200
parents a44d7e4ac1c0
children 695b50472e85
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32669
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
4 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
7 * See README.txt for an overview of the Vim source code.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
8 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
9
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
10 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
11 * vim9compile.c: compiling a :def function
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
12 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
13
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
14 #define USING_FLOAT_STUFF
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
15 #include "vim.h"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
16
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
17 #if defined(FEAT_EVAL) || defined(PROTO)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
18
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
19 // When not generating protos this is included in proto.h
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
20 #ifdef PROTO
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
21 # include "vim9.h"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
22 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
23
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
24 // Functions defined with :def are stored in this growarray.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
25 // They are never removed, so that they can be found by index.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
26 // Deleted functions have the df_deleted flag set.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
27 garray_T def_functions = {0, 0, sizeof(dfunc_T), 50, NULL};
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
28
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
29 static void delete_def_function_contents(dfunc_T *dfunc, int mark_deleted);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
30
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
31 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
32 * Lookup variable "name" in the local scope and return it in "lvar".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
33 * "lvar->lv_from_outer" is incremented accordingly.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
34 * If "lvar" is NULL only check if the variable can be found.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
35 * Return FAIL if not found.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
36 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
37 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
38 lookup_local(char_u *name, size_t len, lvar_T *lvar, cctx_T *cctx)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
39 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
40 int idx;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
41 lvar_T *lvp;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
42
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
43 if (len == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
44 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
45
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
46 if (((len == 4 && STRNCMP(name, "this", 4) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
47 || (len == 5 && STRNCMP(name, "super", 5) == 0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
48 && cctx->ctx_ufunc != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
49 && (cctx->ctx_ufunc->uf_flags & (FC_OBJECT|FC_NEW)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
50 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
51 int is_super = *name == 's';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
52 if (is_super)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
53 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
54 if (name[5] != '.')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
55 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
56 emsg(_(e_super_must_be_followed_by_dot));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
57 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
58 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
59 if (cctx->ctx_ufunc->uf_class != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
60 && cctx->ctx_ufunc->uf_class->class_extends == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
61 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
62 emsg(_(e_using_super_not_in_child_class));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
63 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
64 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
65 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
66 if (lvar != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
67 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
68 CLEAR_POINTER(lvar);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
69 lvar->lv_loop_depth = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
70 lvar->lv_name = (char_u *)(is_super ? "super" : "this");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
71 if (cctx->ctx_ufunc->uf_class != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
72 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
73 lvar->lv_type = &cctx->ctx_ufunc->uf_class->class_object_type;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
74 if (is_super)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
75 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
76 type_T *type = get_type_ptr(cctx->ctx_type_list);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
77
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
78 if (type != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
79 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
80 *type = *lvar->lv_type;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
81 lvar->lv_type = type;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
82 type->tt_flags |= TTFLAG_SUPER;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
83 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
84 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
85 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
86 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
87 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
88 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
89
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
90 // Find local in current function scope.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
91 for (idx = 0; idx < cctx->ctx_locals.ga_len; ++idx)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
92 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
93 lvp = ((lvar_T *)cctx->ctx_locals.ga_data) + idx;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
94 if (lvp->lv_name != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
95 && STRNCMP(name, lvp->lv_name, len) == 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
96 && STRLEN(lvp->lv_name) == len)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
97 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
98 if (lvar != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
99 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
100 *lvar = *lvp;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
101 lvar->lv_from_outer = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
102 // If the variable was declared inside a loop set
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
103 // lvar->lv_loop_idx and lvar->lv_loop_depth.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
104 get_loop_var_idx(cctx, idx, lvar);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
105 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
106 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
107 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
108 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
109
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
110 // Find local in outer function scope.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
111 if (cctx->ctx_outer != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
112 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
113 if (lookup_local(name, len, lvar, cctx->ctx_outer) == OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
114 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
115 if (lvar != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
116 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
117 cctx->ctx_outer_used = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
118 ++lvar->lv_from_outer;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
119 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
120 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
121 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
122 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
123
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
124 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
125 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
126
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
127 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
128 * Lookup an argument in the current function and an enclosing function.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
129 * Returns the argument index in "idxp"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
130 * Returns the argument type in "type"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
131 * Sets "gen_load_outer" to TRUE if found in outer scope.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
132 * Returns OK when found, FAIL otherwise.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
133 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
134 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
135 arg_exists(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
136 char_u *name,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
137 size_t len,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
138 int *idxp,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
139 type_T **type,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
140 int *gen_load_outer,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
141 cctx_T *cctx)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
142 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
143 int idx;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
144 char_u *va_name;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
145
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
146 if (len == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
147 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
148 for (idx = 0; idx < cctx->ctx_ufunc->uf_args_visible; ++idx)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
149 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
150 char_u *arg = FUNCARG(cctx->ctx_ufunc, idx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
151
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
152 if (STRNCMP(name, arg, len) == 0 && arg[len] == NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
153 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
154 if (idxp != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
155 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
156 // Arguments are located above the frame pointer. One further
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
157 // if there is a vararg argument
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
158 *idxp = idx - (cctx->ctx_ufunc->uf_args.ga_len
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
159 + STACK_FRAME_SIZE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
160 + (cctx->ctx_ufunc->uf_va_name != NULL ? -1 : 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
161
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
162 if (cctx->ctx_ufunc->uf_arg_types != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
163 *type = cctx->ctx_ufunc->uf_arg_types[idx];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
164 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
165 *type = &t_any;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
166 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
167 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
168 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
169 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
170
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
171 va_name = cctx->ctx_ufunc->uf_va_name;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
172 if (va_name != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
173 && STRNCMP(name, va_name, len) == 0 && va_name[len] == NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
174 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
175 if (idxp != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
176 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
177 // varargs is always the last argument
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
178 *idxp = -STACK_FRAME_SIZE - 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
179 *type = cctx->ctx_ufunc->uf_va_type;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
180 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
181 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
182 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
183
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
184 if (cctx->ctx_outer != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
185 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
186 // Lookup the name for an argument of the outer function.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
187 if (arg_exists(name, len, idxp, type, gen_load_outer, cctx->ctx_outer)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
188 == OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
189 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
190 if (gen_load_outer != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
191 ++*gen_load_outer;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
192 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
193 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
194 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
195
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
196 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
197 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
198
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
199 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
200 * Lookup a script-local variable in the current script, possibly defined in a
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
201 * block that contains the function "cctx->ctx_ufunc".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
202 * "cctx" is NULL at the script level, "cstack" is NULL in a function.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
203 * If "len" is <= 0 "name" must be NUL terminated.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
204 * Return NULL when not found.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
205 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
206 static sallvar_T *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
207 find_script_var(char_u *name, size_t len, cctx_T *cctx, cstack_T *cstack)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
208 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
209 scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
210 hashitem_T *hi;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
211 int cc;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
212 sallvar_T *sav;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
213 ufunc_T *ufunc;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
214
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
215 // Find the list of all script variables with the right name.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
216 if (len > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
217 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
218 cc = name[len];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
219 name[len] = NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
220 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
221 hi = hash_find(&si->sn_all_vars.dv_hashtab, name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
222 if (len > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
223 name[len] = cc;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
224 if (HASHITEM_EMPTY(hi))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
225 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
226
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
227 sav = HI2SAV(hi);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
228 if (sav->sav_block_id == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
229 // variable defined in the top script scope is always visible
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
230 return sav;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
231
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
232 if (cctx == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
233 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
234 if (cstack == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
235 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
236
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
237 // Not in a function scope, find variable with block ID equal to or
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
238 // smaller than the current block id. Use "cstack" to go up the block
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
239 // scopes.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
240 while (sav != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
241 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
242 int idx;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
243
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
244 for (idx = cstack->cs_idx; idx >= 0; --idx)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
245 if (cstack->cs_block_id[idx] == sav->sav_block_id)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
246 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
247 if (idx >= 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
248 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
249 sav = sav->sav_next;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
250 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
251 return sav;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
252 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
253
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
254 // Go over the variables with this name and find one that was visible
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
255 // from the function.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
256 ufunc = cctx->ctx_ufunc;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
257 while (sav != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
258 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
259 int idx;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
260
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
261 // Go over the blocks that this function was defined in. If the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
262 // variable block ID matches it was visible to the function.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
263 for (idx = 0; idx < ufunc->uf_block_depth; ++idx)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
264 if (ufunc->uf_block_ids[idx] == sav->sav_block_id)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
265 return sav;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
266 sav = sav->sav_next;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
267 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
268
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
269 // Not found, variable was not visible.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
270 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
271 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
272
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
273 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
274 * If "name" can be found in the current script set it's "block_id".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
275 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
276 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
277 update_script_var_block_id(char_u *name, int block_id)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
278 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
279 scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
280 hashitem_T *hi;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
281 sallvar_T *sav;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
282
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
283 hi = hash_find(&si->sn_all_vars.dv_hashtab, name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
284 if (HASHITEM_EMPTY(hi))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
285 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
286 sav = HI2SAV(hi);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
287 sav->sav_block_id = block_id;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
288 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
289
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
290 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
291 * Return TRUE if the script context is Vim9 script.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
292 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
293 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
294 script_is_vim9(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
295 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
296 return SCRIPT_ITEM(current_sctx.sc_sid)->sn_version == SCRIPT_VERSION_VIM9;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
297 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
298
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
299 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
300 * Lookup a variable (without s: prefix) in the current script.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
301 * "cctx" is NULL at the script level, "cstack" is NULL in a function.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
302 * Returns OK or FAIL.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
303 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
304 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
305 script_var_exists(char_u *name, size_t len, cctx_T *cctx, cstack_T *cstack)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
306 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
307 if (current_sctx.sc_sid <= 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
308 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
309 if (script_is_vim9())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
310 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
311 // Check script variables that were visible where the function was
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
312 // defined.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
313 if (find_script_var(name, len, cctx, cstack) != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
314 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
315 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
316 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
317 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
318 hashtab_T *ht = &SCRIPT_VARS(current_sctx.sc_sid);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
319 dictitem_T *di;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
320 int cc;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
321
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
322 // Check script variables that are currently visible
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
323 cc = name[len];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
324 name[len] = NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
325 di = find_var_in_ht(ht, 0, name, TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
326 name[len] = cc;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
327 if (di != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
328 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
329 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
330
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
331 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
332 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
333
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
334 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
335 * Return TRUE if "name" is a local variable, argument, script variable or
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
336 * imported. Also if "name" is "this" and in a class method.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
337 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
338 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
339 variable_exists(char_u *name, size_t len, cctx_T *cctx)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
340 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
341 return (cctx != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
342 && (lookup_local(name, len, NULL, cctx) == OK
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
343 || arg_exists(name, len, NULL, NULL, NULL, cctx) == OK
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
344 || (len == 4
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
345 && cctx->ctx_ufunc != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
346 && (cctx->ctx_ufunc->uf_flags & (FC_OBJECT|FC_NEW))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
347 && STRNCMP(name, "this", 4) == 0)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
348 || script_var_exists(name, len, cctx, NULL) == OK
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
349 || class_member_index(name, len, NULL, cctx) >= 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
350 || find_imported(name, len, FALSE) != NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
351 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
352
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
353 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
354 * Return TRUE if "name" is a local variable, argument, script variable,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
355 * imported or function. Or commands are being skipped, a declaration may have
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
356 * been skipped then.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
357 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
358 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
359 item_exists(char_u *name, size_t len, int cmd UNUSED, cctx_T *cctx)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
360 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
361 return variable_exists(name, len, cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
362 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
363
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
364 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
365 * Check if "p[len]" is already defined, either in script "import_sid" or in
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
366 * compilation context "cctx".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
367 * "cctx" is NULL at the script level, "cstack" is NULL in a function.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
368 * Does not check the global namespace.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
369 * If "is_arg" is TRUE the error message is for an argument name.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
370 * Return FAIL and give an error if it defined.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
371 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
372 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
373 check_defined(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
374 char_u *p,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
375 size_t len,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
376 cctx_T *cctx,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
377 cstack_T *cstack,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
378 int is_arg)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
379 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
380 int c = p[len];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
381 ufunc_T *ufunc = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
382
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
383 // underscore argument is OK
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
384 if (len == 1 && *p == '_')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
385 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
386
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
387 if (script_var_exists(p, len, cctx, cstack) == OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
388 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
389 if (is_arg)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
390 semsg(_(e_argument_already_declared_in_script_str), p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
391 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
392 semsg(_(e_variable_already_declared_in_script_str), p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
393 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
394 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
395
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
396 if (class_member_index(p, len, NULL, cctx) >= 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
397 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
398 if (is_arg)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
399 semsg(_(e_argument_already_declared_in_class_str), p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
400 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
401 semsg(_(e_variable_already_declared_in_class_str), p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
402 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
403 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
404
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
405 p[len] = NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
406 if ((cctx != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
407 && (lookup_local(p, len, NULL, cctx) == OK
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
408 || arg_exists(p, len, NULL, NULL, NULL, cctx) == OK))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
409 || find_imported(p, len, FALSE) != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
410 || (ufunc = find_func_even_dead(p, 0)) != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
411 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
412 // A local or script-local function can shadow a global function.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
413 if (ufunc == NULL || ((ufunc->uf_flags & FC_DEAD) == 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
414 && (!func_is_global(ufunc)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
415 || (p[0] == 'g' && p[1] == ':'))))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
416 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
417 if (is_arg)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
418 semsg(_(e_argument_name_shadows_existing_variable_str), p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
419 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
420 semsg(_(e_name_already_defined_str), p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
421 p[len] = c;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
422 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
423 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
424 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
425 p[len] = c;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
426 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
427 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
428
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
429
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
430 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
431 * Return TRUE if "actual" could be "expected" and a runtime typecheck is to be
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
432 * used. Return FALSE if the types will never match.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
433 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
434 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
435 use_typecheck(type_T *actual, type_T *expected)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
436 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
437 if (actual->tt_type == VAR_ANY
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
438 || actual->tt_type == VAR_UNKNOWN
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
439 || (actual->tt_type == VAR_FUNC
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
440 && (expected->tt_type == VAR_FUNC
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
441 || expected->tt_type == VAR_PARTIAL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
442 && (actual->tt_member == &t_any
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
443 || actual->tt_member == &t_unknown
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
444 || actual->tt_argcount < 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
445 && (actual->tt_member == &t_unknown ||
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
446 (actual->tt_member == &t_void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
447 == (expected->tt_member == &t_void))))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
448 return TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
449 if ((actual->tt_type == VAR_LIST || actual->tt_type == VAR_DICT)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
450 && actual->tt_type == expected->tt_type)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
451 // This takes care of a nested list or dict.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
452 return use_typecheck(actual->tt_member, expected->tt_member);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
453 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
454 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
455
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
456 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
457 * Check that
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
458 * - "actual" matches "expected" type or
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
459 * - "actual" is a type that can be "expected" type: add a runtime check; or
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
460 * - return FAIL.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
461 * If "actual_is_const" is TRUE then the type won't change at runtime, do not
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
462 * generate a TYPECHECK.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
463 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
464 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
465 need_type_where(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
466 type_T *actual,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
467 type_T *expected,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
468 int number_ok, // expect VAR_FLOAT but VAR_NUMBER is OK
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
469 int offset,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
470 where_T where,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
471 cctx_T *cctx,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
472 int silent,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
473 int actual_is_const)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
474 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
475 int ret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
476
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
477 if (expected == &t_bool && actual != &t_bool
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
478 && (actual->tt_flags & TTFLAG_BOOL_OK))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
479 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
480 // Using "0", "1" or the result of an expression with "&&" or "||" as a
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
481 // boolean is OK but requires a conversion.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
482 generate_2BOOL(cctx, FALSE, offset);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
483 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
484 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
485
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
486 ret = check_type_maybe(expected, actual, FALSE, where);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
487 if (ret == OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
488 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
489
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
490 // If actual a constant a runtime check makes no sense. If it's
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
491 // null_function it is OK.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
492 if (actual_is_const && ret == MAYBE && actual == &t_func_unknown)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
493 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
494
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
495 // If the actual type can be the expected type add a runtime check.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
496 if (!actual_is_const && ret == MAYBE && use_typecheck(actual, expected))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
497 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
498 generate_TYPECHECK(cctx, expected, number_ok, offset,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
499 where.wt_variable, where.wt_index);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
500 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
501 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
502
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
503 if (!silent)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
504 type_mismatch_where(expected, actual, where);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
505 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
506 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
507
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
508 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
509 need_type(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
510 type_T *actual,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
511 type_T *expected,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
512 int number_ok, // when expected is float number is also OK
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
513 int offset,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
514 int arg_idx,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
515 cctx_T *cctx,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
516 int silent,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
517 int actual_is_const)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
518 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
519 where_T where = WHERE_INIT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
520
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
521 where.wt_index = arg_idx;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
522 return need_type_where(actual, expected, number_ok, offset, where,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
523 cctx, silent, actual_is_const);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
524 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
525
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
526 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
527 * Set type of variable "lvar" to "type". If the variable is a constant then
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
528 * the type gets TTFLAG_CONST.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
529 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
530 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
531 set_var_type(lvar_T *lvar, type_T *type_arg, cctx_T *cctx)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
532 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
533 type_T *type = type_arg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
534
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
535 if (lvar->lv_const == ASSIGN_CONST && (type->tt_flags & TTFLAG_CONST) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
536 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
537 if (type->tt_flags & TTFLAG_STATIC)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
538 // entry in static_types[] is followed by const type
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
539 type = type + 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
540 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
541 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
542 type = copy_type(type, cctx->ctx_type_list);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
543 type->tt_flags |= TTFLAG_CONST;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
544 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
545 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
546 lvar->lv_type = type;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
547 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
548
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
549 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
550 * Reserve space for a local variable.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
551 * "assign" can be ASSIGN_VAR for :var, ASSIGN_CONST for :const and
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
552 * ASSIGN_FINAL for :final.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
553 * Return the variable or NULL if it failed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
554 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
555 lvar_T *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
556 reserve_local(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
557 cctx_T *cctx,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
558 char_u *name,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
559 size_t len,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
560 int assign,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
561 type_T *type)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
562 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
563 lvar_T *lvar;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
564 dfunc_T *dfunc;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
565
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
566 if (arg_exists(name, len, NULL, NULL, NULL, cctx) == OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
567 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
568 emsg_namelen(_(e_str_is_used_as_argument), name, (int)len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
569 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
570 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
571
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
572 if (GA_GROW_FAILS(&cctx->ctx_locals, 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
573 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
574 lvar = ((lvar_T *)cctx->ctx_locals.ga_data) + cctx->ctx_locals.ga_len++;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
575 CLEAR_POINTER(lvar);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
576
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
577 // Every local variable uses the next entry on the stack. We could re-use
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
578 // the last ones when leaving a scope, but then variables used in a closure
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
579 // might get overwritten. To keep things simple do not re-use stack
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
580 // entries. This is less efficient, but memory is cheap these days.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
581 dfunc = ((dfunc_T *)def_functions.ga_data) + cctx->ctx_ufunc->uf_dfunc_idx;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
582 lvar->lv_idx = dfunc->df_var_names.ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
583
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
584 lvar->lv_name = vim_strnsave(name, len == 0 ? STRLEN(name) : len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
585 lvar->lv_const = assign;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
586 if (type == &t_unknown || type == &t_any)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
587 // type not known yet, may be inferred from RHS
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
588 lvar->lv_type = type;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
589 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
590 // may use TTFLAG_CONST
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
591 set_var_type(lvar, type, cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
592
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
593 // Remember the name for debugging.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
594 if (GA_GROW_FAILS(&dfunc->df_var_names, 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
595 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
596 ((char_u **)dfunc->df_var_names.ga_data)[lvar->lv_idx] =
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
597 vim_strsave(lvar->lv_name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
598 ++dfunc->df_var_names.ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
599
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
600 return lvar;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
601 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
602
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
603 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
604 * If "check_writable" is ASSIGN_CONST give an error if the variable was
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
605 * defined with :final or :const, if "check_writable" is ASSIGN_FINAL give an
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
606 * error if the variable was defined with :const.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
607 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
608 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
609 check_item_writable(svar_T *sv, int check_writable, char_u *name)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
610 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
611 if ((check_writable == ASSIGN_CONST && sv->sv_const != 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
612 || (check_writable == ASSIGN_FINAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
613 && sv->sv_const == ASSIGN_CONST))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
614 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
615 semsg(_(e_cannot_change_readonly_variable_str), name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
616 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
617 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
618 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
619 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
620
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
621 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
622 * Find "name" in script-local items of script "sid".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
623 * Pass "check_writable" to check_item_writable().
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
624 * "cctx" is NULL at the script level, "cstack" is NULL in a function.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
625 * Returns the index in "sn_var_vals" if found.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
626 * If found but not in "sn_var_vals" returns -1.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
627 * If not found or the variable is not writable returns -2.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
628 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
629 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
630 get_script_item_idx(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
631 int sid,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
632 char_u *name,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
633 int check_writable,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
634 cctx_T *cctx,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
635 cstack_T *cstack)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
636 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
637 hashtab_T *ht;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
638 dictitem_T *di;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
639 scriptitem_T *si = SCRIPT_ITEM(sid);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
640 svar_T *sv;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
641 int idx;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
642
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
643 if (!SCRIPT_ID_VALID(sid))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
644 return -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
645 if (sid == current_sctx.sc_sid)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
646 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
647 sallvar_T *sav = find_script_var(name, 0, cctx, cstack);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
648
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
649 if (sav == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
650 return -2;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
651 idx = sav->sav_var_vals_idx;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
652 sv = ((svar_T *)si->sn_var_vals.ga_data) + idx;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
653 if (check_item_writable(sv, check_writable, name) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
654 return -2;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
655 return idx;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
656 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
657
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
658 // First look the name up in the hashtable.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
659 ht = &SCRIPT_VARS(sid);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
660 di = find_var_in_ht(ht, 0, name, TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
661 if (di == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
662 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
663 if (si->sn_autoload_prefix != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
664 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
665 hashitem_T *hi;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
666
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
667 // A variable exported from an autoload script is in the global
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
668 // variables, we can find it in the all_vars table.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
669 hi = hash_find(&si->sn_all_vars.dv_hashtab, name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
670 if (!HASHITEM_EMPTY(hi))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
671 return HI2SAV(hi)->sav_var_vals_idx;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
672 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
673 return -2;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
674 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
675
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
676 // Now find the svar_T index in sn_var_vals.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
677 for (idx = 0; idx < si->sn_var_vals.ga_len; ++idx)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
678 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
679 sv = ((svar_T *)si->sn_var_vals.ga_data) + idx;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
680 if (sv->sv_tv == &di->di_tv)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
681 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
682 if (check_item_writable(sv, check_writable, name) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
683 return -2;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
684 return idx;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
685 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
686 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
687 return -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
688 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
689
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
690 static imported_T *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
691 find_imported_in_script(char_u *name, size_t len, int sid)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
692 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
693 scriptitem_T *si;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
694 int idx;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
695
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
696 if (!SCRIPT_ID_VALID(sid))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
697 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
698 si = SCRIPT_ITEM(sid);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
699 for (idx = 0; idx < si->sn_imports.ga_len; ++idx)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
700 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
701 imported_T *import = ((imported_T *)si->sn_imports.ga_data) + idx;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
702
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
703 if (len == 0 ? STRCMP(name, import->imp_name) == 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
704 : STRLEN(import->imp_name) == len
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
705 && STRNCMP(name, import->imp_name, len) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
706 return import;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
707 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
708 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
709 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
710
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
711 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
712 * Find "name" in imported items of the current script.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
713 * If "len" is 0 use any length that works.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
714 * If "load" is TRUE and the script was not loaded yet, load it now.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
715 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
716 imported_T *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
717 find_imported(char_u *name, size_t len, int load)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
718 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
719 if (!SCRIPT_ID_VALID(current_sctx.sc_sid))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
720 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
721
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
722 // Skip over "s:" before "s:something" to find the import name.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
723 int off = name[0] == 's' && name[1] == ':' ? 2 : 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
724
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
725 imported_T *ret = find_imported_in_script(name + off, len - off,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
726 current_sctx.sc_sid);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
727 if (ret != NULL && load && (ret->imp_flags & IMP_FLAGS_AUTOLOAD))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
728 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
729 scid_T actual_sid = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
730 int save_emsg_off = emsg_off;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
731
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
732 // "emsg_off" will be set when evaluating an expression silently, but
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
733 // we do want to know about errors in a script. Also because it then
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
734 // aborts when an error is encountered.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
735 emsg_off = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
736
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
737 // script found before but not loaded yet
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
738 ret->imp_flags &= ~IMP_FLAGS_AUTOLOAD;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
739 (void)do_source(SCRIPT_ITEM(ret->imp_sid)->sn_name, FALSE,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
740 DOSO_NONE, &actual_sid);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
741 // If the script is a symlink it may be sourced with another name, may
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
742 // need to adjust the script ID for that.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
743 if (actual_sid != 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
744 ret->imp_sid = actual_sid;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
745
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
746 emsg_off = save_emsg_off;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
747 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
748 return ret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
749 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
750
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
751 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
752 * Called when checking for a following operator at "arg". When the rest of
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
753 * the line is empty or only a comment, peek the next line. If there is a next
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
754 * line return a pointer to it and set "nextp".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
755 * Otherwise skip over white space.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
756 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
757 char_u *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
758 may_peek_next_line(cctx_T *cctx, char_u *arg, char_u **nextp)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
759 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
760 char_u *p = skipwhite(arg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
761
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
762 *nextp = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
763 if (*p == NUL || (VIM_ISWHITE(*arg) && vim9_comment_start(p)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
764 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
765 *nextp = peek_next_line_from_context(cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
766 if (*nextp != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
767 return *nextp;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
768 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
769 return p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
770 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
771
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
772 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
773 * Return a pointer to the next line that isn't empty or only contains a
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
774 * comment. Skips over white space.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
775 * Returns NULL if there is none.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
776 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
777 char_u *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
778 peek_next_line_from_context(cctx_T *cctx)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
779 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
780 int lnum = cctx->ctx_lnum;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
781
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
782 while (++lnum < cctx->ctx_ufunc->uf_lines.ga_len)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
783 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
784 char_u *line = ((char_u **)cctx->ctx_ufunc->uf_lines.ga_data)[lnum];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
785 char_u *p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
786
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
787 // ignore NULLs inserted for continuation lines
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
788 if (line != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
789 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
790 p = skipwhite(line);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
791 if (vim9_bad_comment(p))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
792 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
793 if (*p != NUL && !vim9_comment_start(p))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
794 return p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
795 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
796 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
797 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
798 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
799
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
800 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
801 * Get the next line of the function from "cctx".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
802 * Skips over empty lines. Skips over comment lines if "skip_comment" is TRUE.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
803 * Returns NULL when at the end.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
804 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
805 char_u *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
806 next_line_from_context(cctx_T *cctx, int skip_comment)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
807 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
808 char_u *line;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
809
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
810 do
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
811 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
812 ++cctx->ctx_lnum;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
813 if (cctx->ctx_lnum >= cctx->ctx_ufunc->uf_lines.ga_len)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
814 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
815 line = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
816 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
817 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
818 line = ((char_u **)cctx->ctx_ufunc->uf_lines.ga_data)[cctx->ctx_lnum];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
819 cctx->ctx_line_start = line;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
820 SOURCING_LNUM = cctx->ctx_lnum + 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
821 } while (line == NULL || *skipwhite(line) == NUL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
822 || (skip_comment && vim9_comment_start(skipwhite(line))));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
823 return line;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
824 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
825
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
826 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
827 * Skip over white space at "whitep" and assign to "*arg".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
828 * If "*arg" is at the end of the line, advance to the next line.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
829 * Also when "whitep" points to white space and "*arg" is on a "#".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
830 * Return FAIL if beyond the last line, "*arg" is unmodified then.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
831 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
832 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
833 may_get_next_line(char_u *whitep, char_u **arg, cctx_T *cctx)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
834 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
835 *arg = skipwhite(whitep);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
836 if (vim9_bad_comment(*arg))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
837 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
838 if (**arg == NUL || (VIM_ISWHITE(*whitep) && vim9_comment_start(*arg)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
839 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
840 char_u *next = next_line_from_context(cctx, TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
841
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
842 if (next == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
843 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
844 *arg = skipwhite(next);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
845 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
846 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
847 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
848
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
849 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
850 * Idem, and give an error when failed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
851 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
852 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
853 may_get_next_line_error(char_u *whitep, char_u **arg, cctx_T *cctx)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
854 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
855 if (may_get_next_line(whitep, arg, cctx) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
856 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
857 SOURCING_LNUM = cctx->ctx_lnum + 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
858 emsg(_(e_line_incomplete));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
859 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
860 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
861 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
862 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
863
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
864 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
865 * Get a line from the compilation context, compatible with exarg_T getline().
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
866 * Return a pointer to the line in allocated memory.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
867 * Return NULL for end-of-file or some error.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
868 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
869 static char_u *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
870 exarg_getline(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
871 int c UNUSED,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
872 void *cookie,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
873 int indent UNUSED,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
874 getline_opt_T options UNUSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
875 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
876 cctx_T *cctx = (cctx_T *)cookie;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
877 char_u *p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
878
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
879 for (;;)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
880 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
881 if (cctx->ctx_lnum >= cctx->ctx_ufunc->uf_lines.ga_len - 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
882 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
883 ++cctx->ctx_lnum;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
884 p = ((char_u **)cctx->ctx_ufunc->uf_lines.ga_data)[cctx->ctx_lnum];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
885 // Comment lines result in NULL pointers, skip them.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
886 if (p != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
887 return vim_strsave(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
888 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
889 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
890
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
891 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
892 fill_exarg_from_cctx(exarg_T *eap, cctx_T *cctx)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
893 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
894 eap->getline = exarg_getline;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
895 eap->cookie = cctx;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
896 eap->skip = cctx->ctx_skip == SKIP_YES;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
897 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
898
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
899 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
900 * Return TRUE if "ufunc" should be compiled, taking into account whether
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
901 * "profile" indicates profiling is to be done.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
902 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
903 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
904 func_needs_compiling(ufunc_T *ufunc, compiletype_T compile_type)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
905 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
906 switch (ufunc->uf_def_status)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
907 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
908 case UF_TO_BE_COMPILED:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
909 return TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
910
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
911 case UF_COMPILED:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
912 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
913 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
914 + ufunc->uf_dfunc_idx;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
915
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
916 switch (compile_type)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
917 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
918 case CT_PROFILE:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
919 #ifdef FEAT_PROFILE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
920 return dfunc->df_instr_prof == NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
921 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
922 case CT_NONE:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
923 return dfunc->df_instr == NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
924 case CT_DEBUG:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
925 return dfunc->df_instr_debug == NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
926 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
927 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
928
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
929 case UF_NOT_COMPILED:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
930 case UF_COMPILE_ERROR:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
931 case UF_COMPILING:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
932 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
933 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
934 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
935 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
936
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
937 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
938 * Compile a nested :def command.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
939 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
940 static char_u *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
941 compile_nested_function(exarg_T *eap, cctx_T *cctx, garray_T *lines_to_free)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
942 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
943 int is_global = *eap->arg == 'g' && eap->arg[1] == ':';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
944 char_u *name_start = eap->arg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
945 char_u *name_end = to_name_end(eap->arg, TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
946 int off;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
947 char_u *func_name;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
948 char_u *lambda_name;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
949 ufunc_T *ufunc;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
950 int r = FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
951 compiletype_T compile_type;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
952 isn_T *funcref_isn = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
953 lvar_T *lvar = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
954
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
955 if (eap->forceit)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
956 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
957 emsg(_(e_cannot_use_bang_with_nested_def));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
958 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
959 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
960
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
961 if (*name_start == '/')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
962 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
963 name_end = skip_regexp(name_start + 1, '/', TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
964 if (*name_end == '/')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
965 ++name_end;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
966 set_nextcmd(eap, name_end);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
967 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
968 if (name_end == name_start || *skipwhite(name_end) != '(')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
969 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
970 if (!ends_excmd2(name_start, name_end))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
971 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
972 if (*skipwhite(name_end) == '.')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
973 semsg(_(e_cannot_define_dict_func_in_vim9_script_str),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
974 eap->cmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
975 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
976 semsg(_(e_invalid_command_str), eap->cmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
977 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
978 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
979
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
980 // "def" or "def Name": list functions
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
981 if (generate_DEF(cctx, name_start, name_end - name_start) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
982 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
983 return eap->nextcmd == NULL ? (char_u *)"" : eap->nextcmd;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
984 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
985
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
986 // Only g:Func() can use a namespace.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
987 if (name_start[1] == ':' && !is_global)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
988 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
989 semsg(_(e_namespace_not_supported_str), name_start);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
990 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
991 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
992 if (cctx->ctx_skip != SKIP_YES
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
993 && check_defined(name_start, name_end - name_start, cctx,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
994 NULL, FALSE) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
995 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
996 if (!ASCII_ISUPPER(is_global ? name_start[2] : name_start[0]))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
997 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
998 semsg(_(e_function_name_must_start_with_capital_str), name_start);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
999 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1000 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1001
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1002 eap->arg = name_end;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1003 fill_exarg_from_cctx(eap, cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1004
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1005 eap->forceit = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1006 // We use the special <Lamba>99 name, but it's not really a lambda.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1007 lambda_name = vim_strsave(get_lambda_name());
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1008 if (lambda_name == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1009 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1010
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1011 // This may free the current line, make a copy of the name.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1012 off = is_global ? 2 : 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1013 func_name = vim_strnsave(name_start + off, name_end - name_start - off);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1014 if (func_name == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1015 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1016 r = FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1017 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1018 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1019
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1020 // Make sure "KeyTyped" is not set, it may cause indent to be written.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1021 int save_KeyTyped = KeyTyped;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1022 KeyTyped = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1023
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1024 ufunc = define_function(eap, lambda_name, lines_to_free, 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1025
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1026 KeyTyped = save_KeyTyped;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1027
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1028 if (ufunc == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1029 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1030 r = eap->skip ? OK : FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1031 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1032 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1033 if (eap->nextcmd != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1034 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1035 semsg(_(e_text_found_after_str_str),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1036 eap->cmdidx == CMD_def ? "enddef" : "endfunction", eap->nextcmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1037 r = FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1038 func_ptr_unref(ufunc);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1039 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1040 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1041
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1042 // copy over the block scope IDs before compiling
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1043 if (!is_global && cctx->ctx_ufunc->uf_block_depth > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1044 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1045 int block_depth = cctx->ctx_ufunc->uf_block_depth;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1046
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1047 ufunc->uf_block_ids = ALLOC_MULT(int, block_depth);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1048 if (ufunc->uf_block_ids != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1049 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1050 mch_memmove(ufunc->uf_block_ids, cctx->ctx_ufunc->uf_block_ids,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1051 sizeof(int) * block_depth);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1052 ufunc->uf_block_depth = block_depth;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1053 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1054 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1055
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1056 // Define the funcref before compiling, so that it is found by any
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1057 // recursive call.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1058 if (is_global)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1059 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1060 r = generate_NEWFUNC(cctx, lambda_name, func_name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1061 func_name = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1062 lambda_name = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1063 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1064 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1065 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1066 // Define a local variable for the function reference.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1067 lvar = reserve_local(cctx, func_name, name_end - name_start,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1068 ASSIGN_CONST, ufunc->uf_func_type);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1069 if (lvar == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1070 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1071 if (generate_FUNCREF(cctx, ufunc, NULL, 0, &funcref_isn) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1072 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1073 r = generate_STORE(cctx, ISN_STORE, lvar->lv_idx, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1074 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1075
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1076 compile_type = get_compile_type(ufunc);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1077 #ifdef FEAT_PROFILE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1078 // If the outer function is profiled, also compile the nested function for
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1079 // profiling.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1080 if (cctx->ctx_compile_type == CT_PROFILE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1081 compile_type = CT_PROFILE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1082 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1083 if (func_needs_compiling(ufunc, compile_type)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1084 && compile_def_function(ufunc, TRUE, compile_type, cctx) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1085 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1086 func_ptr_unref(ufunc);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1087 if (lvar != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1088 // Now the local variable can't be used.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1089 *lvar->lv_name = '/'; // impossible value
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1090 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1091 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1092
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1093 #ifdef FEAT_PROFILE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1094 // When the outer function is compiled for profiling, the nested function
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1095 // may be called without profiling. Compile it here in the right context.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1096 if (compile_type == CT_PROFILE && func_needs_compiling(ufunc, CT_NONE))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1097 compile_def_function(ufunc, FALSE, CT_NONE, cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1098 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1099
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1100 // If a FUNCREF instruction was generated, set the index after compiling.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1101 if (funcref_isn != NULL && ufunc->uf_def_status == UF_COMPILED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1102 funcref_isn->isn_arg.funcref.fr_dfunc_idx = ufunc->uf_dfunc_idx;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1103
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1104 theend:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1105 vim_free(lambda_name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1106 vim_free(func_name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1107 return r == FAIL ? NULL : (char_u *)"";
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1108 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1109
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1110 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1111 * Compile one Vim expression {expr} in string "p".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1112 * "p" points to the opening "{".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1113 * Return a pointer to the character after "}", NULL for an error.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1114 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1115 char_u *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1116 compile_one_expr_in_str(char_u *p, cctx_T *cctx)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1117 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1118 char_u *block_start;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1119 char_u *block_end;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1120
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1121 // Skip the opening {.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1122 block_start = skipwhite(p + 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1123 block_end = block_start;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1124 if (*block_start != NUL && skip_expr(&block_end, NULL) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1125 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1126 block_end = skipwhite(block_end);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1127 // The block must be closed by a }.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1128 if (*block_end != '}')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1129 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1130 semsg(_(e_missing_close_curly_str), p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1131 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1132 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1133 if (compile_expr0(&block_start, cctx) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1134 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1135 may_generate_2STRING(-1, TRUE, cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1136
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1137 return block_end + 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1138 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1139
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1140 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1141 * Compile a string "str" (either containing a literal string or a mix of
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1142 * literal strings and Vim expressions of the form `{expr}`). This is used
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1143 * when compiling a heredoc assignment to a variable or an interpolated string
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1144 * in a Vim9 def function. Vim9 instructions are generated to push strings,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1145 * evaluate expressions, concatenate them and create a list of lines. When
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1146 * "evalstr" is TRUE, Vim expressions in "str" are evaluated.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1147 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1148 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1149 compile_all_expr_in_str(char_u *str, int evalstr, cctx_T *cctx)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1150 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1151 char_u *p = str;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1152 char_u *val;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1153 int count = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1154
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1155 if (cctx->ctx_skip == SKIP_YES)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1156 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1157
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1158 if (!evalstr || *str == NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1159 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1160 // Literal string, possibly empty.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1161 val = *str != NUL ? vim_strsave(str) : NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1162 return generate_PUSHS(cctx, &val);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1163 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1164
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1165 // Push all the string pieces to the stack, followed by a ISN_CONCAT.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1166 while (*p != NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1167 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1168 char_u *lit_start;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1169 int escaped_brace = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1170
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1171 // Look for a block start.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1172 lit_start = p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1173 while (*p != '{' && *p != '}' && *p != NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1174 ++p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1175
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1176 if (*p != NUL && *p == p[1])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1177 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1178 // Escaped brace, unescape and continue.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1179 // Include the brace in the literal string.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1180 ++p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1181 escaped_brace = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1182 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1183 else if (*p == '}')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1184 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1185 semsg(_(e_stray_closing_curly_str), str);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1186 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1187 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1188
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1189 // Append the literal part.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1190 if (p != lit_start)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1191 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1192 val = vim_strnsave(lit_start, (size_t)(p - lit_start));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1193 if (generate_PUSHS(cctx, &val) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1194 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1195 ++count;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1196 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1197
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1198 if (*p == NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1199 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1200
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1201 if (escaped_brace)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1202 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1203 // Skip the second brace.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1204 ++p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1205 continue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1206 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1207
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1208 p = compile_one_expr_in_str(p, cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1209 if (p == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1210 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1211 ++count;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1212 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1213
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1214 // Small optimization, if there's only a single piece skip the ISN_CONCAT.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1215 if (count > 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1216 return generate_CONCAT(cctx, count);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1217
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1218 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1219 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1220
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1221 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1222 * Return the length of an assignment operator, or zero if there isn't one.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1223 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1224 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1225 assignment_len(char_u *p, int *heredoc)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1226 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1227 if (*p == '=')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1228 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1229 if (p[1] == '<' && p[2] == '<')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1230 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1231 *heredoc = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1232 return 3;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1233 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1234 return 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1235 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1236 if (vim_strchr((char_u *)"+-*/%", *p) != NULL && p[1] == '=')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1237 return 2;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1238 if (STRNCMP(p, "..=", 3) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1239 return 3;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1240 return 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1241 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1242
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1243 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1244 * Generate the load instruction for "name".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1245 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1246 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1247 generate_loadvar(cctx_T *cctx, lhs_T *lhs)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1248 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1249 char_u *name = lhs->lhs_name;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1250 type_T *type = lhs->lhs_type;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1251
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1252 switch (lhs->lhs_dest)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1253 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1254 case dest_option:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1255 case dest_func_option:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1256 generate_LOAD(cctx, ISN_LOADOPT, 0, name, type);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1257 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1258 case dest_global:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1259 if (vim_strchr(name, AUTOLOAD_CHAR) == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1260 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1261 if (name[2] == NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1262 generate_instr_type(cctx, ISN_LOADGDICT, &t_dict_any);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1263 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1264 generate_LOAD(cctx, ISN_LOADG, 0, name + 2, type);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1265 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1266 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1267 generate_LOAD(cctx, ISN_LOADAUTO, 0, name, type);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1268 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1269 case dest_buffer:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1270 generate_LOAD(cctx, ISN_LOADB, 0, name + 2, type);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1271 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1272 case dest_window:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1273 generate_LOAD(cctx, ISN_LOADW, 0, name + 2, type);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1274 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1275 case dest_tab:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1276 generate_LOAD(cctx, ISN_LOADT, 0, name + 2, type);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1277 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1278 case dest_script:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1279 compile_load_scriptvar(cctx,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1280 name + (name[1] == ':' ? 2 : 0), NULL, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1281 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1282 case dest_env:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1283 // Include $ in the name here
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1284 generate_LOAD(cctx, ISN_LOADENV, 0, name, type);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1285 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1286 case dest_reg:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1287 generate_LOAD(cctx, ISN_LOADREG, name[1], NULL, &t_string);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1288 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1289 case dest_vimvar:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1290 generate_LOADV(cctx, name + 2);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1291 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1292 case dest_local:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1293 if (cctx->ctx_skip != SKIP_YES)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1294 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1295 lvar_T *lvar = lhs->lhs_lvar;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1296 if (lvar->lv_from_outer > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1297 generate_LOADOUTER(cctx, lvar->lv_idx, lvar->lv_from_outer,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1298 lvar->lv_loop_depth, lvar->lv_loop_idx, type);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1299 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1300 generate_LOAD(cctx, ISN_LOAD, lvar->lv_idx, NULL, type);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1301 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1302 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1303 case dest_class_member:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1304 generate_CLASSMEMBER(cctx, TRUE, lhs->lhs_class,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1305 lhs->lhs_classmember_idx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1306 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1307 case dest_expr:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1308 // list or dict value should already be on the stack.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1309 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1310 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1311 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1312
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1313 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1314 * Skip over "[expr]" or ".member".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1315 * Does not check for any errors.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1316 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1317 static char_u *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1318 skip_index(char_u *start)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1319 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1320 char_u *p = start;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1321
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1322 if (*p == '[')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1323 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1324 p = skipwhite(p + 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1325 (void)skip_expr(&p, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1326 p = skipwhite(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1327 if (*p == ']')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1328 return p + 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1329 return p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1330 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1331 // if (*p == '.')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1332 return to_name_end(p + 1, TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1333 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1334
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1335 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1336 vim9_declare_error(char_u *name)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1337 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1338 char *scope = "";
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1339
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1340 switch (*name)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1341 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1342 case 'g': scope = _("global"); break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1343 case 'b': scope = _("buffer"); break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1344 case 'w': scope = _("window"); break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1345 case 't': scope = _("tab"); break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1346 case 'v': scope = "v:"; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1347 case '$': semsg(_(e_cannot_declare_an_environment_variable_str), name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1348 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1349 case '&': semsg(_(e_cannot_declare_an_option_str), name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1350 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1351 case '@': semsg(_(e_cannot_declare_a_register_str), name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1352 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1353 default: return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1354 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1355 semsg(_(e_cannot_declare_a_scope_variable_str), scope, name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1356 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1357
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1358 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1359 * Return TRUE if "name" is a valid register to use.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1360 * Return FALSE and give an error message if not.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1361 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1362 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1363 valid_dest_reg(int name)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1364 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1365 if ((name == '@' || valid_yank_reg(name, FALSE)) && name != '.')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1366 return TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1367 emsg_invreg(name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1368 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1369 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1370
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1371 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1372 * For one assignment figure out the type of destination. Return it in "dest".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1373 * When not recognized "dest" is not set.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1374 * For an option "option_scope" is set.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1375 * For a v:var "vimvaridx" is set.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1376 * "type" is set to the destination type if known, unchanted otherwise.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1377 * Return FAIL if an error message was given.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1378 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1379 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1380 get_var_dest(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1381 char_u *name,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1382 assign_dest_T *dest,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1383 cmdidx_T cmdidx,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1384 int *option_scope,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1385 int *vimvaridx,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1386 type_T **type,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1387 cctx_T *cctx)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1388 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1389 char_u *p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1390
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1391 if (*name == '&')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1392 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1393 int cc;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1394 long numval;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1395 getoption_T opt_type;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1396 int opt_p_flags;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1397
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1398 *dest = dest_option;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1399 if (cmdidx == CMD_final || cmdidx == CMD_const)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1400 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1401 emsg(_(e_cannot_lock_option));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1402 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1403 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1404 p = name;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1405 p = find_option_end(&p, option_scope);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1406 if (p == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1407 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1408 // cannot happen?
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1409 emsg(_(e_unexpected_characters_in_assignment));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1410 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1411 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1412 cc = *p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1413 *p = NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1414 opt_type = get_option_value(skip_option_env_lead(name),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1415 &numval, NULL, &opt_p_flags, *option_scope);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1416 *p = cc;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1417 switch (opt_type)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1418 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1419 case gov_unknown:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1420 semsg(_(e_unknown_option_str), name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1421 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1422 case gov_string:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1423 case gov_hidden_string:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1424 if (opt_p_flags & P_FUNC)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1425 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1426 // might be a Funcref, check the type later
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1427 *type = &t_any;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1428 *dest = dest_func_option;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1429 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1430 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1431 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1432 *type = &t_string;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1433 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1434 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1435 case gov_bool:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1436 case gov_hidden_bool:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1437 *type = &t_bool;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1438 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1439 case gov_number:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1440 case gov_hidden_number:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1441 *type = &t_number;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1442 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1443 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1444 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1445 else if (*name == '$')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1446 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1447 *dest = dest_env;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1448 *type = &t_string;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1449 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1450 else if (*name == '@')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1451 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1452 if (!valid_dest_reg(name[1]))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1453 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1454 *dest = dest_reg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1455 *type = name[1] == '#' ? &t_number_or_string : &t_string;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1456 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1457 else if (STRNCMP(name, "g:", 2) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1458 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1459 *dest = dest_global;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1460 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1461 else if (STRNCMP(name, "b:", 2) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1462 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1463 *dest = dest_buffer;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1464 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1465 else if (STRNCMP(name, "w:", 2) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1466 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1467 *dest = dest_window;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1468 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1469 else if (STRNCMP(name, "t:", 2) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1470 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1471 *dest = dest_tab;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1472 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1473 else if (STRNCMP(name, "v:", 2) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1474 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1475 typval_T *vtv;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1476 int di_flags;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1477
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1478 *vimvaridx = find_vim_var(name + 2, &di_flags);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1479 if (*vimvaridx < 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1480 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1481 semsg(_(e_variable_not_found_str), name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1482 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1483 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1484 // We use the current value of "sandbox" here, is that OK?
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1485 if (var_check_ro(di_flags, name, FALSE))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1486 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1487 *dest = dest_vimvar;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1488 vtv = get_vim_var_tv(*vimvaridx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1489 *type = typval2type_vimvar(vtv, cctx->ctx_type_list);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1490 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1491 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1492 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1493
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1494 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1495 is_decl_command(cmdidx_T cmdidx)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1496 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1497 return cmdidx == CMD_let || cmdidx == CMD_var
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1498 || cmdidx == CMD_final || cmdidx == CMD_const;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1499 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1500
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1501 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1502 * Figure out the LHS type and other properties for an assignment or one item
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1503 * of ":unlet" with an index.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1504 * Returns OK or FAIL.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1505 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1506 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1507 compile_lhs(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1508 char_u *var_start,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1509 lhs_T *lhs,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1510 cmdidx_T cmdidx,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1511 int heredoc,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1512 int has_cmd, // "var" before "var_start"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1513 int oplen,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1514 cctx_T *cctx)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1515 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1516 char_u *var_end;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1517 int is_decl = is_decl_command(cmdidx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1518
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1519 CLEAR_POINTER(lhs);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1520 lhs->lhs_dest = dest_local;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1521 lhs->lhs_vimvaridx = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1522 lhs->lhs_scriptvar_idx = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1523 lhs->lhs_member_idx = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1524
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1525 // "dest_end" is the end of the destination, including "[expr]" or
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1526 // ".name".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1527 // "var_end" is the end of the variable/option/etc. name.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1528 lhs->lhs_dest_end = skip_var_one(var_start, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1529 if (*var_start == '@')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1530 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1531 if (!valid_dest_reg(var_start[1]))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1532 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1533 var_end = var_start + 2;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1534 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1535 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1536 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1537 // skip over the leading "&", "&l:", "&g:" and "$"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1538 var_end = skip_option_env_lead(var_start);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1539 var_end = to_name_end(var_end, TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1540 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1541
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1542 // "a: type" is declaring variable "a" with a type, not dict "a:".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1543 if (is_decl && lhs->lhs_dest_end == var_start + 2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1544 && lhs->lhs_dest_end[-1] == ':')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1545 --lhs->lhs_dest_end;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1546 if (is_decl && var_end == var_start + 2 && var_end[-1] == ':')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1547 --var_end;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1548 lhs->lhs_end = lhs->lhs_dest_end;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1549
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1550 // compute the length of the destination without "[expr]" or ".name"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1551 lhs->lhs_varlen = var_end - var_start;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1552 lhs->lhs_varlen_total = lhs->lhs_varlen;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1553 lhs->lhs_name = vim_strnsave(var_start, lhs->lhs_varlen);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1554 if (lhs->lhs_name == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1555 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1556
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1557 if (lhs->lhs_dest_end > var_start + lhs->lhs_varlen)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1558 // Something follows after the variable: "var[idx]" or "var.key".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1559 lhs->lhs_has_index = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1560
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1561 if (heredoc)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1562 lhs->lhs_type = &t_list_string;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1563 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1564 lhs->lhs_type = &t_any;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1565
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1566 if (cctx->ctx_skip != SKIP_YES)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1567 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1568 int declare_error = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1569
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1570 if (get_var_dest(lhs->lhs_name, &lhs->lhs_dest, cmdidx,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1571 &lhs->lhs_opt_flags, &lhs->lhs_vimvaridx,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1572 &lhs->lhs_type, cctx) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1573 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1574 if (lhs->lhs_dest != dest_local
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1575 && cmdidx != CMD_const && cmdidx != CMD_final)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1576 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1577 // Specific kind of variable recognized.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1578 declare_error = is_decl;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1579 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1580 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1581 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1582 // No specific kind of variable recognized, just a name.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1583 if (check_reserved_name(lhs->lhs_name, lhs->lhs_has_index
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1584 && *var_end == '.') == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1585 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1586
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1587 if (lookup_local(var_start, lhs->lhs_varlen,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1588 &lhs->lhs_local_lvar, cctx) == OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1589 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1590 lhs->lhs_lvar = &lhs->lhs_local_lvar;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1591 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1592 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1593 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1594 CLEAR_FIELD(lhs->lhs_arg_lvar);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1595 if (arg_exists(var_start, lhs->lhs_varlen,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1596 &lhs->lhs_arg_lvar.lv_idx, &lhs->lhs_arg_lvar.lv_type,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1597 &lhs->lhs_arg_lvar.lv_from_outer, cctx) == OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1598 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1599 if (is_decl)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1600 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1601 semsg(_(e_str_is_used_as_argument), lhs->lhs_name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1602 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1603 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1604 lhs->lhs_lvar = &lhs->lhs_arg_lvar;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1605 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1606 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1607
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1608 if (lhs->lhs_lvar != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1609 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1610 if (is_decl)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1611 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1612 semsg(_(e_variable_already_declared_str), lhs->lhs_name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1613 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1614 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1615 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1616 else if ((lhs->lhs_classmember_idx = class_member_index(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1617 var_start, lhs->lhs_varlen, NULL, cctx)) >= 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1618 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1619 if (is_decl)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1620 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1621 semsg(_(e_variable_already_declared_in_class_str),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1622 lhs->lhs_name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1623 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1624 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1625 lhs->lhs_dest = dest_class_member;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1626 lhs->lhs_class = cctx->ctx_ufunc->uf_class;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1627 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1628 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1629 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1630 int script_namespace = lhs->lhs_varlen > 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1631 && STRNCMP(var_start, "s:", 2) == 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1632 int script_var = (script_namespace
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1633 ? script_var_exists(var_start + 2, lhs->lhs_varlen - 2,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1634 cctx, NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1635 : script_var_exists(var_start, lhs->lhs_varlen,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1636 cctx, NULL)) == OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1637 imported_T *import =
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1638 find_imported(var_start, lhs->lhs_varlen, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1639
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1640 if (script_namespace || script_var || import != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1641 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1642 char_u *rawname = lhs->lhs_name
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1643 + (lhs->lhs_name[1] == ':' ? 2 : 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1644
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1645 if (script_namespace && current_script_is_vim9())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1646 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1647 semsg(_(e_cannot_use_s_colon_in_vim9_script_str),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1648 var_start);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1649 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1650 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1651 if (is_decl)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1652 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1653 if (script_namespace)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1654 semsg(_(e_cannot_declare_script_variable_in_function_str),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1655 lhs->lhs_name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1656 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1657 semsg(_(e_variable_already_declared_in_script_str),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1658 lhs->lhs_name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1659 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1660 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1661 else if (cctx->ctx_ufunc->uf_script_ctx_version
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1662 == SCRIPT_VERSION_VIM9
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1663 && script_namespace
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1664 && !script_var && import == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1665 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1666 semsg(_(e_unknown_variable_str), lhs->lhs_name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1667 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1668 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1669
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1670 lhs->lhs_dest = dest_script;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1671
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1672 // existing script-local variables should have a type
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1673 lhs->lhs_scriptvar_sid = current_sctx.sc_sid;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1674 if (import != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1675 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1676 char_u *dot = vim_strchr(var_start, '.');
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1677 char_u *p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1678
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1679 // for an import the name is what comes after the dot
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1680 if (dot == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1681 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1682 semsg(_(e_no_dot_after_imported_name_str),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1683 var_start);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1684 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1685 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1686 p = skipwhite(dot + 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1687 var_end = to_name_end(p, TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1688 if (var_end == p)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1689 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1690 semsg(_(e_missing_name_after_imported_name_str),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1691 var_start);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1692 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1693 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1694 vim_free(lhs->lhs_name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1695 lhs->lhs_varlen = var_end - p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1696 lhs->lhs_name = vim_strnsave(p, lhs->lhs_varlen);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1697 if (lhs->lhs_name == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1698 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1699 rawname = lhs->lhs_name;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1700 lhs->lhs_scriptvar_sid = import->imp_sid;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1701 // TODO: where do we check this name is exported?
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1702
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1703 // Check if something follows: "exp.var[idx]" or
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1704 // "exp.var.key".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1705 lhs->lhs_has_index = lhs->lhs_dest_end
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1706 > skipwhite(var_end);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1707 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1708 if (SCRIPT_ID_VALID(lhs->lhs_scriptvar_sid))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1709 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1710 // Check writable only when no index follows.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1711 lhs->lhs_scriptvar_idx = get_script_item_idx(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1712 lhs->lhs_scriptvar_sid, rawname,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1713 lhs->lhs_has_index ? ASSIGN_FINAL : ASSIGN_CONST,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1714 cctx, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1715 if (lhs->lhs_scriptvar_idx >= 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1716 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1717 scriptitem_T *si = SCRIPT_ITEM(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1718 lhs->lhs_scriptvar_sid);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1719 svar_T *sv =
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1720 ((svar_T *)si->sn_var_vals.ga_data)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1721 + lhs->lhs_scriptvar_idx;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1722 lhs->lhs_type = sv->sv_type;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1723 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1724 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1725 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1726 else if (check_defined(var_start, lhs->lhs_varlen, cctx,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1727 NULL, FALSE) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1728 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1729 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1730 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1731
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1732 if (declare_error)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1733 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1734 vim9_declare_error(lhs->lhs_name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1735 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1736 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1737 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1738
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1739 // handle "a:name" as a name, not index "name" in "a"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1740 if (lhs->lhs_varlen > 1 || var_start[lhs->lhs_varlen] != ':')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1741 var_end = lhs->lhs_dest_end;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1742
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1743 if (lhs->lhs_dest != dest_option && lhs->lhs_dest != dest_func_option)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1744 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1745 if (is_decl && *skipwhite(var_end) == ':')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1746 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1747 char_u *p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1748
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1749 // parse optional type: "let var: type = expr"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1750 if (VIM_ISWHITE(*var_end))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1751 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1752 semsg(_(e_no_white_space_allowed_before_colon_str), var_end);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1753 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1754 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1755 if (!VIM_ISWHITE(var_end[1]))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1756 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1757 semsg(_(e_white_space_required_after_str_str), ":", var_end);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1758 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1759 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1760 p = skipwhite(var_end + 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1761 lhs->lhs_type = parse_type(&p, cctx->ctx_type_list, TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1762 if (lhs->lhs_type == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1763 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1764 lhs->lhs_has_type = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1765 lhs->lhs_end = p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1766 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1767 else if (lhs->lhs_lvar != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1768 lhs->lhs_type = lhs->lhs_lvar->lv_type;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1769 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1770
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1771 if (oplen == 3 && !heredoc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1772 && lhs->lhs_dest != dest_global
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1773 && !lhs->lhs_has_index
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1774 && lhs->lhs_type->tt_type != VAR_STRING
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1775 && lhs->lhs_type->tt_type != VAR_ANY)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1776 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1777 emsg(_(e_can_only_concatenate_to_string));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1778 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1779 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1780
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1781 if (lhs->lhs_lvar == NULL && lhs->lhs_dest == dest_local
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1782 && cctx->ctx_skip != SKIP_YES)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1783 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1784 if (oplen > 1 && !heredoc)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1785 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1786 // +=, /=, etc. require an existing variable
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1787 semsg(_(e_cannot_use_operator_on_new_variable_str), lhs->lhs_name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1788 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1789 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1790 if (!is_decl || (lhs->lhs_has_index && !has_cmd
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1791 && cctx->ctx_skip != SKIP_YES))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1792 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1793 semsg(_(e_unknown_variable_str), lhs->lhs_name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1794 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1795 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1796
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1797 // Check the name is valid for a funcref.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1798 if ((lhs->lhs_type->tt_type == VAR_FUNC
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1799 || lhs->lhs_type->tt_type == VAR_PARTIAL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1800 && var_wrong_func_name(lhs->lhs_name, TRUE))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1801 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1802
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1803 // New local variable.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1804 int assign = cmdidx == CMD_final ? ASSIGN_FINAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1805 : cmdidx == CMD_const ? ASSIGN_CONST : ASSIGN_VAR;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1806 lhs->lhs_lvar = reserve_local(cctx, var_start, lhs->lhs_varlen,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1807 assign, lhs->lhs_type);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1808 if (lhs->lhs_lvar == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1809 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1810 lhs->lhs_new_local = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1811 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1812
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1813 lhs->lhs_member_type = lhs->lhs_type;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1814 if (lhs->lhs_has_index)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1815 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1816 char_u *after = var_start + lhs->lhs_varlen;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1817 char_u *p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1818
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1819 // Something follows after the variable: "var[idx]" or "var.key".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1820 if (is_decl && cctx->ctx_skip != SKIP_YES)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1821 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1822 if (has_cmd)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1823 emsg(_(e_cannot_use_index_when_declaring_variable));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1824 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1825 semsg(_(e_unknown_variable_str), lhs->lhs_name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1826 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1827 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1828
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1829 // Now: var_start[lhs->lhs_varlen] is '[' or '.'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1830 // Only the last index is used below, if there are others
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1831 // before it generate code for the expression. Thus for
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1832 // "ll[1][2]" the expression is "ll[1]" and "[2]" is the index.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1833 for (;;)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1834 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1835 p = skip_index(after);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1836 if (*p != '[' && *p != '.')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1837 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1838 lhs->lhs_varlen_total = p - var_start;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1839 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1840 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1841 after = p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1842 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1843 if (after > var_start + lhs->lhs_varlen)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1844 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1845 lhs->lhs_varlen = after - var_start;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1846 lhs->lhs_dest = dest_expr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1847 // We don't know the type before evaluating the expression,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1848 // use "any" until then.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1849 lhs->lhs_type = &t_any;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1850 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1851
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1852 int use_class = lhs->lhs_type != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1853 && (lhs->lhs_type->tt_type == VAR_CLASS
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1854 || lhs->lhs_type->tt_type == VAR_OBJECT);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1855 if (lhs->lhs_type == NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1856 || (use_class ? lhs->lhs_type->tt_class == NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1857 : lhs->lhs_type->tt_member == NULL))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1858 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1859 lhs->lhs_member_type = &t_any;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1860 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1861 else if (use_class)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1862 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1863 // for an object or class member get the type of the member
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1864 class_T *cl = lhs->lhs_type->tt_class;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1865 lhs->lhs_member_type = class_member_type(cl, after + 1,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1866 lhs->lhs_end, &lhs->lhs_member_idx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1867 if (lhs->lhs_member_idx < 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1868 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1869 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1870 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1871 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1872 lhs->lhs_member_type = lhs->lhs_type->tt_member;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1873 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1874 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1875 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1876 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1877
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1878 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1879 * Figure out the LHS and check a few errors.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1880 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1881 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1882 compile_assign_lhs(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1883 char_u *var_start,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1884 lhs_T *lhs,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1885 cmdidx_T cmdidx,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1886 int is_decl,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1887 int heredoc,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1888 int has_cmd, // "var" before "var_start"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1889 int oplen,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1890 cctx_T *cctx)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1891 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1892 if (compile_lhs(var_start, lhs, cmdidx, heredoc, has_cmd, oplen, cctx)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1893 == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1894 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1895
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1896 if (!lhs->lhs_has_index && lhs->lhs_lvar == &lhs->lhs_arg_lvar)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1897 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1898 semsg(_(e_cannot_assign_to_argument_str), lhs->lhs_name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1899 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1900 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1901 if (!is_decl && lhs->lhs_lvar != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1902 && lhs->lhs_lvar->lv_const != ASSIGN_VAR
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1903 && !lhs->lhs_has_index)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1904 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1905 semsg(_(e_cannot_assign_to_constant_str), lhs->lhs_name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1906 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1907 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1908 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1909 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1910
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1911 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1912 * Return TRUE if "lhs" has a range index: "[expr : expr]".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1913 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1914 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1915 has_list_index(char_u *idx_start, cctx_T *cctx)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1916 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1917 char_u *p = idx_start;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1918 int save_skip;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1919
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1920 if (*p != '[')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1921 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1922
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1923 p = skipwhite(p + 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1924 if (*p == ':')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1925 return TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1926
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1927 save_skip = cctx->ctx_skip;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1928 cctx->ctx_skip = SKIP_YES;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1929 (void)compile_expr0(&p, cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1930 cctx->ctx_skip = save_skip;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1931 return *skipwhite(p) == ':';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1932 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1933
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1934 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1935 * For an assignment with an index, compile the "idx" in "var[idx]" or "key" in
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1936 * "var.key".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1937 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1938 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1939 compile_assign_index(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1940 char_u *var_start,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1941 lhs_T *lhs,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1942 int *range,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1943 cctx_T *cctx)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1944 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1945 size_t varlen = lhs->lhs_varlen;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1946 char_u *p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1947 int r = OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1948 int need_white_before = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1949 int empty_second;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1950
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1951 p = var_start + varlen;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1952 if (*p == '[')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1953 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1954 p = skipwhite(p + 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1955 if (*p == ':')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1956 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1957 // empty first index, push zero
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1958 r = generate_PUSHNR(cctx, 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1959 need_white_before = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1960 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1961 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1962 r = compile_expr0(&p, cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1963
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1964 if (r == OK && *skipwhite(p) == ':')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1965 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1966 // unlet var[idx : idx]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1967 // blob[idx : idx] = value
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1968 *range = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1969 p = skipwhite(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1970 empty_second = *skipwhite(p + 1) == ']';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1971 if ((need_white_before && !IS_WHITE_OR_NUL(p[-1]))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1972 || (!empty_second && !IS_WHITE_OR_NUL(p[1])))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1973 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1974 semsg(_(e_white_space_required_before_and_after_str_at_str),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1975 ":", p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1976 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1977 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1978 p = skipwhite(p + 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1979 if (*p == ']')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1980 // empty second index, push "none"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1981 r = generate_PUSHSPEC(cctx, VVAL_NONE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1982 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1983 r = compile_expr0(&p, cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1984 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1985
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1986 if (r == OK && *skipwhite(p) != ']')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1987 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1988 // this should not happen
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1989 emsg(_(e_missing_closing_square_brace));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1990 r = FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1991 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1992 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1993 else if (lhs->lhs_member_idx >= 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1994 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1995 // object member index
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1996 r = generate_PUSHNR(cctx, lhs->lhs_member_idx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1997 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1998 else // if (*p == '.')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
1999 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2000 char_u *key_end = to_name_end(p + 1, TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2001 char_u *key = vim_strnsave(p + 1, key_end - p - 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2002
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2003 r = generate_PUSHS(cctx, &key);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2004 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2005 return r;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2006 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2007
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2008 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2009 * For a LHS with an index, load the variable to be indexed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2010 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2011 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2012 compile_load_lhs(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2013 lhs_T *lhs,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2014 char_u *var_start,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2015 type_T *rhs_type,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2016 cctx_T *cctx)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2017 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2018 if (lhs->lhs_dest == dest_expr)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2019 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2020 size_t varlen = lhs->lhs_varlen;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2021 int c = var_start[varlen];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2022 int lines_len = cctx->ctx_ufunc->uf_lines.ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2023 int res;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2024
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2025 // Evaluate "ll[expr]" of "ll[expr][idx]". End the line with a NUL and
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2026 // limit the lines array length to avoid skipping to a following line.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2027 var_start[varlen] = NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2028 cctx->ctx_ufunc->uf_lines.ga_len = cctx->ctx_lnum + 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2029 char_u *p = var_start;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2030 res = compile_expr0(&p, cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2031 var_start[varlen] = c;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2032 cctx->ctx_ufunc->uf_lines.ga_len = lines_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2033 if (res == FAIL || p != var_start + varlen)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2034 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2035 // this should not happen
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2036 if (res != FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2037 emsg(_(e_missing_closing_square_brace));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2038 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2039 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2040
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2041 lhs->lhs_type = cctx->ctx_type_stack.ga_len == 0 ? &t_void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2042 : get_type_on_stack(cctx, 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2043 // Now we can properly check the type. The variable is indexed, thus
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2044 // we need the member type. For a class or object we don't know the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2045 // type yet, it depends on what member is used.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2046 vartype_T vartype = lhs->lhs_type->tt_type;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2047 type_T *member_type = lhs->lhs_type->tt_member;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2048 if (rhs_type != NULL && member_type != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2049 && vartype != VAR_OBJECT && vartype != VAR_CLASS
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2050 && rhs_type != &t_void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2051 && need_type(rhs_type, member_type, FALSE,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2052 -2, 0, cctx, FALSE, FALSE) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2053 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2054 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2055 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2056 generate_loadvar(cctx, lhs);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2057 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2058 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2059
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2060 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2061 * Produce code for loading "lhs" and also take care of an index.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2062 * Return OK/FAIL.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2063 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2064 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2065 compile_load_lhs_with_index(lhs_T *lhs, char_u *var_start, cctx_T *cctx)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2066 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2067 if (lhs->lhs_type->tt_type == VAR_OBJECT)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2068 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2069 // "this.value": load "this" object and get the value at index for an
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2070 // object or class member get the type of the member.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2071 // Also for "obj.value".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2072 char_u *dot = vim_strchr(var_start, '.');
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2073 if (dot == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2074 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2075
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2076 class_T *cl = lhs->lhs_type->tt_class;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2077 type_T *type = class_member_type(cl, dot + 1,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2078 lhs->lhs_end, &lhs->lhs_member_idx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2079 if (lhs->lhs_member_idx < 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2080 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2081
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2082 if (dot - var_start == 4 && STRNCMP(var_start, "this", 4) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2083 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2084 // load "this"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2085 if (generate_LOAD(cctx, ISN_LOAD, 0, NULL, lhs->lhs_type) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2086 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2087 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2088 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2089 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2090 // load object variable or argument
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2091 if (compile_load_lhs(lhs, var_start, lhs->lhs_type, cctx) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2092 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2093 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2094 if (cl->class_flags & CLASS_INTERFACE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2095 return generate_GET_ITF_MEMBER(cctx, cl, lhs->lhs_member_idx, type);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2096 return generate_GET_OBJ_MEMBER(cctx, lhs->lhs_member_idx, type);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2097 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2098
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2099 compile_load_lhs(lhs, var_start, NULL, cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2100
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2101 if (lhs->lhs_has_index)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2102 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2103 int range = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2104
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2105 // Get member from list or dict. First compile the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2106 // index value.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2107 if (compile_assign_index(var_start, lhs, &range, cctx) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2108 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2109 if (range)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2110 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2111 semsg(_(e_cannot_use_range_with_assignment_operator_str),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2112 var_start);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2113 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2114 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2115
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2116 // Get the member.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2117 if (compile_member(FALSE, NULL, cctx) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2118 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2119 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2120 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2121 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2122
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2123 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2124 * Assignment to a list or dict member, or ":unlet" for the item, using the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2125 * information in "lhs".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2126 * Returns OK or FAIL.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2127 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2128 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2129 compile_assign_unlet(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2130 char_u *var_start,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2131 lhs_T *lhs,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2132 int is_assign,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2133 type_T *rhs_type,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2134 cctx_T *cctx)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2135 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2136 vartype_T dest_type;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2137 int range = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2138
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2139 if (compile_assign_index(var_start, lhs, &range, cctx) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2140 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2141 if (is_assign && range
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2142 && lhs->lhs_type->tt_type != VAR_LIST
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2143 && lhs->lhs_type != &t_blob
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2144 && lhs->lhs_type != &t_any)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2145 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2146 semsg(_(e_cannot_use_range_with_assignment_str), var_start);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2147 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2148 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2149
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2150 if (lhs->lhs_type == NULL || lhs->lhs_type == &t_any)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2151 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2152 // Index on variable of unknown type: check at runtime.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2153 dest_type = VAR_ANY;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2154 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2155 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2156 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2157 dest_type = lhs->lhs_type->tt_type;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2158 if (dest_type == VAR_DICT && range)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2159 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2160 emsg(_(e_cannot_use_range_with_dictionary));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2161 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2162 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2163 if (dest_type == VAR_DICT
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2164 && may_generate_2STRING(-1, FALSE, cctx) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2165 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2166 if (dest_type == VAR_LIST || dest_type == VAR_BLOB)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2167 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2168 type_T *type;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2169
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2170 if (range)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2171 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2172 type = get_type_on_stack(cctx, 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2173 if (need_type(type, &t_number, FALSE,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2174 -2, 0, cctx, FALSE, FALSE) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2175 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2176 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2177 type = get_type_on_stack(cctx, 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2178 if ((dest_type != VAR_BLOB && type->tt_type != VAR_SPECIAL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2179 && need_type(type, &t_number, FALSE,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2180 -1, 0, cctx, FALSE, FALSE) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2181 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2182 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2183 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2184
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2185 if (cctx->ctx_skip == SKIP_YES)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2186 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2187
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2188 // Load the dict, list or object. On the stack we then have:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2189 // - value (for assignment, not for :unlet)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2190 // - index
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2191 // - for [a : b] second index
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2192 // - variable
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2193 if (compile_load_lhs(lhs, var_start, rhs_type, cctx) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2194 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2195
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2196 if (dest_type == VAR_LIST
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2197 || dest_type == VAR_DICT
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2198 || dest_type == VAR_BLOB
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2199 || dest_type == VAR_CLASS
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2200 || dest_type == VAR_OBJECT
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2201 || dest_type == VAR_ANY)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2202 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2203 if (is_assign)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2204 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2205 if (range)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2206 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2207 if (generate_instr_drop(cctx, ISN_STORERANGE, 4) == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2208 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2209 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2210 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2211 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2212 isn_T *isn = generate_instr_drop(cctx, ISN_STOREINDEX, 3);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2213
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2214 if (isn == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2215 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2216 isn->isn_arg.storeindex.si_vartype = dest_type;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2217 isn->isn_arg.storeindex.si_class = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2218
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2219 if (dest_type == VAR_OBJECT)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2220 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2221 class_T *cl = lhs->lhs_type->tt_class;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2222
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2223 if (cl->class_flags & CLASS_INTERFACE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2224 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2225 // "this.value": load "this" object and get the value
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2226 // at index for an object or class member get the type
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2227 // of the member
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2228 isn->isn_arg.storeindex.si_class = cl;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2229 ++cl->class_refcount;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2230 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2231 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2232 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2233 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2234 else if (range)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2235 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2236 if (generate_instr_drop(cctx, ISN_UNLETRANGE, 3) == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2237 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2238 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2239 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2240 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2241 if (generate_instr_drop(cctx, ISN_UNLETINDEX, 2) == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2242 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2243 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2244 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2245 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2246 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2247 emsg(_(e_indexable_type_required));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2248 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2249 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2250
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2251 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2252 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2253
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2254 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2255 * Generate an instruction to push the default value for "vartype".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2256 * if "dest_local" is TRUE then for some types no instruction is generated.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2257 * "skip_store" is set to TRUE if no PUSH instruction is generated.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2258 * Returns OK or FAIL.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2259 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2260 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2261 push_default_value(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2262 cctx_T *cctx,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2263 vartype_T vartype,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2264 int dest_is_local,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2265 int *skip_store)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2266 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2267 int r = OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2268
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2269 switch (vartype)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2270 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2271 case VAR_BOOL:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2272 r = generate_PUSHBOOL(cctx, VVAL_FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2273 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2274 case VAR_FLOAT:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2275 r = generate_PUSHF(cctx, 0.0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2276 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2277 case VAR_STRING:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2278 r = generate_PUSHS(cctx, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2279 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2280 case VAR_BLOB:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2281 r = generate_PUSHBLOB(cctx, blob_alloc());
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2282 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2283 case VAR_FUNC:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2284 r = generate_PUSHFUNC(cctx, NULL, &t_func_void, TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2285 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2286 case VAR_LIST:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2287 r = generate_NEWLIST(cctx, 0, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2288 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2289 case VAR_DICT:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2290 r = generate_NEWDICT(cctx, 0, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2291 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2292 case VAR_JOB:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2293 r = generate_PUSHJOB(cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2294 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2295 case VAR_CHANNEL:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2296 r = generate_PUSHCHANNEL(cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2297 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2298 case VAR_NUMBER:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2299 case VAR_UNKNOWN:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2300 case VAR_ANY:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2301 case VAR_PARTIAL:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2302 case VAR_VOID:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2303 case VAR_INSTR:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2304 case VAR_CLASS:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2305 case VAR_OBJECT:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2306 case VAR_SPECIAL: // cannot happen
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2307 // This is skipped for local variables, they are always
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2308 // initialized to zero. But in a "for" or "while" loop
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2309 // the value may have been changed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2310 if (dest_is_local && !inside_loop_scope(cctx))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2311 *skip_store = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2312 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2313 r = generate_PUSHNR(cctx, 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2314 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2315 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2316 return r;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2317 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2318
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2319 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2320 * Compile declaration and assignment:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2321 * "let name"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2322 * "var name = expr"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2323 * "final name = expr"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2324 * "const name = expr"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2325 * "name = expr"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2326 * "arg" points to "name".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2327 * "++arg" and "--arg"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2328 * Return NULL for an error.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2329 * Return "arg" if it does not look like a variable list.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2330 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2331 static char_u *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2332 compile_assignment(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2333 char_u *arg_start,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2334 exarg_T *eap,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2335 cmdidx_T cmdidx,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2336 cctx_T *cctx)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2337 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2338 char_u *arg = arg_start;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2339 char_u *var_start;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2340 char_u *p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2341 char_u *end = arg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2342 char_u *ret = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2343 int var_count = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2344 int var_idx;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2345 int semicolon = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2346 int did_generate_slice = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2347 garray_T *instr = &cctx->ctx_instr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2348 int jump_instr_idx = instr->ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2349 char_u *op;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2350 int oplen = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2351 int heredoc = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2352 int incdec = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2353 type_T *rhs_type = &t_any;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2354 char_u *sp;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2355 int is_decl = is_decl_command(cmdidx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2356 lhs_T lhs;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2357 CLEAR_FIELD(lhs);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2358 long start_lnum = SOURCING_LNUM;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2359
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2360 int has_arg_is_set_prefix = STRNCMP(arg, "ifargisset ", 11) == 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2361 if (has_arg_is_set_prefix)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2362 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2363 arg += 11;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2364 int def_idx = getdigits(&arg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2365 arg = skipwhite(arg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2366
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2367 // Use a JUMP_IF_ARG_NOT_SET instruction to skip if the value was not
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2368 // given and the default value is "v:none".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2369 int off = STACK_FRAME_SIZE + (cctx->ctx_ufunc->uf_va_name != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2370 ? 1 : 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2371 int count = cctx->ctx_ufunc->uf_def_args.ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2372 if (generate_JUMP_IF_ARG(cctx, ISN_JUMP_IF_ARG_NOT_SET,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2373 def_idx - count - off) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2374 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2375 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2376
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2377 // Skip over the "varname" or "[varname, varname]" to get to any "=".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2378 p = skip_var_list(arg, TRUE, &var_count, &semicolon, TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2379 if (p == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2380 return *arg == '[' ? arg : NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2381
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2382 if (eap->cmdidx == CMD_increment || eap->cmdidx == CMD_decrement)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2383 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2384 if (VIM_ISWHITE(eap->cmd[2]))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2385 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2386 semsg(_(e_no_white_space_allowed_after_str_str),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2387 eap->cmdidx == CMD_increment ? "++" : "--", eap->cmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2388 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2389 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2390 op = (char_u *)(eap->cmdidx == CMD_increment ? "+=" : "-=");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2391 oplen = 2;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2392 incdec = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2393 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2394 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2395 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2396 sp = p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2397 p = skipwhite(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2398 op = p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2399 oplen = assignment_len(p, &heredoc);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2400
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2401 if (var_count > 0 && oplen == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2402 // can be something like "[1, 2]->func()"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2403 return arg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2404
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2405 if (oplen > 0 && (!VIM_ISWHITE(*sp) || !IS_WHITE_OR_NUL(op[oplen])))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2406 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2407 error_white_both(op, oplen);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2408 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2409 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2410 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2411
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2412 if (heredoc)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2413 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2414 list_T *l;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2415
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2416 // [let] varname =<< [trim] {end}
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2417 eap->getline = exarg_getline;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2418 eap->cookie = cctx;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2419 l = heredoc_get(eap, op + 3, FALSE, TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2420 if (l == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2421 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2422
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2423 list_free(l);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2424 p += STRLEN(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2425 end = p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2426 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2427 else if (var_count > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2428 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2429 char_u *wp;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2430
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2431 // for "[var, var] = expr" evaluate the expression here, loop over the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2432 // list of variables below.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2433 // A line break may follow the "=".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2434
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2435 wp = op + oplen;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2436 if (may_get_next_line_error(wp, &p, cctx) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2437 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2438 if (compile_expr0(&p, cctx) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2439 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2440 end = p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2441
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2442 if (cctx->ctx_skip != SKIP_YES)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2443 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2444 type_T *stacktype;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2445 int needed_list_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2446 int did_check = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2447
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2448 stacktype = cctx->ctx_type_stack.ga_len == 0 ? &t_void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2449 : get_type_on_stack(cctx, 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2450 if (stacktype->tt_type == VAR_VOID)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2451 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2452 emsg(_(e_cannot_use_void_value));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2453 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2454 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2455 if (need_type(stacktype, &t_list_any, FALSE, -1, 0, cctx,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2456 FALSE, FALSE) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2457 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2458 // If a constant list was used we can check the length right here.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2459 needed_list_len = semicolon ? var_count - 1 : var_count;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2460 if (instr->ga_len > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2461 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2462 isn_T *isn = ((isn_T *)instr->ga_data) + instr->ga_len - 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2463
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2464 if (isn->isn_type == ISN_NEWLIST)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2465 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2466 did_check = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2467 if (semicolon ? isn->isn_arg.number < needed_list_len
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2468 : isn->isn_arg.number != needed_list_len)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2469 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2470 semsg(_(e_expected_nr_items_but_got_nr),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2471 needed_list_len, (int)isn->isn_arg.number);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2472 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2473 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2474 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2475 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2476 if (!did_check)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2477 generate_CHECKLEN(cctx, needed_list_len, semicolon);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2478 if (stacktype->tt_member != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2479 rhs_type = stacktype->tt_member;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2480 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2481 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2482
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2483 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2484 * Loop over variables in "[var, var] = expr".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2485 * For "var = expr" and "let var: type" this is done only once.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2486 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2487 if (var_count > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2488 var_start = skipwhite(arg + 1); // skip over the "["
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2489 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2490 var_start = arg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2491 for (var_idx = 0; var_idx == 0 || var_idx < var_count; var_idx++)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2492 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2493 int instr_count = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2494 int save_lnum;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2495 int skip_store = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2496 type_T *inferred_type = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2497
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2498 if (var_start[0] == '_' && !eval_isnamec(var_start[1]))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2499 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2500 // Ignore underscore in "[a, _, b] = list".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2501 if (var_count > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2502 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2503 var_start = skipwhite(var_start + 2);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2504 continue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2505 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2506 emsg(_(e_cannot_use_underscore_here));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2507 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2508 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2509 vim_free(lhs.lhs_name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2510
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2511 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2512 * Figure out the LHS type and other properties.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2513 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2514 if (compile_assign_lhs(var_start, &lhs, cmdidx,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2515 is_decl, heredoc, var_start > eap->cmd,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2516 oplen, cctx) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2517 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2518 if (heredoc)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2519 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2520 SOURCING_LNUM = start_lnum;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2521 if (lhs.lhs_has_type
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2522 && need_type(&t_list_string, lhs.lhs_type, FALSE,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2523 -1, 0, cctx, FALSE, FALSE) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2524 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2525 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2526 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2527 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2528 if (cctx->ctx_skip == SKIP_YES)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2529 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2530 if (oplen > 0 && var_count == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2531 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2532 // skip over the "=" and the expression
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2533 p = skipwhite(op + oplen);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2534 (void)compile_expr0(&p, cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2535 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2536 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2537 else if (oplen > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2538 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2539 int is_const = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2540 char_u *wp;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2541
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2542 // for "+=", "*=", "..=" etc. first load the current value
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2543 if (*op != '='
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2544 && compile_load_lhs_with_index(&lhs, var_start,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2545 cctx) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2546 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2547
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2548 // For "var = expr" evaluate the expression.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2549 if (var_count == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2550 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2551 int r;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2552
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2553 // Compile the expression.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2554 instr_count = instr->ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2555 if (incdec)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2556 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2557 r = generate_PUSHNR(cctx, 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2558 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2559 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2560 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2561 // Temporarily hide the new local variable here, it is
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2562 // not available to this expression.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2563 if (lhs.lhs_new_local)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2564 --cctx->ctx_locals.ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2565 wp = op + oplen;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2566 if (may_get_next_line_error(wp, &p, cctx) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2567 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2568 if (lhs.lhs_new_local)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2569 ++cctx->ctx_locals.ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2570 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2571 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2572 r = compile_expr0_ext(&p, cctx, &is_const);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2573 if (lhs.lhs_new_local)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2574 ++cctx->ctx_locals.ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2575 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2576 if (r == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2577 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2578 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2579 else if (semicolon && var_idx == var_count - 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2580 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2581 // For "[var; var] = expr" get the rest of the list
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2582 did_generate_slice = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2583 if (generate_SLICE(cctx, var_count - 1) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2584 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2585 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2586 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2587 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2588 // For "[var, var] = expr" get the "var_idx" item from the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2589 // list.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2590 if (generate_GETITEM(cctx, var_idx, *op != '=') == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2591 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2592 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2593
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2594 rhs_type = cctx->ctx_type_stack.ga_len == 0 ? &t_void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2595 : get_type_on_stack(cctx, 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2596 if (lhs.lhs_lvar != NULL && (is_decl || !lhs.lhs_has_type))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2597 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2598 if ((rhs_type->tt_type == VAR_FUNC
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2599 || rhs_type->tt_type == VAR_PARTIAL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2600 && !lhs.lhs_has_index
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2601 && var_wrong_func_name(lhs.lhs_name, TRUE))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2602 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2603
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2604 if (lhs.lhs_new_local && !lhs.lhs_has_type)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2605 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2606 if (rhs_type->tt_type == VAR_VOID)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2607 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2608 emsg(_(e_cannot_use_void_value));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2609 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2610 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2611 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2612 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2613 type_T *type;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2614
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2615 // An empty list or dict has a &t_unknown member,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2616 // for a variable that implies &t_any.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2617 if (rhs_type == &t_list_empty)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2618 type = &t_list_any;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2619 else if (rhs_type == &t_dict_empty)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2620 type = &t_dict_any;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2621 else if (rhs_type == &t_unknown)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2622 type = &t_any;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2623 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2624 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2625 type = rhs_type;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2626 inferred_type = rhs_type;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2627 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2628 set_var_type(lhs.lhs_lvar, type, cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2629 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2630 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2631 else if (*op == '=')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2632 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2633 type_T *use_type = lhs.lhs_lvar->lv_type;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2634 where_T where = WHERE_INIT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2635
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2636 // Without operator check type here, otherwise below.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2637 // Use the line number of the assignment.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2638 SOURCING_LNUM = start_lnum;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2639 where.wt_index = var_count > 0 ? var_idx + 1 : 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2640 where.wt_variable = var_count > 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2641 // If assigning to a list or dict member, use the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2642 // member type. Not for "list[:] =".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2643 if (lhs.lhs_has_index
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2644 && !has_list_index(var_start + lhs.lhs_varlen,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2645 cctx))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2646 use_type = lhs.lhs_member_type;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2647 if (need_type_where(rhs_type, use_type, FALSE, -1,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2648 where, cctx, FALSE, is_const) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2649 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2650 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2651 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2652 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2653 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2654 type_T *lhs_type = lhs.lhs_member_type;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2655
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2656 // Special case: assigning to @# can use a number or a
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2657 // string.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2658 // Also: can assign a number to a float.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2659 if ((lhs_type == &t_number_or_string
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2660 || lhs_type == &t_float)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2661 && rhs_type->tt_type == VAR_NUMBER)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2662 lhs_type = &t_number;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2663 if (*p != '=' && need_type(rhs_type, lhs_type, FALSE,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2664 -1, 0, cctx, FALSE, FALSE) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2665 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2666 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2667 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2668 else if (cmdidx == CMD_final)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2669 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2670 emsg(_(e_final_requires_a_value));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2671 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2672 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2673 else if (cmdidx == CMD_const)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2674 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2675 emsg(_(e_const_requires_a_value));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2676 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2677 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2678 else if (!lhs.lhs_has_type || lhs.lhs_dest == dest_option
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2679 || lhs.lhs_dest == dest_func_option)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2680 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2681 emsg(_(e_type_or_initialization_required));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2682 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2683 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2684 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2685 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2686 // variables are always initialized
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2687 if (GA_GROW_FAILS(instr, 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2688 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2689 instr_count = instr->ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2690 int r = push_default_value(cctx, lhs.lhs_member_type->tt_type,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2691 lhs.lhs_dest == dest_local, &skip_store);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2692 if (r == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2693 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2694 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2695 if (var_count == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2696 end = p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2697 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2698
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2699 // no need to parse more when skipping
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2700 if (cctx->ctx_skip == SKIP_YES)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2701 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2702
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2703 if (oplen > 0 && *op != '=')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2704 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2705 type_T *expected;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2706 type_T *stacktype = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2707
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2708 if (*op == '.')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2709 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2710 if (may_generate_2STRING(-1, FALSE, cctx) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2711 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2712 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2713 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2714 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2715 expected = lhs.lhs_member_type;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2716 stacktype = get_type_on_stack(cctx, 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2717 if (
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2718 // If variable is float operation with number is OK.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2719 !(expected == &t_float && (stacktype == &t_number
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2720 || stacktype == &t_number_bool))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2721 && need_type(stacktype, expected, TRUE, -1, 0, cctx,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2722 FALSE, FALSE) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2723 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2724 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2725
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2726 if (*op == '.')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2727 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2728 if (generate_CONCAT(cctx, 2) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2729 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2730 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2731 else if (*op == '+')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2732 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2733 if (generate_add_instr(cctx,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2734 operator_type(lhs.lhs_member_type, stacktype),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2735 lhs.lhs_member_type, stacktype,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2736 EXPR_APPEND) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2737 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2738 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2739 else if (generate_two_op(cctx, op) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2740 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2741 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2742
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2743 // Use the line number of the assignment for store instruction.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2744 save_lnum = cctx->ctx_lnum;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2745 cctx->ctx_lnum = start_lnum - 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2746
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2747 if (lhs.lhs_has_index)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2748 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2749 // Use the info in "lhs" to store the value at the index in the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2750 // list, dict or object.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2751 if (compile_assign_unlet(var_start, &lhs, TRUE, rhs_type, cctx)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2752 == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2753 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2754 cctx->ctx_lnum = save_lnum;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2755 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2756 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2757 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2758 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2759 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2760 if (is_decl && cmdidx == CMD_const && (lhs.lhs_dest == dest_script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2761 || lhs.lhs_dest == dest_global
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2762 || lhs.lhs_dest == dest_local))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2763 // ":const var": lock the value, but not referenced variables
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2764 generate_LOCKCONST(cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2765
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2766 if ((lhs.lhs_type->tt_type == VAR_DICT
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2767 || lhs.lhs_type->tt_type == VAR_LIST)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2768 && lhs.lhs_type->tt_member != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2769 && lhs.lhs_type->tt_member != &t_any
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2770 && lhs.lhs_type->tt_member != &t_unknown)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2771 // Set the type in the list or dict, so that it can be checked,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2772 // also in legacy script.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2773 generate_SETTYPE(cctx, lhs.lhs_type);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2774 else if (inferred_type != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2775 && (inferred_type->tt_type == VAR_DICT
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2776 || inferred_type->tt_type == VAR_LIST)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2777 && inferred_type->tt_member != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2778 && inferred_type->tt_member != &t_unknown
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2779 && inferred_type->tt_member != &t_any)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2780 // Set the type in the list or dict, so that it can be checked,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2781 // also in legacy script.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2782 generate_SETTYPE(cctx, inferred_type);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2783
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2784 if (!skip_store && generate_store_lhs(cctx, &lhs,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2785 instr_count, is_decl) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2786 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2787 cctx->ctx_lnum = save_lnum;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2788 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2789 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2790 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2791 cctx->ctx_lnum = save_lnum;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2792
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2793 if (var_idx + 1 < var_count)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2794 var_start = skipwhite(lhs.lhs_end + 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2795
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2796 if (has_arg_is_set_prefix)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2797 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2798 // set instruction index in JUMP_IF_ARG_SET to here
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2799 isn_T *isn = ((isn_T *)instr->ga_data) + jump_instr_idx;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2800 isn->isn_arg.jumparg.jump_where = instr->ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2801 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2802 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2803
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2804 // For "[var, var] = expr" drop the "expr" value.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2805 // Also for "[var, var; _] = expr".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2806 if (var_count > 0 && (!semicolon || !did_generate_slice))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2807 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2808 if (generate_instr_drop(cctx, ISN_DROP, 1) == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2809 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2810 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2811
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2812 ret = skipwhite(end);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2813
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2814 theend:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2815 vim_free(lhs.lhs_name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2816 return ret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2817 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2818
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2819 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2820 * Check for an assignment at "eap->cmd", compile it if found.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2821 * Return NOTDONE if there is none, FAIL for failure, OK if done.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2822 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2823 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2824 may_compile_assignment(exarg_T *eap, char_u **line, cctx_T *cctx)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2825 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2826 char_u *pskip;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2827 char_u *p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2828
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2829 // Assuming the command starts with a variable or function name,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2830 // find what follows.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2831 // Skip over "var.member", "var[idx]" and the like.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2832 // Also "&opt = val", "$ENV = val" and "@r = val".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2833 pskip = (*eap->cmd == '&' || *eap->cmd == '$' || *eap->cmd == '@')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2834 ? eap->cmd + 1 : eap->cmd;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2835 p = to_name_end(pskip, TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2836 if (p > eap->cmd && *p != NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2837 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2838 char_u *var_end;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2839 int oplen;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2840 int heredoc;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2841
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2842 if (eap->cmd[0] == '@')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2843 var_end = eap->cmd + 2;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2844 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2845 var_end = find_name_end(pskip, NULL, NULL,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2846 FNE_CHECK_START | FNE_INCL_BR);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2847 oplen = assignment_len(skipwhite(var_end), &heredoc);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2848 if (oplen > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2849 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2850 size_t len = p - eap->cmd;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2851
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2852 // Recognize an assignment if we recognize the variable
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2853 // name:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2854 // "&opt = expr"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2855 // "$ENV = expr"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2856 // "@r = expr"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2857 // "g:var = expr"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2858 // "g:[key] = expr"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2859 // "local = expr" where "local" is a local var.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2860 // "script = expr" where "script" is a script-local var.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2861 // "import = expr" where "import" is an imported var
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2862 if (*eap->cmd == '&'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2863 || *eap->cmd == '$'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2864 || *eap->cmd == '@'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2865 || ((len) > 2 && eap->cmd[1] == ':')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2866 || STRNCMP(eap->cmd, "g:[", 3) == 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2867 || variable_exists(eap->cmd, len, cctx))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2868 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2869 *line = compile_assignment(eap->cmd, eap, CMD_SIZE, cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2870 if (*line == NULL || *line == eap->cmd)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2871 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2872 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2873 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2874 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2875 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2876
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2877 // might be "[var, var] = expr" or "ifargisset this.member = expr"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2878 if (*eap->cmd == '[' || STRNCMP(eap->cmd, "ifargisset ", 11) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2879 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2880 *line = compile_assignment(eap->cmd, eap, CMD_SIZE, cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2881 if (*line == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2882 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2883 if (*line != eap->cmd)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2884 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2885 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2886 return NOTDONE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2887 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2888
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2889 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2890 * Check if arguments of "ufunc" shadow variables in "cctx".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2891 * Return OK or FAIL.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2892 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2893 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2894 check_args_shadowing(ufunc_T *ufunc, cctx_T *cctx)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2895 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2896 int i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2897 char_u *arg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2898 int r = OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2899
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2900 // Make sure arguments are not found when compiling a second time.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2901 ufunc->uf_args_visible = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2902
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2903 // Check for arguments shadowing variables from the context.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2904 for (i = 0; i < ufunc->uf_args.ga_len; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2905 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2906 arg = ((char_u **)(ufunc->uf_args.ga_data))[i];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2907 if (check_defined(arg, STRLEN(arg), cctx, NULL, TRUE) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2908 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2909 r = FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2910 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2911 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2912 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2913 ufunc->uf_args_visible = ufunc->uf_args.ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2914 return r;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2915 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2916
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2917 #ifdef HAS_MESSAGE_WINDOW
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2918 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2919 * Get a count before a command. Can only be a number.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2920 * Returns zero if there is no count.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2921 * Returns -1 if there is something wrong.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2922 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2923 static long
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2924 get_cmd_count(char_u *line, exarg_T *eap)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2925 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2926 char_u *p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2927
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2928 // skip over colons and white space
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2929 for (p = line; *p == ':' || VIM_ISWHITE(*p); ++p)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2930 ;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2931 if (!isdigit(*p))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2932 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2933 // The command or modifiers must be following. Assume a lower case
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2934 // character means there is a modifier.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2935 if (p < eap->cmd && !vim_islower(*p))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2936 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2937 emsg(_(e_invalid_range));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2938 return -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2939 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2940 return 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2941 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2942 return atol((char *)p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2943 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2944 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2945
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2946 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2947 * Get the compilation type that should be used for "ufunc".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2948 * Keep in sync with INSTRUCTIONS().
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2949 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2950 compiletype_T
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2951 get_compile_type(ufunc_T *ufunc)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2952 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2953 // Update uf_has_breakpoint if needed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2954 update_has_breakpoint(ufunc);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2955
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2956 if (debug_break_level > 0 || may_break_in_function(ufunc))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2957 return CT_DEBUG;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2958 #ifdef FEAT_PROFILE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2959 if (do_profiling == PROF_YES)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2960 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2961 if (!ufunc->uf_profiling && has_profiling(FALSE, ufunc->uf_name, NULL))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2962 func_do_profile(ufunc);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2963 if (ufunc->uf_profiling)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2964 return CT_PROFILE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2965 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2966 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2967 return CT_NONE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2968 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2969
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2970
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2971 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2972 * Add a function to the list of :def functions.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2973 * This sets "ufunc->uf_dfunc_idx" but the function isn't compiled yet.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2974 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2975 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2976 add_def_function(ufunc_T *ufunc)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2977 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2978 dfunc_T *dfunc;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2979
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2980 if (def_functions.ga_len == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2981 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2982 // The first position is not used, so that a zero uf_dfunc_idx means it
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2983 // wasn't set.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2984 if (GA_GROW_FAILS(&def_functions, 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2985 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2986 ++def_functions.ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2987 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2988
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2989 // Add the function to "def_functions".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2990 if (GA_GROW_FAILS(&def_functions, 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2991 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2992 dfunc = ((dfunc_T *)def_functions.ga_data) + def_functions.ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2993 CLEAR_POINTER(dfunc);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2994 dfunc->df_idx = def_functions.ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2995 ufunc->uf_dfunc_idx = dfunc->df_idx;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2996 dfunc->df_ufunc = ufunc;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2997 dfunc->df_name = vim_strsave(ufunc->uf_name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2998 ga_init2(&dfunc->df_var_names, sizeof(char_u *), 10);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
2999 ++dfunc->df_refcount;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3000 ++def_functions.ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3001 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3002 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3003
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3004 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3005 * After ex_function() has collected all the function lines: parse and compile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3006 * the lines into instructions.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3007 * Adds the function to "def_functions".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3008 * When "check_return_type" is set then set ufunc->uf_ret_type to the type of
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3009 * the return statement (used for lambda). When uf_ret_type is already set
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3010 * then check that it matches.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3011 * When "profiling" is true add ISN_PROF_START instructions.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3012 * "outer_cctx" is set for a nested function.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3013 * This can be used recursively through compile_lambda(), which may reallocate
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3014 * "def_functions".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3015 * Returns OK or FAIL.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3016 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3017 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3018 compile_def_function(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3019 ufunc_T *ufunc,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3020 int check_return_type,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3021 compiletype_T compile_type,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3022 cctx_T *outer_cctx)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3023 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3024 char_u *line = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3025 garray_T lines_to_free;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3026 char_u *p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3027 char *errormsg = NULL; // error message
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3028 cctx_T cctx;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3029 garray_T *instr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3030 int did_emsg_before = did_emsg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3031 int did_emsg_silent_before = did_emsg_silent;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3032 int ret = FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3033 sctx_T save_current_sctx = current_sctx;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3034 int save_estack_compiling = estack_compiling;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3035 int save_cmod_flags = cmdmod.cmod_flags;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3036 int do_estack_push;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3037 int new_def_function = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3038 #ifdef FEAT_PROFILE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3039 int prof_lnum = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3040 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3041 int debug_lnum = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3042
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3043 // allocated lines are freed at the end
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3044 ga_init2(&lines_to_free, sizeof(char_u *), 50);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3045
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3046 // When using a function that was compiled before: Free old instructions.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3047 // The index is reused. Otherwise add a new entry in "def_functions".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3048 if (ufunc->uf_dfunc_idx > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3049 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3050 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3051 + ufunc->uf_dfunc_idx;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3052 isn_T *instr_dest = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3053
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3054 switch (compile_type)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3055 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3056 case CT_PROFILE:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3057 #ifdef FEAT_PROFILE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3058 instr_dest = dfunc->df_instr_prof; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3059 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3060 case CT_NONE: instr_dest = dfunc->df_instr; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3061 case CT_DEBUG: instr_dest = dfunc->df_instr_debug; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3062 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3063 if (instr_dest != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3064 // Was compiled in this mode before: Free old instructions.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3065 delete_def_function_contents(dfunc, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3066 ga_clear_strings(&dfunc->df_var_names);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3067 dfunc->df_defer_var_idx = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3068 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3069 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3070 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3071 if (add_def_function(ufunc) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3072 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3073 new_def_function = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3074 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3075
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3076 if ((ufunc->uf_flags & FC_CLOSURE) && outer_cctx == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3077 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3078 semsg(_(e_compiling_closure_without_context_str),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3079 printable_func_name(ufunc));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3080 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3081 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3082
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3083 ufunc->uf_def_status = UF_COMPILING;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3084
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3085 CLEAR_FIELD(cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3086
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3087 cctx.ctx_compile_type = compile_type;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3088 cctx.ctx_ufunc = ufunc;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3089 cctx.ctx_lnum = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3090 cctx.ctx_outer = outer_cctx;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3091 ga_init2(&cctx.ctx_locals, sizeof(lvar_T), 10);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3092 // Each entry on the type stack consists of two type pointers.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3093 ga_init2(&cctx.ctx_type_stack, sizeof(type2_T), 50);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3094 cctx.ctx_type_list = &ufunc->uf_type_list;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3095 ga_init2(&cctx.ctx_instr, sizeof(isn_T), 50);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3096 instr = &cctx.ctx_instr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3097
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3098 // Set the context to the function, it may be compiled when called from
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3099 // another script. Set the script version to the most modern one.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3100 // The line number will be set in next_line_from_context().
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3101 current_sctx = ufunc->uf_script_ctx;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3102 current_sctx.sc_version = SCRIPT_VERSION_VIM9;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3103
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3104 // Don't use the flag from ":legacy" here.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3105 cmdmod.cmod_flags &= ~CMOD_LEGACY;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3106
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3107 // Make sure error messages are OK.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3108 do_estack_push = !estack_top_is_ufunc(ufunc, 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3109 if (do_estack_push)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3110 estack_push_ufunc(ufunc, 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3111 estack_compiling = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3112
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3113 if (check_args_shadowing(ufunc, &cctx) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3114 goto erret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3115
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3116 // For an object method and constructor "this" is the first local variable.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3117 if (ufunc->uf_flags & (FC_OBJECT|FC_NEW))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3118 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3119 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3120 + ufunc->uf_dfunc_idx;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3121 if (GA_GROW_FAILS(&dfunc->df_var_names, 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3122 goto erret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3123 ((char_u **)dfunc->df_var_names.ga_data)[0] =
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3124 vim_strsave((char_u *)"this");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3125 ++dfunc->df_var_names.ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3126
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3127 // In the constructor allocate memory for the object and initialize the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3128 // object members.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3129 if ((ufunc->uf_flags & FC_NEW) == FC_NEW)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3130 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3131 generate_CONSTRUCT(&cctx, ufunc->uf_class);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3132
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3133 for (int i = 0; i < ufunc->uf_class->class_obj_member_count; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3134 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3135 ocmember_T *m = &ufunc->uf_class->class_obj_members[i];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3136 if (m->ocm_init != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3137 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3138 char_u *expr = m->ocm_init;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3139 if (compile_expr0(&expr, &cctx) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3140 goto erret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3141 if (!ends_excmd2(m->ocm_init, expr))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3142 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3143 semsg(_(e_trailing_characters_str), expr);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3144 goto erret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3145 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3146 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3147 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3148 push_default_value(&cctx, m->ocm_type->tt_type,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3149 FALSE, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3150 generate_STORE_THIS(&cctx, i);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3151 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3152 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3153 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3154
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3155 if (ufunc->uf_def_args.ga_len > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3156 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3157 int count = ufunc->uf_def_args.ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3158 int first_def_arg = ufunc->uf_args.ga_len - count;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3159 int i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3160 int off = STACK_FRAME_SIZE + (ufunc->uf_va_name != NULL ? 1 : 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3161 int did_set_arg_type = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3162
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3163 // Produce instructions for the default values of optional arguments.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3164 SOURCING_LNUM = 0; // line number unknown
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3165 for (i = 0; i < count; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3166 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3167 char_u *arg = ((char_u **)(ufunc->uf_def_args.ga_data))[i];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3168 if (STRCMP(arg, "v:none") == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3169 // "arg = v:none" means the argument is optional without
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3170 // setting a value when the argument is missing.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3171 continue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3172
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3173 type_T *val_type;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3174 int arg_idx = first_def_arg + i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3175 where_T where = WHERE_INIT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3176 int jump_instr_idx = instr->ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3177 isn_T *isn;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3178
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3179 // Use a JUMP_IF_ARG_SET instruction to skip if the value was given.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3180 if (generate_JUMP_IF_ARG(&cctx, ISN_JUMP_IF_ARG_SET,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3181 i - count - off) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3182 goto erret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3183
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3184 // Make sure later arguments are not found.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3185 ufunc->uf_args_visible = arg_idx;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3186
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3187 int r = compile_expr0(&arg, &cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3188 if (r == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3189 goto erret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3190
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3191 // If no type specified use the type of the default value.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3192 // Otherwise check that the default value type matches the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3193 // specified type.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3194 val_type = get_type_on_stack(&cctx, 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3195 where.wt_index = arg_idx + 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3196 if (ufunc->uf_arg_types[arg_idx] == &t_unknown)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3197 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3198 did_set_arg_type = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3199 ufunc->uf_arg_types[arg_idx] = val_type;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3200 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3201 else if (need_type_where(val_type, ufunc->uf_arg_types[arg_idx],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3202 FALSE, -1, where, &cctx, FALSE, FALSE) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3203 goto erret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3204
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3205 if (generate_STORE(&cctx, ISN_STORE, i - count - off, NULL) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3206 goto erret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3207
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3208 // set instruction index in JUMP_IF_ARG_SET to here
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3209 isn = ((isn_T *)instr->ga_data) + jump_instr_idx;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3210 isn->isn_arg.jumparg.jump_where = instr->ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3211 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3212
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3213 if (did_set_arg_type)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3214 set_function_type(ufunc);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3215 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3216 ufunc->uf_args_visible = ufunc->uf_args.ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3217
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3218 // Compiling a function in an interface is done to get the function type.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3219 // No code is actually compiled.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3220 if (ufunc->uf_class != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3221 && (ufunc->uf_class->class_flags & CLASS_INTERFACE))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3222 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3223 ufunc->uf_def_status = UF_NOT_COMPILED;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3224 ret = OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3225 goto erret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3226 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3227
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3228 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3229 * Loop over all the lines of the function and generate instructions.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3230 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3231 for (;;)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3232 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3233 exarg_T ea;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3234 int starts_with_colon = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3235 char_u *cmd;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3236 cmdmod_T local_cmdmod;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3237
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3238 // Bail out on the first error to avoid a flood of errors and report
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3239 // the right line number when inside try/catch.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3240 if (did_emsg_before != did_emsg)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3241 goto erret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3242
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3243 if (line != NULL && *line == '|')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3244 // the line continues after a '|'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3245 ++line;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3246 else if (line != NULL && *skipwhite(line) != NUL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3247 && !(*line == '#' && (line == cctx.ctx_line_start
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3248 || VIM_ISWHITE(line[-1]))))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3249 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3250 semsg(_(e_trailing_characters_str), line);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3251 goto erret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3252 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3253 else if (line != NULL && vim9_bad_comment(skipwhite(line)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3254 goto erret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3255 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3256 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3257 line = next_line_from_context(&cctx, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3258 if (cctx.ctx_lnum >= ufunc->uf_lines.ga_len)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3259 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3260 // beyond the last line
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3261 #ifdef FEAT_PROFILE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3262 if (cctx.ctx_skip != SKIP_YES)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3263 may_generate_prof_end(&cctx, prof_lnum);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3264 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3265 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3266 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3267 // Make a copy, splitting off nextcmd and removing trailing spaces
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3268 // may change it.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3269 if (line != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3270 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3271 line = vim_strsave(line);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3272 if (ga_add_string(&lines_to_free, line) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3273 goto erret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3274 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3275 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3276
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3277 CLEAR_FIELD(ea);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3278 ea.cmdlinep = &line;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3279 ea.cmd = skipwhite(line);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3280 ea.skip = cctx.ctx_skip == SKIP_YES;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3281
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3282 if (*ea.cmd == '#')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3283 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3284 // "#" starts a comment, but "#{" is an error
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3285 if (vim9_bad_comment(ea.cmd))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3286 goto erret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3287 line = (char_u *)"";
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3288 continue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3289 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3290
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3291 #ifdef FEAT_PROFILE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3292 if (cctx.ctx_compile_type == CT_PROFILE && cctx.ctx_lnum != prof_lnum
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3293 && cctx.ctx_skip != SKIP_YES)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3294 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3295 may_generate_prof_end(&cctx, prof_lnum);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3296
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3297 prof_lnum = cctx.ctx_lnum;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3298 generate_instr(&cctx, ISN_PROF_START);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3299 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3300 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3301 if (cctx.ctx_compile_type == CT_DEBUG && cctx.ctx_lnum != debug_lnum
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3302 && cctx.ctx_skip != SKIP_YES)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3303 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3304 debug_lnum = cctx.ctx_lnum;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3305 generate_instr_debug(&cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3306 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3307 cctx.ctx_prev_lnum = cctx.ctx_lnum + 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3308
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3309 // Some things can be recognized by the first character.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3310 switch (*ea.cmd)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3311 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3312 case '}':
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3313 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3314 // "}" ends a block scope
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3315 scopetype_T stype = cctx.ctx_scope == NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3316 ? NO_SCOPE : cctx.ctx_scope->se_type;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3317
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3318 if (stype == BLOCK_SCOPE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3319 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3320 compile_endblock(&cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3321 line = ea.cmd;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3322 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3323 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3324 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3325 emsg(_(e_using_rcurly_outside_if_block_scope));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3326 goto erret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3327 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3328 if (line != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3329 line = skipwhite(ea.cmd + 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3330 continue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3331 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3332
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3333 case '{':
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3334 // "{" starts a block scope
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3335 // "{'a': 1}->func() is something else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3336 if (ends_excmd(*skipwhite(ea.cmd + 1)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3337 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3338 line = compile_block(ea.cmd, &cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3339 continue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3340 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3341 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3342 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3343
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3344 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3345 * COMMAND MODIFIERS
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3346 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3347 cctx.ctx_has_cmdmod = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3348 if (parse_command_modifiers(&ea, &errormsg, &local_cmdmod, FALSE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3349 == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3350 goto erret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3351 generate_cmdmods(&cctx, &local_cmdmod);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3352 undo_cmdmod(&local_cmdmod);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3353
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3354 // Check if there was a colon after the last command modifier or before
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3355 // the current position.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3356 for (p = ea.cmd; p >= line; --p)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3357 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3358 if (*p == ':')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3359 starts_with_colon = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3360 if (p < ea.cmd && !VIM_ISWHITE(*p))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3361 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3362 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3363
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3364 // Skip ":call" to get to the function name, unless using :legacy
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3365 p = ea.cmd;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3366 if (!(local_cmdmod.cmod_flags & CMOD_LEGACY))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3367 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3368 if (checkforcmd(&ea.cmd, "call", 3))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3369 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3370 if (*ea.cmd == '(')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3371 // not for "call()"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3372 ea.cmd = p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3373 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3374 ea.cmd = skipwhite(ea.cmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3375 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3376
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3377 if (!starts_with_colon)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3378 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3379 int assign;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3380
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3381 // Check for assignment after command modifiers.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3382 assign = may_compile_assignment(&ea, &line, &cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3383 if (assign == OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3384 goto nextline;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3385 if (assign == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3386 goto erret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3387 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3388 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3389
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3390 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3391 * COMMAND after range
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3392 * 'text'->func() should not be confused with 'a mark
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3393 * 0z1234->func() should not be confused with a zero line number
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3394 * "++nr" and "--nr" are eval commands
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3395 * in "$ENV->func()" the "$" is not a range
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3396 * "123->func()" is a method call
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3397 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3398 cmd = ea.cmd;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3399 if ((*cmd != '$' || starts_with_colon)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3400 && (starts_with_colon
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3401 || !(*cmd == '\''
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3402 || (cmd[0] == '0' && cmd[1] == 'z')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3403 || (cmd[0] != NUL && cmd[0] == cmd[1]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3404 && (*cmd == '+' || *cmd == '-'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3405 || number_method(cmd))))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3406 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3407 ea.cmd = skip_range(ea.cmd, TRUE, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3408 if (ea.cmd > cmd)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3409 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3410 if (!starts_with_colon
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3411 && !(local_cmdmod.cmod_flags & CMOD_LEGACY))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3412 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3413 semsg(_(e_colon_required_before_range_str), cmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3414 goto erret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3415 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3416 ea.addr_count = 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3417 if (ends_excmd2(line, ea.cmd))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3418 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3419 // A range without a command: jump to the line.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3420 generate_EXEC(&cctx, ISN_EXECRANGE,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3421 vim_strnsave(cmd, ea.cmd - cmd));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3422 line = ea.cmd;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3423 goto nextline;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3424 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3425 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3426 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3427 p = find_ex_command(&ea, NULL,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3428 starts_with_colon || (local_cmdmod.cmod_flags & CMOD_LEGACY)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3429 ? NULL : item_exists, &cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3430
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3431 if (p == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3432 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3433 if (cctx.ctx_skip != SKIP_YES)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3434 semsg(_(e_ambiguous_use_of_user_defined_command_str), ea.cmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3435 goto erret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3436 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3437
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3438 // When using ":legacy cmd" always use compile_exec().
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3439 if (local_cmdmod.cmod_flags & CMOD_LEGACY)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3440 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3441 char_u *start = ea.cmd;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3442
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3443 switch (ea.cmdidx)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3444 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3445 case CMD_if:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3446 case CMD_elseif:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3447 case CMD_else:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3448 case CMD_endif:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3449 case CMD_for:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3450 case CMD_endfor:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3451 case CMD_continue:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3452 case CMD_break:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3453 case CMD_while:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3454 case CMD_endwhile:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3455 case CMD_try:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3456 case CMD_catch:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3457 case CMD_finally:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3458 case CMD_endtry:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3459 semsg(_(e_cannot_use_legacy_with_command_str), ea.cmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3460 goto erret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3461 default: break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3462 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3463
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3464 // ":legacy return expr" needs to be handled differently.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3465 if (checkforcmd(&start, "return", 4))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3466 ea.cmdidx = CMD_return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3467 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3468 ea.cmdidx = CMD_legacy;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3469 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3470
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3471 if (p == ea.cmd && ea.cmdidx != CMD_SIZE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3472 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3473 // "eval" is used for "val->func()" and "var" for "var = val", then
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3474 // "p" is equal to "ea.cmd" for a valid command.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3475 if (ea.cmdidx == CMD_eval || ea.cmdidx == CMD_var)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3476 ;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3477 else if (cctx.ctx_skip == SKIP_YES)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3478 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3479 line += STRLEN(line);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3480 goto nextline;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3481 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3482 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3483 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3484 semsg(_(e_command_not_recognized_str), ea.cmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3485 goto erret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3486 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3487 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3488
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3489 if ((cctx.ctx_had_return || cctx.ctx_had_throw)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3490 && ea.cmdidx != CMD_elseif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3491 && ea.cmdidx != CMD_else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3492 && ea.cmdidx != CMD_endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3493 && ea.cmdidx != CMD_endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3494 && ea.cmdidx != CMD_endwhile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3495 && ea.cmdidx != CMD_catch
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3496 && ea.cmdidx != CMD_finally
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3497 && ea.cmdidx != CMD_endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3498 && !ignore_unreachable_code_for_testing)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3499 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3500 semsg(_(e_unreachable_code_after_str),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3501 cctx.ctx_had_return ? "return" : "throw");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3502 goto erret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3503 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3504 cctx.ctx_had_throw = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3505
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3506 p = skipwhite(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3507 if (ea.cmdidx != CMD_SIZE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3508 && ea.cmdidx != CMD_write && ea.cmdidx != CMD_read)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3509 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3510 if (ea.cmdidx >= 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3511 ea.argt = excmd_get_argt(ea.cmdidx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3512 if ((ea.argt & EX_BANG) && *p == '!')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3513 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3514 ea.forceit = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3515 p = skipwhite(p + 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3516 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3517 if ((ea.argt & EX_RANGE) == 0 && ea.addr_count > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3518 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3519 emsg(_(e_no_range_allowed));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3520 goto erret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3521 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3522 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3523
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3524 switch (ea.cmdidx)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3525 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3526 case CMD_def:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3527 case CMD_function:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3528 ea.arg = p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3529 line = compile_nested_function(&ea, &cctx, &lines_to_free);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3530 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3531
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3532 case CMD_return:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3533 line = compile_return(p, check_return_type,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3534 local_cmdmod.cmod_flags & CMOD_LEGACY, &cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3535 cctx.ctx_had_return = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3536 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3537
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3538 case CMD_let:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3539 emsg(_(e_cannot_use_let_in_vim9_script));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3540 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3541 case CMD_var:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3542 case CMD_final:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3543 case CMD_const:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3544 case CMD_increment:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3545 case CMD_decrement:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3546 line = compile_assignment(p, &ea, ea.cmdidx, &cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3547 if (line == p)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3548 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3549 emsg(_(e_invalid_assignment));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3550 line = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3551 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3552 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3553
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3554 case CMD_unlet:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3555 case CMD_unlockvar:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3556 case CMD_lockvar:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3557 line = compile_unletlock(p, &ea, &cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3558 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3559
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3560 case CMD_import:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3561 emsg(_(e_import_can_only_be_used_in_script));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3562 line = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3563 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3564
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3565 case CMD_if:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3566 line = compile_if(p, &cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3567 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3568 case CMD_elseif:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3569 line = compile_elseif(p, &cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3570 cctx.ctx_had_return = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3571 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3572 case CMD_else:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3573 line = compile_else(p, &cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3574 cctx.ctx_had_return = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3575 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3576 case CMD_endif:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3577 line = compile_endif(p, &cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3578 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3579
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3580 case CMD_while:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3581 line = compile_while(p, &cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3582 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3583 case CMD_endwhile:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3584 line = compile_endwhile(p, &cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3585 cctx.ctx_had_return = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3586 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3587
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3588 case CMD_for:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3589 line = compile_for(p, &cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3590 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3591 case CMD_endfor:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3592 line = compile_endfor(p, &cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3593 cctx.ctx_had_return = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3594 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3595 case CMD_continue:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3596 line = compile_continue(p, &cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3597 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3598 case CMD_break:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3599 line = compile_break(p, &cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3600 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3601
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3602 case CMD_try:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3603 line = compile_try(p, &cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3604 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3605 case CMD_catch:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3606 line = compile_catch(p, &cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3607 cctx.ctx_had_return = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3608 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3609 case CMD_finally:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3610 line = compile_finally(p, &cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3611 cctx.ctx_had_return = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3612 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3613 case CMD_endtry:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3614 line = compile_endtry(p, &cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3615 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3616 case CMD_throw:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3617 line = compile_throw(p, &cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3618 cctx.ctx_had_throw = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3619 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3620
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3621 case CMD_eval:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3622 line = compile_eval(p, &cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3623 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3624
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3625 case CMD_defer:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3626 line = compile_defer(p, &cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3627 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3628
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3629 #ifdef HAS_MESSAGE_WINDOW
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3630 case CMD_echowindow:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3631 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3632 long cmd_count = get_cmd_count(line, &ea);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3633 if (cmd_count < 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3634 line = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3635 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3636 line = compile_mult_expr(p, ea.cmdidx,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3637 cmd_count, &cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3638 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3639 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3640 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3641 case CMD_echo:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3642 case CMD_echon:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3643 case CMD_echoconsole:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3644 case CMD_echoerr:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3645 case CMD_echomsg:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3646 case CMD_execute:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3647 line = compile_mult_expr(p, ea.cmdidx, 0, &cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3648 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3649
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3650 case CMD_put:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3651 ea.cmd = cmd;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3652 line = compile_put(p, &ea, &cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3653 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3654
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3655 case CMD_substitute:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3656 if (check_global_and_subst(ea.cmd, p) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3657 goto erret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3658 if (cctx.ctx_skip == SKIP_YES)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3659 line = (char_u *)"";
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3660 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3661 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3662 ea.arg = p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3663 line = compile_substitute(line, &ea, &cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3664 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3665 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3666
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3667 case CMD_redir:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3668 ea.arg = p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3669 line = compile_redir(line, &ea, &cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3670 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3671
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3672 case CMD_cexpr:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3673 case CMD_lexpr:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3674 case CMD_caddexpr:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3675 case CMD_laddexpr:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3676 case CMD_cgetexpr:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3677 case CMD_lgetexpr:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3678 #ifdef FEAT_QUICKFIX
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3679 ea.arg = p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3680 line = compile_cexpr(line, &ea, &cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3681 #else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3682 ex_ni(&ea);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3683 line = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3684 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3685 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3686
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3687 case CMD_append:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3688 case CMD_change:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3689 case CMD_insert:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3690 case CMD_k:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3691 case CMD_t:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3692 case CMD_xit:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3693 not_in_vim9(&ea);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3694 goto erret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3695
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3696 case CMD_SIZE:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3697 if (cctx.ctx_skip != SKIP_YES)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3698 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3699 semsg(_(e_invalid_command_str), ea.cmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3700 goto erret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3701 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3702 // We don't check for a next command here.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3703 line = (char_u *)"";
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3704 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3705
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3706 case CMD_lua:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3707 case CMD_mzscheme:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3708 case CMD_perl:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3709 case CMD_py3:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3710 case CMD_python3:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3711 case CMD_python:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3712 case CMD_pythonx:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3713 case CMD_ruby:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3714 case CMD_tcl:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3715 ea.arg = p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3716 if (vim_strchr(line, '\n') == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3717 line = compile_exec(line, &ea, &cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3718 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3719 // heredoc lines have been concatenated with NL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3720 // characters in get_function_body()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3721 line = compile_script(line, &cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3722 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3723
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3724 case CMD_vim9script:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3725 if (cctx.ctx_skip != SKIP_YES)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3726 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3727 emsg(_(e_vim9script_can_only_be_used_in_script));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3728 goto erret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3729 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3730 line = (char_u *)"";
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3731 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3732
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3733 case CMD_global:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3734 if (check_global_and_subst(ea.cmd, p) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3735 goto erret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3736 // FALLTHROUGH
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3737 default:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3738 // Not recognized, execute with do_cmdline_cmd().
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3739 ea.arg = p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3740 line = compile_exec(line, &ea, &cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3741 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3742 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3743 nextline:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3744 if (line == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3745 goto erret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3746 line = skipwhite(line);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3747
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3748 // Undo any command modifiers.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3749 generate_undo_cmdmods(&cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3750
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3751 if (cctx.ctx_type_stack.ga_len < 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3752 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3753 iemsg("Type stack underflow");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3754 goto erret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3755 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3756 } // END of the loop over all the function body lines.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3757
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3758 if (cctx.ctx_scope != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3759 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3760 if (cctx.ctx_scope->se_type == IF_SCOPE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3761 emsg(_(e_missing_endif));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3762 else if (cctx.ctx_scope->se_type == WHILE_SCOPE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3763 emsg(_(e_missing_endwhile));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3764 else if (cctx.ctx_scope->se_type == FOR_SCOPE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3765 emsg(_(e_missing_endfor));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3766 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3767 emsg(_(e_missing_rcurly));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3768 goto erret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3769 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3770
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3771 // TODO: if a function ends in "throw" but there was a return elsewhere we
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3772 // should not assume the return type is "void".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3773 if (!cctx.ctx_had_return && !cctx.ctx_had_throw)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3774 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3775 if (ufunc->uf_ret_type->tt_type == VAR_UNKNOWN)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3776 ufunc->uf_ret_type = &t_void;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3777 else if (ufunc->uf_ret_type->tt_type != VAR_VOID
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3778 && (ufunc->uf_flags & FC_NEW) != FC_NEW)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3779 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3780 emsg(_(e_missing_return_statement));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3781 goto erret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3782 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3783
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3784 // Return void if there is no return at the end.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3785 // For a constructor return the object.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3786 if ((ufunc->uf_flags & FC_NEW) == FC_NEW)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3787 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3788 generate_instr(&cctx, ISN_RETURN_OBJECT);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3789 ufunc->uf_ret_type = &ufunc->uf_class->class_object_type;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3790 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3791 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3792 generate_instr(&cctx, ISN_RETURN_VOID);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3793 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3794
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3795 // When compiled with ":silent!" and there was an error don't consider the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3796 // function compiled.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3797 if (emsg_silent == 0 || did_emsg_silent == did_emsg_silent_before)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3798 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3799 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3800 + ufunc->uf_dfunc_idx;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3801 dfunc->df_deleted = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3802 dfunc->df_script_seq = current_sctx.sc_seq;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3803 #ifdef FEAT_PROFILE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3804 if (cctx.ctx_compile_type == CT_PROFILE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3805 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3806 dfunc->df_instr_prof = instr->ga_data;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3807 dfunc->df_instr_prof_count = instr->ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3808 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3809 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3810 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3811 if (cctx.ctx_compile_type == CT_DEBUG)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3812 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3813 dfunc->df_instr_debug = instr->ga_data;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3814 dfunc->df_instr_debug_count = instr->ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3815 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3816 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3817 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3818 dfunc->df_instr = instr->ga_data;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3819 dfunc->df_instr_count = instr->ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3820 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3821 dfunc->df_varcount = dfunc->df_var_names.ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3822 dfunc->df_has_closure = cctx.ctx_has_closure;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3823
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3824 if (cctx.ctx_outer_used)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3825 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3826 ufunc->uf_flags |= FC_CLOSURE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3827 if (outer_cctx != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3828 ++outer_cctx->ctx_closure_count;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3829 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3830
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3831 ufunc->uf_def_status = UF_COMPILED;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3832 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3833
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3834 ret = OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3835
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3836 erret:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3837 if (ufunc->uf_def_status == UF_COMPILING)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3838 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3839 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3840 + ufunc->uf_dfunc_idx;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3841
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3842 // Compiling aborted, free the generated instructions.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3843 clear_instr_ga(instr);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3844 VIM_CLEAR(dfunc->df_name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3845 ga_clear_strings(&dfunc->df_var_names);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3846
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3847 // If using the last entry in the table and it was added above, we
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3848 // might as well remove it.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3849 if (!dfunc->df_deleted && new_def_function
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3850 && ufunc->uf_dfunc_idx == def_functions.ga_len - 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3851 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3852 --def_functions.ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3853 ufunc->uf_dfunc_idx = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3854 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3855 ufunc->uf_def_status = UF_COMPILE_ERROR;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3856
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3857 while (cctx.ctx_scope != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3858 drop_scope(&cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3859
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3860 if (errormsg != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3861 emsg(errormsg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3862 else if (did_emsg == did_emsg_before)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3863 emsg(_(e_compiling_def_function_failed));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3864 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3865
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3866 if (cctx.ctx_redir_lhs.lhs_name != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3867 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3868 if (ret == OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3869 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3870 emsg(_(e_missing_redir_end));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3871 ret = FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3872 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3873 vim_free(cctx.ctx_redir_lhs.lhs_name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3874 vim_free(cctx.ctx_redir_lhs.lhs_whole);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3875 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3876
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3877 current_sctx = save_current_sctx;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3878 estack_compiling = save_estack_compiling;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3879 cmdmod.cmod_flags = save_cmod_flags;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3880 if (do_estack_push)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3881 estack_pop();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3882
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3883 ga_clear_strings(&lines_to_free);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3884 free_locals(&cctx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3885 ga_clear(&cctx.ctx_type_stack);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3886 return ret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3887 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3888
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3889 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3890 set_function_type(ufunc_T *ufunc)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3891 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3892 int varargs = ufunc->uf_va_name != NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3893 int argcount = ufunc->uf_args.ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3894
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3895 // Create a type for the function, with the return type and any
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3896 // argument types.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3897 // A vararg is included in uf_args.ga_len but not in uf_arg_types.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3898 // The type is included in "tt_args".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3899 if (argcount > 0 || varargs)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3900 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3901 if (ufunc->uf_type_list.ga_itemsize == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3902 ga_init2(&ufunc->uf_type_list, sizeof(type_T *), 10);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3903 ufunc->uf_func_type = alloc_func_type(ufunc->uf_ret_type,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3904 argcount, &ufunc->uf_type_list);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3905 // Add argument types to the function type.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3906 if (func_type_add_arg_types(ufunc->uf_func_type,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3907 argcount + varargs,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3908 &ufunc->uf_type_list) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3909 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3910 ufunc->uf_func_type->tt_argcount = argcount + varargs;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3911 ufunc->uf_func_type->tt_min_argcount =
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3912 argcount - ufunc->uf_def_args.ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3913 if (ufunc->uf_arg_types == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3914 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3915 int i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3916
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3917 // lambda does not have argument types.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3918 for (i = 0; i < argcount; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3919 ufunc->uf_func_type->tt_args[i] = &t_any;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3920 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3921 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3922 mch_memmove(ufunc->uf_func_type->tt_args,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3923 ufunc->uf_arg_types, sizeof(type_T *) * argcount);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3924 if (varargs)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3925 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3926 ufunc->uf_func_type->tt_args[argcount] =
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3927 ufunc->uf_va_type == NULL ? &t_list_any : ufunc->uf_va_type;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3928 ufunc->uf_func_type->tt_flags = TTFLAG_VARARGS;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3929 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3930 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3931 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3932 // No arguments, can use a predefined type.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3933 ufunc->uf_func_type = get_func_type(ufunc->uf_ret_type,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3934 argcount, &ufunc->uf_type_list);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3935 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3936
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3937 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3938 * Free all instructions for "dfunc" except df_name.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3939 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3940 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3941 delete_def_function_contents(dfunc_T *dfunc, int mark_deleted)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3942 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3943 int idx;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3944
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3945 // In same cases the instructions may refer to a class in which the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3946 // function is defined and unreferencing the class may call back here
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3947 // recursively. Set the df_delete_busy to avoid problems.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3948 if (dfunc->df_delete_busy)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3949 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3950 dfunc->df_delete_busy = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3951
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3952 ga_clear(&dfunc->df_def_args_isn);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3953 ga_clear_strings(&dfunc->df_var_names);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3954
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3955 if (dfunc->df_instr != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3956 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3957 for (idx = 0; idx < dfunc->df_instr_count; ++idx)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3958 delete_instr(dfunc->df_instr + idx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3959 VIM_CLEAR(dfunc->df_instr);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3960 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3961 if (dfunc->df_instr_debug != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3962 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3963 for (idx = 0; idx < dfunc->df_instr_debug_count; ++idx)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3964 delete_instr(dfunc->df_instr_debug + idx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3965 VIM_CLEAR(dfunc->df_instr_debug);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3966 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3967 #ifdef FEAT_PROFILE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3968 if (dfunc->df_instr_prof != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3969 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3970 for (idx = 0; idx < dfunc->df_instr_prof_count; ++idx)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3971 delete_instr(dfunc->df_instr_prof + idx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3972 VIM_CLEAR(dfunc->df_instr_prof);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3973 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3974 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3975
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3976 if (mark_deleted)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3977 dfunc->df_deleted = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3978 if (dfunc->df_ufunc != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3979 dfunc->df_ufunc->uf_def_status = UF_NOT_COMPILED;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3980
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3981 dfunc->df_delete_busy = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3982 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3983
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3984 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3985 * When a user function is deleted, clear the contents of any associated def
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3986 * function, unless another user function still uses it.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3987 * The position in def_functions can be re-used.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3988 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3989 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3990 unlink_def_function(ufunc_T *ufunc)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3991 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3992 if (ufunc->uf_dfunc_idx <= 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3993 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3994
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3995 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3996 + ufunc->uf_dfunc_idx;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3997
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3998 if (--dfunc->df_refcount <= 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
3999 delete_def_function_contents(dfunc, TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
4000 ufunc->uf_def_status = UF_NOT_COMPILED;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
4001 ufunc->uf_dfunc_idx = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
4002 if (dfunc->df_ufunc == ufunc)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
4003 dfunc->df_ufunc = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
4004 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
4005
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
4006 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
4007 * Used when a user function refers to an existing dfunc.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
4008 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
4009 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
4010 link_def_function(ufunc_T *ufunc)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
4011 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
4012 if (ufunc->uf_dfunc_idx <= 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
4013 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
4014
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
4015 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
4016 + ufunc->uf_dfunc_idx;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
4017
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
4018 ++dfunc->df_refcount;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
4019 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
4020
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
4021 #if defined(EXITFREE) || defined(PROTO)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
4022 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
4023 * Free all functions defined with ":def".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
4024 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
4025 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
4026 free_def_functions(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
4027 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
4028 int idx;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
4029
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
4030 for (idx = 0; idx < def_functions.ga_len; ++idx)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
4031 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
4032 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data) + idx;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
4033
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
4034 delete_def_function_contents(dfunc, TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
4035 vim_free(dfunc->df_name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
4036 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
4037
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
4038 ga_clear(&def_functions);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
4039 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
4040 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
4041
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
4042
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32475
diff changeset
4043 #endif // FEAT_EVAL