Mercurial > vim
comparison src/eval.c @ 446:7472c565592a v7.0117
updated for version 7.0117
author | vimboss |
---|---|
date | Wed, 27 Jul 2005 21:13:01 +0000 |
parents | c773cb978acf |
children | dd9db57ee7ce |
comparison
equal
deleted
inserted
replaced
445:c773cb978acf | 446:7472c565592a |
---|---|
637 static int get_var_tv __ARGS((char_u *name, int len, typval_T *rettv, int verbose)); | 637 static int get_var_tv __ARGS((char_u *name, int len, typval_T *rettv, int verbose)); |
638 static int handle_subscript __ARGS((char_u **arg, typval_T *rettv, int evaluate, int verbose)); | 638 static int handle_subscript __ARGS((char_u **arg, typval_T *rettv, int evaluate, int verbose)); |
639 static typval_T *alloc_tv __ARGS((void)); | 639 static typval_T *alloc_tv __ARGS((void)); |
640 static typval_T *alloc_string_tv __ARGS((char_u *string)); | 640 static typval_T *alloc_string_tv __ARGS((char_u *string)); |
641 static void free_tv __ARGS((typval_T *varp)); | 641 static void free_tv __ARGS((typval_T *varp)); |
642 static void clear_tv __ARGS((typval_T *varp)); | |
643 static void init_tv __ARGS((typval_T *varp)); | 642 static void init_tv __ARGS((typval_T *varp)); |
644 static long get_tv_number __ARGS((typval_T *varp)); | 643 static long get_tv_number __ARGS((typval_T *varp)); |
645 static long get_tv_number_chk __ARGS((typval_T *varp, int *denote)); | 644 static long get_tv_number_chk __ARGS((typval_T *varp, int *denote)); |
646 static linenr_T get_tv_lnum __ARGS((typval_T *argvars)); | 645 static linenr_T get_tv_lnum __ARGS((typval_T *argvars)); |
647 static char_u *get_tv_string __ARGS((typval_T *varp)); | 646 static char_u *get_tv_string __ARGS((typval_T *varp)); |
681 # ifdef __BORLANDC__ | 680 # ifdef __BORLANDC__ |
682 _RTLENTRYF | 681 _RTLENTRYF |
683 # endif | 682 # endif |
684 prof_self_cmp __ARGS((const void *s1, const void *s2)); | 683 prof_self_cmp __ARGS((const void *s1, const void *s2)); |
685 #endif | 684 #endif |
686 static int script_autoload __ARGS((char_u *name)); | 685 static int script_autoload __ARGS((char_u *name, int reload)); |
687 static char_u *autoload_name __ARGS((char_u *name)); | 686 static char_u *autoload_name __ARGS((char_u *name)); |
688 static void cat_func_name __ARGS((char_u *buf, ufunc_T *fp)); | 687 static void cat_func_name __ARGS((char_u *buf, ufunc_T *fp)); |
689 static void func_free __ARGS((ufunc_T *fp)); | 688 static void func_free __ARGS((ufunc_T *fp)); |
690 static void func_unref __ARGS((char_u *name)); | 689 static void func_unref __ARGS((char_u *name)); |
691 static void func_ref __ARGS((char_u *name)); | 690 static void func_ref __ARGS((char_u *name)); |
1305 if (li == NULL) | 1304 if (li == NULL) |
1306 return -1; | 1305 return -1; |
1307 return get_tv_number(&li->li_tv); | 1306 return get_tv_number(&li->li_tv); |
1308 } | 1307 } |
1309 #endif | 1308 #endif |
1309 | |
1310 /* | |
1311 * Top level evaluation function, | |
1312 */ | |
1313 typval_T * | |
1314 eval_expr(arg, nextcmd) | |
1315 char_u *arg; | |
1316 char_u **nextcmd; | |
1317 { | |
1318 typval_T *tv; | |
1319 | |
1320 tv = (typval_T *)alloc(sizeof(typval_T)); | |
1321 if (!tv) | |
1322 return NULL; | |
1323 | |
1324 if (eval0(arg, tv, nextcmd, TRUE) == FAIL) | |
1325 { | |
1326 vim_free(tv); | |
1327 return NULL; | |
1328 } | |
1329 | |
1330 return tv; | |
1331 } | |
1332 | |
1310 | 1333 |
1311 #if (defined(FEAT_USR_CMDS) && defined(FEAT_CMDL_COMPL)) || defined(PROTO) | 1334 #if (defined(FEAT_USR_CMDS) && defined(FEAT_CMDL_COMPL)) || defined(PROTO) |
1312 /* | 1335 /* |
1313 * Call some vimL function and return the result in "*rettv". | 1336 * Call some vimL function and return the result in "*rettv". |
1314 * Uses argv[argc] for the function arguments. | 1337 * Uses argv[argc] for the function arguments. |
7099 /* executed an autocommand, search for the function again */ | 7122 /* executed an autocommand, search for the function again */ |
7100 fp = find_func(fname); | 7123 fp = find_func(fname); |
7101 } | 7124 } |
7102 #endif | 7125 #endif |
7103 /* Try loading a package. */ | 7126 /* Try loading a package. */ |
7104 if (fp == NULL && script_autoload(fname) && !aborting()) | 7127 if (fp == NULL && script_autoload(fname, TRUE) && !aborting()) |
7105 { | 7128 { |
7106 /* loaded a package, search for the function again */ | 7129 /* loaded a package, search for the function again */ |
7107 fp = find_func(fname); | 7130 fp = find_func(fname); |
7108 } | 7131 } |
7109 | 7132 |
15526 } | 15549 } |
15527 | 15550 |
15528 /* | 15551 /* |
15529 * Free the memory for a variable value and set the value to NULL or 0. | 15552 * Free the memory for a variable value and set the value to NULL or 0. |
15530 */ | 15553 */ |
15531 static void | 15554 void |
15532 clear_tv(varp) | 15555 clear_tv(varp) |
15533 typval_T *varp; | 15556 typval_T *varp; |
15534 { | 15557 { |
15535 if (varp != NULL) | 15558 if (varp != NULL) |
15536 { | 15559 { |
15772 | 15795 |
15773 hi = hash_find(ht, varname); | 15796 hi = hash_find(ht, varname); |
15774 if (HASHITEM_EMPTY(hi)) | 15797 if (HASHITEM_EMPTY(hi)) |
15775 { | 15798 { |
15776 /* For global variables we may try auto-loading the script. If it | 15799 /* For global variables we may try auto-loading the script. If it |
15777 * worked find the variable again. */ | 15800 * worked find the variable again. Don't auto-load a script if it was |
15801 * loaded already, otherwise it would be loaded every time when | |
15802 * checking if a function name is a Funcref variable. */ | |
15778 if (ht == &globvarht && !writing | 15803 if (ht == &globvarht && !writing |
15779 && script_autoload(varname) && !aborting()) | 15804 && script_autoload(varname, FALSE) && !aborting()) |
15780 hi = hash_find(ht, varname); | 15805 hi = hash_find(ht, varname); |
15781 if (HASHITEM_EMPTY(hi)) | 15806 if (HASHITEM_EMPTY(hi)) |
15782 return NULL; | 15807 return NULL; |
15783 } | 15808 } |
15784 return HI2DI(hi); | 15809 return HI2DI(hi); |
17564 return profile_cmp(&p1->uf_tm_self, &p2->uf_tm_self); | 17589 return profile_cmp(&p1->uf_tm_self, &p2->uf_tm_self); |
17565 } | 17590 } |
17566 | 17591 |
17567 #endif | 17592 #endif |
17568 | 17593 |
17594 /* The names of packages that once were loaded is remembered. */ | |
17595 static garray_T ga_loaded = {0, 0, sizeof(char_u *), 4, NULL}; | |
17596 | |
17569 /* | 17597 /* |
17570 * If "name" has a package name try autoloading the script for it. | 17598 * If "name" has a package name try autoloading the script for it. |
17571 * Return TRUE if a package was loaded. | 17599 * Return TRUE if a package was loaded. |
17572 */ | 17600 */ |
17573 static int | 17601 static int |
17574 script_autoload(name) | 17602 script_autoload(name, reload) |
17575 char_u *name; | 17603 char_u *name; |
17604 int reload; /* load script again when already loaded */ | |
17576 { | 17605 { |
17577 char_u *p; | 17606 char_u *p; |
17578 char_u *scriptname; | 17607 char_u *scriptname, *tofree; |
17579 int ret = FALSE; | 17608 int ret = FALSE; |
17580 | 17609 int i; |
17581 /* If there is no colon after name[1] there is no package name. */ | 17610 |
17611 /* If there is no '#' after name[0] there is no package name. */ | |
17582 p = vim_strchr(name, AUTOLOAD_CHAR); | 17612 p = vim_strchr(name, AUTOLOAD_CHAR); |
17583 if (p == NULL || p <= name + 2) | 17613 if (p == NULL || p == name) |
17584 return FALSE; | 17614 return FALSE; |
17585 | 17615 |
17586 /* Try loading the package from $VIMRUNTIME/autoload/<name>.vim */ | 17616 tofree = scriptname = autoload_name(name); |
17587 scriptname = autoload_name(name); | 17617 |
17588 if (cmd_runtime(scriptname, FALSE) == OK) | 17618 /* Find the name in the list of previously loaded package names. Skip |
17589 ret = TRUE; | 17619 * "autoload/", it's always the same. */ |
17590 | 17620 for (i = 0; i < ga_loaded.ga_len; ++i) |
17591 vim_free(scriptname); | 17621 if (STRCMP(((char_u **)ga_loaded.ga_data)[i] + 9, scriptname + 9) == 0) |
17622 break; | |
17623 if (!reload && i < ga_loaded.ga_len) | |
17624 ret = FALSE; /* was loaded already */ | |
17625 else | |
17626 { | |
17627 /* Remember the name if it wasn't loaded already. */ | |
17628 if (i == ga_loaded.ga_len && ga_grow(&ga_loaded, 1) == OK) | |
17629 { | |
17630 ((char_u **)ga_loaded.ga_data)[ga_loaded.ga_len++] = scriptname; | |
17631 tofree = NULL; | |
17632 } | |
17633 | |
17634 /* Try loading the package from $VIMRUNTIME/autoload/<name>.vim */ | |
17635 if (cmd_runtime(scriptname, FALSE) == OK) | |
17636 ret = TRUE; | |
17637 } | |
17638 | |
17639 vim_free(tofree); | |
17592 return ret; | 17640 return ret; |
17593 } | 17641 } |
17594 | 17642 |
17595 /* | 17643 /* |
17596 * Return the autoload script name for a function or variable name. | 17644 * Return the autoload script name for a function or variable name. |