comparison src/vim9expr.c @ 26980:8796f1384750 v8.2.4019

patch 8.2.4019: Vim9: import mechanism is too complicated Commit: https://github.com/vim/vim/commit/d5f400c607182db6d4fbe2964471d796277f67e8 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Jan 6 21:10:28 2022 +0000 patch 8.2.4019: Vim9: import mechanism is too complicated Problem: Vim9: import mechanism is too complicated. Solution: Do not use the Javascript mechanism but a much simpler one.
author Bram Moolenaar <Bram@vim.org>
date Thu, 06 Jan 2022 22:15:04 +0100
parents ccb9be1cdd71
children fc19375787dd
comparison
equal deleted inserted replaced
26979:2fb4968983af 26980:8796f1384750
238 int 238 int
239 compile_load_scriptvar( 239 compile_load_scriptvar(
240 cctx_T *cctx, 240 cctx_T *cctx,
241 char_u *name, // variable NUL terminated 241 char_u *name, // variable NUL terminated
242 char_u *start, // start of variable 242 char_u *start, // start of variable
243 char_u **end, // end of variable 243 char_u **end, // end of variable, may be NULL
244 int error) // when TRUE may give error 244 int error) // when TRUE may give error
245 { 245 {
246 scriptitem_T *si; 246 scriptitem_T *si;
247 int idx; 247 int idx;
248 imported_T *import; 248 imported_T *import;
264 generate_VIM9SCRIPT(cctx, ISN_LOADSCRIPT, 264 generate_VIM9SCRIPT(cctx, ISN_LOADSCRIPT,
265 current_sctx.sc_sid, idx, sv->sv_type); 265 current_sctx.sc_sid, idx, sv->sv_type);
266 return OK; 266 return OK;
267 } 267 }
268 268
269 import = find_imported(name, 0, cctx); 269 import = end == NULL ? NULL : find_imported(name, 0, cctx);
270 if (import != NULL) 270 if (import != NULL)
271 { 271 {
272 if (import->imp_flags & IMP_FLAGS_STAR) 272 char_u *p = skipwhite(*end);
273 { 273 char_u *exp_name;
274 char_u *p = skipwhite(*end); 274 int cc;
275 char_u *exp_name; 275 ufunc_T *ufunc;
276 int cc; 276 type_T *type;
277 ufunc_T *ufunc; 277
278 type_T *type; 278 // Need to lookup the member.
279 279 if (*p != '.')
280 // Used "import * as Name", need to lookup the member. 280 {
281 if (*p != '.') 281 semsg(_(e_expected_dot_after_name_str), start);
282 { 282 return FAIL;
283 semsg(_(e_expected_dot_after_name_str), start); 283 }
284 return FAIL; 284 ++p;
285 } 285 if (VIM_ISWHITE(*p))
286 {
287 emsg(_(e_no_white_space_allowed_after_dot));
288 return FAIL;
289 }
290
291 // isolate one name
292 exp_name = p;
293 while (eval_isnamec(*p))
286 ++p; 294 ++p;
287 if (VIM_ISWHITE(*p)) 295 cc = *p;
288 { 296 *p = NUL;
289 emsg(_(e_no_white_space_allowed_after_dot)); 297
290 return FAIL; 298 idx = find_exported(import->imp_sid, exp_name, &ufunc, &type,
291 }
292
293 // isolate one name
294 exp_name = p;
295 while (eval_isnamec(*p))
296 ++p;
297 cc = *p;
298 *p = NUL;
299
300 idx = find_exported(import->imp_sid, exp_name, &ufunc, &type,
301 cctx, TRUE); 299 cctx, TRUE);
302 *p = cc; 300 *p = cc;
303 p = skipwhite(p); 301 p = skipwhite(p);
304 *end = p; 302 *end = p;
305 303
306 if (idx < 0) 304 if (idx < 0)
307 { 305 {
308 if (*p == '(' && ufunc != NULL) 306 if (ufunc != NULL)
309 { 307 {
310 generate_PUSHFUNC(cctx, ufunc->uf_name, import->imp_type); 308 // function call or function reference
311 return OK; 309 generate_PUSHFUNC(cctx, ufunc->uf_name, NULL);
312 } 310 return OK;
313 return FAIL; 311 }
314 } 312 return FAIL;
315 313 }
316 generate_VIM9SCRIPT(cctx, ISN_LOADSCRIPT, 314
317 import->imp_sid, 315 generate_VIM9SCRIPT(cctx, ISN_LOADSCRIPT,
318 idx, 316 import->imp_sid,
319 type); 317 idx,
320 } 318 type);
321 else if (import->imp_funcname != NULL)
322 generate_PUSHFUNC(cctx, import->imp_funcname, import->imp_type);
323 else
324 generate_VIM9SCRIPT(cctx, ISN_LOADSCRIPT,
325 import->imp_sid,
326 import->imp_var_vals_idx,
327 import->imp_type);
328 return OK; 319 return OK;
329 } 320 }
330 321
331 if (error) 322 if (error)
332 semsg(_(e_item_not_found_str), name); 323 semsg(_(e_item_not_found_str), name);