annotate src/typval.c @ 24610:c1263588156b v8.2.2844

patch 8.2.2844: Vim9: memory leak when using searchpair() Commit: https://github.com/vim/vim/commit/24f720998f852dd1ba861ec67d56625a507b915e Author: Bram Moolenaar <Bram@vim.org> Date: Fri May 7 20:43:54 2021 +0200 patch 8.2.2844: Vim9: memory leak when using searchpair() Problem: Vim9: memory leak when using searchpair(). Solution: Free the v_instr field.
author Bram Moolenaar <Bram@vim.org>
date Fri, 07 May 2021 20:45:03 +0200
parents a4fda40e0bb9
children 07b3d21a8b4b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2 *
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 *
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 * typval.c: functions that deal with a typval
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 #include "vim.h"
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16 #if defined(FEAT_EVAL) || defined(PROTO)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19 * Allocate memory for a variable type-value, and make it empty (0 or NULL
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 * value).
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 typval_T *
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23 alloc_tv(void)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25 return ALLOC_CLEAR_ONE(typval_T);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29 * Allocate memory for a variable type-value, and assign a string to it.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30 * The string "s" must have been allocated, it is consumed.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31 * Return NULL for out of memory, the variable otherwise.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33 typval_T *
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34 alloc_string_tv(char_u *s)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 typval_T *rettv;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 rettv = alloc_tv();
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 if (rettv != NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41 rettv->v_type = VAR_STRING;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42 rettv->vval.v_string = s;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45 vim_free(s);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 return rettv;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50 * Free the memory for a variable type-value.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 void
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53 free_tv(typval_T *varp)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55 if (varp != NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57 switch (varp->v_type)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59 case VAR_FUNC:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 func_unref(varp->vval.v_string);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61 // FALLTHROUGH
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62 case VAR_STRING:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63 vim_free(varp->vval.v_string);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 case VAR_PARTIAL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66 partial_unref(varp->vval.v_partial);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68 case VAR_BLOB:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 blob_unref(varp->vval.v_blob);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71 case VAR_LIST:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72 list_unref(varp->vval.v_list);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74 case VAR_DICT:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75 dict_unref(varp->vval.v_dict);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77 case VAR_JOB:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78 #ifdef FEAT_JOB_CHANNEL
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79 job_unref(varp->vval.v_job);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81 #endif
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82 case VAR_CHANNEL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 #ifdef FEAT_JOB_CHANNEL
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84 channel_unref(varp->vval.v_channel);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
85 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
86 #endif
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
87 case VAR_NUMBER:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88 case VAR_FLOAT:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89 case VAR_ANY:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
90 case VAR_UNKNOWN:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
91 case VAR_VOID:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
92 case VAR_BOOL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
93 case VAR_SPECIAL:
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24424
diff changeset
94 case VAR_INSTR:
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
95 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
96 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
97 vim_free(varp);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
98 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
99 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
100
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
101 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102 * Free the memory for a variable value and set the value to NULL or 0.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
103 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104 void
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105 clear_tv(typval_T *varp)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107 if (varp != NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109 switch (varp->v_type)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
110 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
111 case VAR_FUNC:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
112 func_unref(varp->vval.v_string);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
113 // FALLTHROUGH
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114 case VAR_STRING:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
115 VIM_CLEAR(varp->vval.v_string);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
116 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
117 case VAR_PARTIAL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
118 partial_unref(varp->vval.v_partial);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
119 varp->vval.v_partial = NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
120 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
121 case VAR_BLOB:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
122 blob_unref(varp->vval.v_blob);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
123 varp->vval.v_blob = NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
124 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
125 case VAR_LIST:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
126 list_unref(varp->vval.v_list);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
127 varp->vval.v_list = NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
128 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
129 case VAR_DICT:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
130 dict_unref(varp->vval.v_dict);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
131 varp->vval.v_dict = NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
132 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
133 case VAR_NUMBER:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
134 case VAR_BOOL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135 case VAR_SPECIAL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
136 varp->vval.v_number = 0;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
137 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
138 case VAR_FLOAT:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
139 #ifdef FEAT_FLOAT
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
140 varp->vval.v_float = 0.0;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
141 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
142 #endif
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
143 case VAR_JOB:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
144 #ifdef FEAT_JOB_CHANNEL
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
145 job_unref(varp->vval.v_job);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
146 varp->vval.v_job = NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
147 #endif
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
148 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
149 case VAR_CHANNEL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
150 #ifdef FEAT_JOB_CHANNEL
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
151 channel_unref(varp->vval.v_channel);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
152 varp->vval.v_channel = NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
153 #endif
24610
c1263588156b patch 8.2.2844: Vim9: memory leak when using searchpair()
Bram Moolenaar <Bram@vim.org>
parents: 24606
diff changeset
154 break;
c1263588156b patch 8.2.2844: Vim9: memory leak when using searchpair()
Bram Moolenaar <Bram@vim.org>
parents: 24606
diff changeset
155 case VAR_INSTR:
c1263588156b patch 8.2.2844: Vim9: memory leak when using searchpair()
Bram Moolenaar <Bram@vim.org>
parents: 24606
diff changeset
156 VIM_CLEAR(varp->vval.v_instr);
c1263588156b patch 8.2.2844: Vim9: memory leak when using searchpair()
Bram Moolenaar <Bram@vim.org>
parents: 24606
diff changeset
157 break;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
158 case VAR_UNKNOWN:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
159 case VAR_ANY:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
160 case VAR_VOID:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
161 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
162 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
163 varp->v_lock = 0;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
164 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
165 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
166
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
167 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
168 * Set the value of a variable to NULL without freeing items.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
169 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
170 void
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
171 init_tv(typval_T *varp)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
172 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
173 if (varp != NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
174 CLEAR_POINTER(varp);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
175 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
176
21851
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
177 static varnumber_T
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
178 tv_get_bool_or_number_chk(typval_T *varp, int *denote, int want_bool)
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
179 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
180 varnumber_T n = 0L;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
181
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
182 switch (varp->v_type)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
183 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
184 case VAR_NUMBER:
22405
0ef3ae4ec70e patch 8.2.1751: using 2 where bool is expected may throw an error
Bram Moolenaar <Bram@vim.org>
parents: 22298
diff changeset
185 if (in_vim9script() && want_bool && varp->vval.v_number != 0
21913
9fc27a955f00 patch 8.2.1506: Vim9: no error when using a number other than 0 or 1 as bool
Bram Moolenaar <Bram@vim.org>
parents: 21861
diff changeset
186 && varp->vval.v_number != 1)
9fc27a955f00 patch 8.2.1506: Vim9: no error when using a number other than 0 or 1 as bool
Bram Moolenaar <Bram@vim.org>
parents: 21861
diff changeset
187 {
9fc27a955f00 patch 8.2.1506: Vim9: no error when using a number other than 0 or 1 as bool
Bram Moolenaar <Bram@vim.org>
parents: 21861
diff changeset
188 semsg(_(e_using_number_as_bool_nr), varp->vval.v_number);
9fc27a955f00 patch 8.2.1506: Vim9: no error when using a number other than 0 or 1 as bool
Bram Moolenaar <Bram@vim.org>
parents: 21861
diff changeset
189 break;
9fc27a955f00 patch 8.2.1506: Vim9: no error when using a number other than 0 or 1 as bool
Bram Moolenaar <Bram@vim.org>
parents: 21861
diff changeset
190 }
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
191 return varp->vval.v_number;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
192 case VAR_FLOAT:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
193 #ifdef FEAT_FLOAT
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
194 emsg(_("E805: Using a Float as a Number"));
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
195 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
196 #endif
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
197 case VAR_FUNC:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
198 case VAR_PARTIAL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
199 emsg(_("E703: Using a Funcref as a Number"));
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
200 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
201 case VAR_STRING:
21831
d8422de73113 patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21425
diff changeset
202 if (in_vim9script())
d8422de73113 patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21425
diff changeset
203 {
22860
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22405
diff changeset
204 emsg_using_string_as(varp, !want_bool);
21831
d8422de73113 patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21425
diff changeset
205 break;
d8422de73113 patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21425
diff changeset
206 }
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
207 if (varp->vval.v_string != NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
208 vim_str2nr(varp->vval.v_string, NULL, NULL,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
209 STR2NR_ALL, &n, NULL, 0, FALSE);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
210 return n;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
211 case VAR_LIST:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
212 emsg(_("E745: Using a List as a Number"));
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
213 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
214 case VAR_DICT:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
215 emsg(_("E728: Using a Dictionary as a Number"));
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
216 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
217 case VAR_BOOL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
218 case VAR_SPECIAL:
21851
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
219 if (!want_bool && in_vim9script())
21831
d8422de73113 patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21425
diff changeset
220 {
22930
84567584951f patch 8.2.2012: Vim9: confusing error message when using bool wrongly
Bram Moolenaar <Bram@vim.org>
parents: 22860
diff changeset
221 if (varp->v_type == VAR_BOOL)
84567584951f patch 8.2.2012: Vim9: confusing error message when using bool wrongly
Bram Moolenaar <Bram@vim.org>
parents: 22860
diff changeset
222 emsg(_(e_using_bool_as_number));
84567584951f patch 8.2.2012: Vim9: confusing error message when using bool wrongly
Bram Moolenaar <Bram@vim.org>
parents: 22860
diff changeset
223 else
84567584951f patch 8.2.2012: Vim9: confusing error message when using bool wrongly
Bram Moolenaar <Bram@vim.org>
parents: 22860
diff changeset
224 emsg(_("E611: Using a Special as a Number"));
21831
d8422de73113 patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21425
diff changeset
225 break;
d8422de73113 patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21425
diff changeset
226 }
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
227 return varp->vval.v_number == VVAL_TRUE ? 1 : 0;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
228 case VAR_JOB:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
229 #ifdef FEAT_JOB_CHANNEL
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
230 emsg(_("E910: Using a Job as a Number"));
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
231 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
232 #endif
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
233 case VAR_CHANNEL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
234 #ifdef FEAT_JOB_CHANNEL
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
235 emsg(_("E913: Using a Channel as a Number"));
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
236 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
237 #endif
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
238 case VAR_BLOB:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
239 emsg(_("E974: Using a Blob as a Number"));
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
240 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
241 case VAR_UNKNOWN:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
242 case VAR_ANY:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
243 case VAR_VOID:
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24424
diff changeset
244 case VAR_INSTR:
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
245 internal_error_no_abort("tv_get_number(UNKNOWN)");
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
246 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
247 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
248 if (denote == NULL) // useful for values that must be unsigned
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
249 n = -1;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
250 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
251 *denote = TRUE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
252 return n;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
253 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
254
21851
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
255 /*
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
256 * Get the number value of a variable.
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
257 * If it is a String variable, uses vim_str2nr().
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
258 * For incompatible types, return 0.
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
259 * tv_get_number_chk() is similar to tv_get_number(), but informs the
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
260 * caller of incompatible types: it sets *denote to TRUE if "denote"
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
261 * is not NULL or returns -1 otherwise.
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
262 */
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
263 varnumber_T
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
264 tv_get_number(typval_T *varp)
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
265 {
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
266 int error = FALSE;
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
267
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
268 return tv_get_number_chk(varp, &error); // return 0L on error
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
269 }
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
270
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
271 varnumber_T
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
272 tv_get_number_chk(typval_T *varp, int *denote)
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
273 {
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
274 return tv_get_bool_or_number_chk(varp, denote, FALSE);
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
275 }
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
276
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
277 /*
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
278 * Get the boolean value of "varp". This is like tv_get_number_chk(),
21913
9fc27a955f00 patch 8.2.1506: Vim9: no error when using a number other than 0 or 1 as bool
Bram Moolenaar <Bram@vim.org>
parents: 21861
diff changeset
279 * but in Vim9 script accepts Number (0 and 1) and Bool/Special.
21851
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
280 */
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
281 varnumber_T
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
282 tv_get_bool(typval_T *varp)
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
283 {
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
284 return tv_get_bool_or_number_chk(varp, NULL, TRUE);
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
285 }
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
286
21861
cd8dafe937ba patch 8.2.1480: Vim9: skip expression in search() gives error
Bram Moolenaar <Bram@vim.org>
parents: 21851
diff changeset
287 /*
cd8dafe937ba patch 8.2.1480: Vim9: skip expression in search() gives error
Bram Moolenaar <Bram@vim.org>
parents: 21851
diff changeset
288 * Get the boolean value of "varp". This is like tv_get_number_chk(),
cd8dafe937ba patch 8.2.1480: Vim9: skip expression in search() gives error
Bram Moolenaar <Bram@vim.org>
parents: 21851
diff changeset
289 * but in Vim9 script accepts Number and Bool.
cd8dafe937ba patch 8.2.1480: Vim9: skip expression in search() gives error
Bram Moolenaar <Bram@vim.org>
parents: 21851
diff changeset
290 */
cd8dafe937ba patch 8.2.1480: Vim9: skip expression in search() gives error
Bram Moolenaar <Bram@vim.org>
parents: 21851
diff changeset
291 varnumber_T
cd8dafe937ba patch 8.2.1480: Vim9: skip expression in search() gives error
Bram Moolenaar <Bram@vim.org>
parents: 21851
diff changeset
292 tv_get_bool_chk(typval_T *varp, int *denote)
cd8dafe937ba patch 8.2.1480: Vim9: skip expression in search() gives error
Bram Moolenaar <Bram@vim.org>
parents: 21851
diff changeset
293 {
cd8dafe937ba patch 8.2.1480: Vim9: skip expression in search() gives error
Bram Moolenaar <Bram@vim.org>
parents: 21851
diff changeset
294 return tv_get_bool_or_number_chk(varp, denote, TRUE);
cd8dafe937ba patch 8.2.1480: Vim9: skip expression in search() gives error
Bram Moolenaar <Bram@vim.org>
parents: 21851
diff changeset
295 }
cd8dafe937ba patch 8.2.1480: Vim9: skip expression in search() gives error
Bram Moolenaar <Bram@vim.org>
parents: 21851
diff changeset
296
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
297 #ifdef FEAT_FLOAT
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
298 float_T
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
299 tv_get_float(typval_T *varp)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
300 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
301 switch (varp->v_type)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
302 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
303 case VAR_NUMBER:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
304 return (float_T)(varp->vval.v_number);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
305 case VAR_FLOAT:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
306 return varp->vval.v_float;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
307 case VAR_FUNC:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
308 case VAR_PARTIAL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
309 emsg(_("E891: Using a Funcref as a Float"));
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
310 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
311 case VAR_STRING:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
312 emsg(_("E892: Using a String as a Float"));
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
313 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
314 case VAR_LIST:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
315 emsg(_("E893: Using a List as a Float"));
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
316 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
317 case VAR_DICT:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
318 emsg(_("E894: Using a Dictionary as a Float"));
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
319 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
320 case VAR_BOOL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
321 emsg(_("E362: Using a boolean value as a Float"));
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
322 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
323 case VAR_SPECIAL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
324 emsg(_("E907: Using a special value as a Float"));
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
325 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
326 case VAR_JOB:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
327 # ifdef FEAT_JOB_CHANNEL
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
328 emsg(_("E911: Using a Job as a Float"));
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
329 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
330 # endif
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
331 case VAR_CHANNEL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
332 # ifdef FEAT_JOB_CHANNEL
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
333 emsg(_("E914: Using a Channel as a Float"));
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
334 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
335 # endif
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
336 case VAR_BLOB:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
337 emsg(_("E975: Using a Blob as a Float"));
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
338 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
339 case VAR_UNKNOWN:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
340 case VAR_ANY:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
341 case VAR_VOID:
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24424
diff changeset
342 case VAR_INSTR:
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
343 internal_error_no_abort("tv_get_float(UNKNOWN)");
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
344 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
345 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
346 return 0;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
347 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
348 #endif
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
349
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
350 /*
23175
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
351 * Give an error and return FAIL unless "tv" is a string.
23142
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 22930
diff changeset
352 */
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 22930
diff changeset
353 int
24246
35603c7991d7 patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24210
diff changeset
354 check_for_string_arg(typval_T *args, int idx)
23142
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 22930
diff changeset
355 {
24246
35603c7991d7 patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24210
diff changeset
356 if (args[idx].v_type != VAR_STRING)
23142
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 22930
diff changeset
357 {
24246
35603c7991d7 patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24210
diff changeset
358 if (idx >= 0)
35603c7991d7 patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24210
diff changeset
359 semsg(_(e_string_required_for_argument_nr), idx + 1);
24210
083f07f99e20 patch 8.2.2646: Vim9: error for not using string doesn't mentionargument
Bram Moolenaar <Bram@vim.org>
parents: 23909
diff changeset
360 else
083f07f99e20 patch 8.2.2646: Vim9: error for not using string doesn't mentionargument
Bram Moolenaar <Bram@vim.org>
parents: 23909
diff changeset
361 emsg(_(e_stringreq));
23142
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 22930
diff changeset
362 return FAIL;
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 22930
diff changeset
363 }
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 22930
diff changeset
364 return OK;
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 22930
diff changeset
365 }
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 22930
diff changeset
366
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 22930
diff changeset
367 /*
24246
35603c7991d7 patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24210
diff changeset
368 * Give an error and return FAIL unless "args[idx]" is a non-empty string.
23175
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
369 */
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
370 int
24246
35603c7991d7 patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24210
diff changeset
371 check_for_nonempty_string_arg(typval_T *args, int idx)
23175
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
372 {
24246
35603c7991d7 patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24210
diff changeset
373 if (check_for_string_arg(args, idx) == FAIL)
23175
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
374 return FAIL;
24246
35603c7991d7 patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24210
diff changeset
375 if (args[idx].vval.v_string == NULL || *args[idx].vval.v_string == NUL)
23175
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
376 {
24424
ddcda424f882 patch 8.2.2752
Bram Moolenaar <Bram@vim.org>
parents: 24260
diff changeset
377 semsg(_(e_non_empty_string_required_for_argument_nr), idx + 1);
23175
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
378 return FAIL;
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
379 }
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
380 return OK;
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
381 }
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
382
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
383 /*
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
384 * Get the string value of a variable.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
385 * If it is a Number variable, the number is converted into a string.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
386 * tv_get_string() uses a single, static buffer. YOU CAN ONLY USE IT ONCE!
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
387 * tv_get_string_buf() uses a given buffer.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
388 * If the String variable has never been set, return an empty string.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
389 * Never returns NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
390 * tv_get_string_chk() and tv_get_string_buf_chk() are similar, but return
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
391 * NULL on error.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
392 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
393 char_u *
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
394 tv_get_string(typval_T *varp)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
395 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
396 static char_u mybuf[NUMBUFLEN];
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
397
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
398 return tv_get_string_buf(varp, mybuf);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
399 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
400
23786
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
401 /*
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
402 * Like tv_get_string() but don't allow number to string conversion for Vim9.
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
403 */
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
404 char_u *
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
405 tv_get_string_strict(typval_T *varp)
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
406 {
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
407 static char_u mybuf[NUMBUFLEN];
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
408 char_u *res = tv_get_string_buf_chk_strict(
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
409 varp, mybuf, in_vim9script());
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
410
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
411 return res != NULL ? res : (char_u *)"";
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
412 }
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
413
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
414 char_u *
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
415 tv_get_string_buf(typval_T *varp, char_u *buf)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
416 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
417 char_u *res = tv_get_string_buf_chk(varp, buf);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
418
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
419 return res != NULL ? res : (char_u *)"";
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
420 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
421
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
422 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
423 * Careful: This uses a single, static buffer. YOU CAN ONLY USE IT ONCE!
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
424 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
425 char_u *
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
426 tv_get_string_chk(typval_T *varp)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
427 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
428 static char_u mybuf[NUMBUFLEN];
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
429
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
430 return tv_get_string_buf_chk(varp, mybuf);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
431 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
432
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
433 char_u *
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
434 tv_get_string_buf_chk(typval_T *varp, char_u *buf)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
435 {
23786
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
436 return tv_get_string_buf_chk_strict(varp, buf, FALSE);
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
437 }
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
438
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
439 char_u *
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
440 tv_get_string_buf_chk_strict(typval_T *varp, char_u *buf, int strict)
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
441 {
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
442 switch (varp->v_type)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
443 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
444 case VAR_NUMBER:
23786
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
445 if (strict)
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
446 {
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
447 emsg(_(e_using_number_as_string));
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
448 break;
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
449 }
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
450 vim_snprintf((char *)buf, NUMBUFLEN, "%lld",
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
451 (varnumber_T)varp->vval.v_number);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
452 return buf;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
453 case VAR_FUNC:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
454 case VAR_PARTIAL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
455 emsg(_("E729: using Funcref as a String"));
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
456 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
457 case VAR_LIST:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
458 emsg(_("E730: using List as a String"));
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
459 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
460 case VAR_DICT:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
461 emsg(_("E731: using Dictionary as a String"));
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
462 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
463 case VAR_FLOAT:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
464 #ifdef FEAT_FLOAT
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
465 emsg(_(e_float_as_string));
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
466 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
467 #endif
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
468 case VAR_STRING:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
469 if (varp->vval.v_string != NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
470 return varp->vval.v_string;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
471 return (char_u *)"";
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
472 case VAR_BOOL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
473 case VAR_SPECIAL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
474 STRCPY(buf, get_var_special_name(varp->vval.v_number));
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
475 return buf;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
476 case VAR_BLOB:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
477 emsg(_("E976: using Blob as a String"));
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
478 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
479 case VAR_JOB:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
480 #ifdef FEAT_JOB_CHANNEL
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
481 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
482 job_T *job = varp->vval.v_job;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
483 char *status;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
484
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
485 if (job == NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
486 return (char_u *)"no process";
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
487 status = job->jv_status == JOB_FAILED ? "fail"
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
488 : job->jv_status >= JOB_ENDED ? "dead"
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
489 : "run";
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
490 # ifdef UNIX
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
491 vim_snprintf((char *)buf, NUMBUFLEN,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
492 "process %ld %s", (long)job->jv_pid, status);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
493 # elif defined(MSWIN)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
494 vim_snprintf((char *)buf, NUMBUFLEN,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
495 "process %ld %s",
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
496 (long)job->jv_proc_info.dwProcessId,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
497 status);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
498 # else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
499 // fall-back
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
500 vim_snprintf((char *)buf, NUMBUFLEN, "process ? %s", status);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
501 # endif
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
502 return buf;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
503 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
504 #endif
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
505 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
506 case VAR_CHANNEL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
507 #ifdef FEAT_JOB_CHANNEL
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
508 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
509 channel_T *channel = varp->vval.v_channel;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
510 char *status = channel_status(channel, -1);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
511
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
512 if (channel == NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
513 vim_snprintf((char *)buf, NUMBUFLEN, "channel %s", status);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
514 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
515 vim_snprintf((char *)buf, NUMBUFLEN,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
516 "channel %d %s", channel->ch_id, status);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
517 return buf;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
518 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
519 #endif
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
520 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
521 case VAR_UNKNOWN:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
522 case VAR_ANY:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
523 case VAR_VOID:
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24424
diff changeset
524 case VAR_INSTR:
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
525 emsg(_(e_inval_string));
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
526 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
527 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
528 return NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
529 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
530
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
531 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
532 * Turn a typeval into a string. Similar to tv_get_string_buf() but uses
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
533 * string() on Dict, List, etc.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
534 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
535 char_u *
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
536 tv_stringify(typval_T *varp, char_u *buf)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
537 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
538 if (varp->v_type == VAR_LIST
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
539 || varp->v_type == VAR_DICT
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
540 || varp->v_type == VAR_BLOB
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
541 || varp->v_type == VAR_FUNC
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
542 || varp->v_type == VAR_PARTIAL
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
543 || varp->v_type == VAR_FLOAT)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
544 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
545 typval_T tmp;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
546
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
547 f_string(varp, &tmp);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
548 tv_get_string_buf(&tmp, buf);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
549 clear_tv(varp);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
550 *varp = tmp;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
551 return tmp.vval.v_string;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
552 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
553 return tv_get_string_buf(varp, buf);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
554 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
555
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
556 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
557 * Return TRUE if typeval "tv" and its value are set to be locked (immutable).
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
558 * Also give an error message, using "name" or _("name") when use_gettext is
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
559 * TRUE.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
560 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
561 int
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
562 tv_check_lock(typval_T *tv, char_u *name, int use_gettext)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
563 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
564 int lock = 0;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
565
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
566 switch (tv->v_type)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
567 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
568 case VAR_BLOB:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
569 if (tv->vval.v_blob != NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
570 lock = tv->vval.v_blob->bv_lock;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
571 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
572 case VAR_LIST:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
573 if (tv->vval.v_list != NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
574 lock = tv->vval.v_list->lv_lock;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
575 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
576 case VAR_DICT:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
577 if (tv->vval.v_dict != NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
578 lock = tv->vval.v_dict->dv_lock;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
579 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
580 default:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
581 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
582 }
22298
07e48ee8c3bb patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 22043
diff changeset
583 return value_check_lock(tv->v_lock, name, use_gettext)
07e48ee8c3bb patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 22043
diff changeset
584 || (lock != 0 && value_check_lock(lock, name, use_gettext));
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
585 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
586
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
587 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
588 * Copy the values from typval_T "from" to typval_T "to".
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
589 * When needed allocates string or increases reference count.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
590 * Does not make a copy of a list, blob or dict but copies the reference!
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
591 * It is OK for "from" and "to" to point to the same item. This is used to
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
592 * make a copy later.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
593 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
594 void
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
595 copy_tv(typval_T *from, typval_T *to)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
596 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
597 to->v_type = from->v_type;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
598 to->v_lock = 0;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
599 switch (from->v_type)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
600 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
601 case VAR_NUMBER:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
602 case VAR_BOOL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
603 case VAR_SPECIAL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
604 to->vval.v_number = from->vval.v_number;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
605 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
606 case VAR_FLOAT:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
607 #ifdef FEAT_FLOAT
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
608 to->vval.v_float = from->vval.v_float;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
609 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
610 #endif
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
611 case VAR_JOB:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
612 #ifdef FEAT_JOB_CHANNEL
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
613 to->vval.v_job = from->vval.v_job;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
614 if (to->vval.v_job != NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
615 ++to->vval.v_job->jv_refcount;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
616 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
617 #endif
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
618 case VAR_CHANNEL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
619 #ifdef FEAT_JOB_CHANNEL
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
620 to->vval.v_channel = from->vval.v_channel;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
621 if (to->vval.v_channel != NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
622 ++to->vval.v_channel->ch_refcount;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
623 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
624 #endif
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24424
diff changeset
625 case VAR_INSTR:
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24424
diff changeset
626 to->vval.v_instr = from->vval.v_instr;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24424
diff changeset
627 break;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24424
diff changeset
628
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
629 case VAR_STRING:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
630 case VAR_FUNC:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
631 if (from->vval.v_string == NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
632 to->vval.v_string = NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
633 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
634 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
635 to->vval.v_string = vim_strsave(from->vval.v_string);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
636 if (from->v_type == VAR_FUNC)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
637 func_ref(to->vval.v_string);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
638 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
639 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
640 case VAR_PARTIAL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
641 if (from->vval.v_partial == NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
642 to->vval.v_partial = NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
643 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
644 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
645 to->vval.v_partial = from->vval.v_partial;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
646 ++to->vval.v_partial->pt_refcount;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
647 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
648 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
649 case VAR_BLOB:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
650 if (from->vval.v_blob == NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
651 to->vval.v_blob = NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
652 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
653 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
654 to->vval.v_blob = from->vval.v_blob;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
655 ++to->vval.v_blob->bv_refcount;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
656 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
657 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
658 case VAR_LIST:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
659 if (from->vval.v_list == NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
660 to->vval.v_list = NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
661 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
662 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
663 to->vval.v_list = from->vval.v_list;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
664 ++to->vval.v_list->lv_refcount;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
665 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
666 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
667 case VAR_DICT:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
668 if (from->vval.v_dict == NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
669 to->vval.v_dict = NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
670 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
671 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
672 to->vval.v_dict = from->vval.v_dict;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
673 ++to->vval.v_dict->dv_refcount;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
674 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
675 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
676 case VAR_UNKNOWN:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
677 case VAR_ANY:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
678 case VAR_VOID:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
679 internal_error_no_abort("copy_tv(UNKNOWN)");
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
680 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
681 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
682 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
683
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
684 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
685 * Compare "typ1" and "typ2". Put the result in "typ1".
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
686 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
687 int
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
688 typval_compare(
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
689 typval_T *typ1, // first operand
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
690 typval_T *typ2, // second operand
23553
5c094273c015 patch 8.2.2319: "exptype_T" can be read as "expected type"
Bram Moolenaar <Bram@vim.org>
parents: 23519
diff changeset
691 exprtype_T type, // operator
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
692 int ic) // ignore case
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
693 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
694 int i;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
695 varnumber_T n1, n2;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
696 char_u *s1, *s2;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
697 char_u buf1[NUMBUFLEN], buf2[NUMBUFLEN];
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
698 int type_is = type == EXPR_IS || type == EXPR_ISNOT;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
699
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
700 if (type_is && typ1->v_type != typ2->v_type)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
701 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
702 // For "is" a different type always means FALSE, for "notis"
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
703 // it means TRUE.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
704 n1 = (type == EXPR_ISNOT);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
705 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
706 else if (typ1->v_type == VAR_BLOB || typ2->v_type == VAR_BLOB)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
707 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
708 if (type_is)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
709 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
710 n1 = (typ1->v_type == typ2->v_type
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
711 && typ1->vval.v_blob == typ2->vval.v_blob);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
712 if (type == EXPR_ISNOT)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
713 n1 = !n1;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
714 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
715 else if (typ1->v_type != typ2->v_type
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
716 || (type != EXPR_EQUAL && type != EXPR_NEQUAL))
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
717 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
718 if (typ1->v_type != typ2->v_type)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
719 emsg(_("E977: Can only compare Blob with Blob"));
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
720 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
721 emsg(_(e_invalblob));
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
722 clear_tv(typ1);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
723 return FAIL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
724 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
725 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
726 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
727 // Compare two Blobs for being equal or unequal.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
728 n1 = blob_equal(typ1->vval.v_blob, typ2->vval.v_blob);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
729 if (type == EXPR_NEQUAL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
730 n1 = !n1;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
731 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
732 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
733 else if (typ1->v_type == VAR_LIST || typ2->v_type == VAR_LIST)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
734 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
735 if (type_is)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
736 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
737 n1 = (typ1->v_type == typ2->v_type
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
738 && typ1->vval.v_list == typ2->vval.v_list);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
739 if (type == EXPR_ISNOT)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
740 n1 = !n1;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
741 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
742 else if (typ1->v_type != typ2->v_type
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
743 || (type != EXPR_EQUAL && type != EXPR_NEQUAL))
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
744 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
745 if (typ1->v_type != typ2->v_type)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
746 emsg(_("E691: Can only compare List with List"));
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
747 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
748 emsg(_("E692: Invalid operation for List"));
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
749 clear_tv(typ1);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
750 return FAIL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
751 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
752 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
753 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
754 // Compare two Lists for being equal or unequal.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
755 n1 = list_equal(typ1->vval.v_list, typ2->vval.v_list,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
756 ic, FALSE);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
757 if (type == EXPR_NEQUAL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
758 n1 = !n1;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
759 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
760 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
761
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
762 else if (typ1->v_type == VAR_DICT || typ2->v_type == VAR_DICT)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
763 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
764 if (type_is)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
765 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
766 n1 = (typ1->v_type == typ2->v_type
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
767 && typ1->vval.v_dict == typ2->vval.v_dict);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
768 if (type == EXPR_ISNOT)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
769 n1 = !n1;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
770 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
771 else if (typ1->v_type != typ2->v_type
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
772 || (type != EXPR_EQUAL && type != EXPR_NEQUAL))
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
773 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
774 if (typ1->v_type != typ2->v_type)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
775 emsg(_("E735: Can only compare Dictionary with Dictionary"));
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
776 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
777 emsg(_("E736: Invalid operation for Dictionary"));
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
778 clear_tv(typ1);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
779 return FAIL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
780 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
781 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
782 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
783 // Compare two Dictionaries for being equal or unequal.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
784 n1 = dict_equal(typ1->vval.v_dict, typ2->vval.v_dict,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
785 ic, FALSE);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
786 if (type == EXPR_NEQUAL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
787 n1 = !n1;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
788 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
789 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
790
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
791 else if (typ1->v_type == VAR_FUNC || typ2->v_type == VAR_FUNC
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
792 || typ1->v_type == VAR_PARTIAL || typ2->v_type == VAR_PARTIAL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
793 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
794 if (type != EXPR_EQUAL && type != EXPR_NEQUAL
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
795 && type != EXPR_IS && type != EXPR_ISNOT)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
796 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
797 emsg(_("E694: Invalid operation for Funcrefs"));
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
798 clear_tv(typ1);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
799 return FAIL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
800 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
801 if ((typ1->v_type == VAR_PARTIAL
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
802 && typ1->vval.v_partial == NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
803 || (typ2->v_type == VAR_PARTIAL
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
804 && typ2->vval.v_partial == NULL))
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
805 // When both partials are NULL, then they are equal.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
806 // Otherwise they are not equal.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
807 n1 = (typ1->vval.v_partial == typ2->vval.v_partial);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
808 else if (type_is)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
809 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
810 if (typ1->v_type == VAR_FUNC && typ2->v_type == VAR_FUNC)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
811 // strings are considered the same if their value is
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
812 // the same
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
813 n1 = tv_equal(typ1, typ2, ic, FALSE);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
814 else if (typ1->v_type == VAR_PARTIAL
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
815 && typ2->v_type == VAR_PARTIAL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
816 n1 = (typ1->vval.v_partial == typ2->vval.v_partial);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
817 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
818 n1 = FALSE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
819 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
820 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
821 n1 = tv_equal(typ1, typ2, ic, FALSE);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
822 if (type == EXPR_NEQUAL || type == EXPR_ISNOT)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
823 n1 = !n1;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
824 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
825
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
826 #ifdef FEAT_FLOAT
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
827 // If one of the two variables is a float, compare as a float.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
828 // When using "=~" or "!~", always compare as string.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
829 else if ((typ1->v_type == VAR_FLOAT || typ2->v_type == VAR_FLOAT)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
830 && type != EXPR_MATCH && type != EXPR_NOMATCH)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
831 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
832 float_T f1, f2;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
833
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
834 f1 = tv_get_float(typ1);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
835 f2 = tv_get_float(typ2);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
836 n1 = FALSE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
837 switch (type)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
838 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
839 case EXPR_IS:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
840 case EXPR_EQUAL: n1 = (f1 == f2); break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
841 case EXPR_ISNOT:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
842 case EXPR_NEQUAL: n1 = (f1 != f2); break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
843 case EXPR_GREATER: n1 = (f1 > f2); break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
844 case EXPR_GEQUAL: n1 = (f1 >= f2); break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
845 case EXPR_SMALLER: n1 = (f1 < f2); break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
846 case EXPR_SEQUAL: n1 = (f1 <= f2); break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
847 case EXPR_UNKNOWN:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
848 case EXPR_MATCH:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
849 default: break; // avoid gcc warning
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
850 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
851 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
852 #endif
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
853
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
854 // If one of the two variables is a number, compare as a number.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
855 // When using "=~" or "!~", always compare as string.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
856 else if ((typ1->v_type == VAR_NUMBER || typ2->v_type == VAR_NUMBER)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
857 && type != EXPR_MATCH && type != EXPR_NOMATCH)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
858 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
859 n1 = tv_get_number(typ1);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
860 n2 = tv_get_number(typ2);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
861 switch (type)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
862 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
863 case EXPR_IS:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
864 case EXPR_EQUAL: n1 = (n1 == n2); break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
865 case EXPR_ISNOT:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
866 case EXPR_NEQUAL: n1 = (n1 != n2); break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
867 case EXPR_GREATER: n1 = (n1 > n2); break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
868 case EXPR_GEQUAL: n1 = (n1 >= n2); break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
869 case EXPR_SMALLER: n1 = (n1 < n2); break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
870 case EXPR_SEQUAL: n1 = (n1 <= n2); break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
871 case EXPR_UNKNOWN:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
872 case EXPR_MATCH:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
873 default: break; // avoid gcc warning
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
874 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
875 }
23555
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
876 else if (in_vim9script() && (typ1->v_type == VAR_BOOL
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
877 || typ2->v_type == VAR_BOOL))
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
878 {
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
879 if (typ1->v_type != typ2->v_type)
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
880 {
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
881 semsg(_(e_cannot_compare_str_with_str),
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
882 vartype_name(typ1->v_type), vartype_name(typ2->v_type));
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
883 clear_tv(typ1);
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
884 return FAIL;
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
885 }
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
886 n1 = typ1->vval.v_number;
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
887 n2 = typ2->vval.v_number;
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
888 switch (type)
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
889 {
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
890 case EXPR_IS:
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
891 case EXPR_EQUAL: n1 = (n1 == n2); break;
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
892 case EXPR_ISNOT:
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
893 case EXPR_NEQUAL: n1 = (n1 != n2); break;
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
894 default:
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
895 emsg(_(e_invalid_operation_for_bool));
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
896 clear_tv(typ1);
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
897 return FAIL;
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
898 }
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
899 }
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
900 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
901 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
902 s1 = tv_get_string_buf(typ1, buf1);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
903 s2 = tv_get_string_buf(typ2, buf2);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
904 if (type != EXPR_MATCH && type != EXPR_NOMATCH)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
905 i = ic ? MB_STRICMP(s1, s2) : STRCMP(s1, s2);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
906 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
907 i = 0;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
908 n1 = FALSE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
909 switch (type)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
910 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
911 case EXPR_IS:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
912 case EXPR_EQUAL: n1 = (i == 0); break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
913 case EXPR_ISNOT:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
914 case EXPR_NEQUAL: n1 = (i != 0); break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
915 case EXPR_GREATER: n1 = (i > 0); break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
916 case EXPR_GEQUAL: n1 = (i >= 0); break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
917 case EXPR_SMALLER: n1 = (i < 0); break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
918 case EXPR_SEQUAL: n1 = (i <= 0); break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
919
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
920 case EXPR_MATCH:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
921 case EXPR_NOMATCH:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
922 n1 = pattern_match(s2, s1, ic);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
923 if (type == EXPR_NOMATCH)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
924 n1 = !n1;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
925 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
926
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
927 default: break; // avoid gcc warning
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
928 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
929 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
930 clear_tv(typ1);
21425
a6c316ef161a patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
931 if (in_vim9script())
a6c316ef161a patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
932 {
a6c316ef161a patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
933 typ1->v_type = VAR_BOOL;
a6c316ef161a patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
934 typ1->vval.v_number = n1 ? VVAL_TRUE : VVAL_FALSE;
a6c316ef161a patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
935 }
a6c316ef161a patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
936 else
a6c316ef161a patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
937 {
a6c316ef161a patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
938 typ1->v_type = VAR_NUMBER;
a6c316ef161a patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
939 typ1->vval.v_number = n1;
a6c316ef161a patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
940 }
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
941
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
942 return OK;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
943 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
944
23788
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
945 /*
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
946 * Convert any type to a string, never give an error.
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
947 * When "quotes" is TRUE add quotes to a string.
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
948 * Returns an allocated string.
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
949 */
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
950 char_u *
23788
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
951 typval_tostring(typval_T *arg, int quotes)
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
952 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
953 char_u *tofree;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
954 char_u numbuf[NUMBUFLEN];
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
955 char_u *ret = NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
956
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
957 if (arg == NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
958 return vim_strsave((char_u *)"(does not exist)");
23788
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
959 if (!quotes && arg->v_type == VAR_STRING)
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
960 {
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
961 ret = vim_strsave(arg->vval.v_string == NULL ? (char_u *)""
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
962 : arg->vval.v_string);
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
963 }
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
964 else
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
965 {
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
966 ret = tv2string(arg, &tofree, numbuf, 0);
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
967 // Make a copy if we have a value but it's not in allocated memory.
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
968 if (ret != NULL && tofree == NULL)
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
969 ret = vim_strsave(ret);
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
970 }
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
971 return ret;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
972 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
973
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
974 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
975 * Return TRUE if typeval "tv" is locked: Either that value is locked itself
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
976 * or it refers to a List or Dictionary that is locked.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
977 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
978 int
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
979 tv_islocked(typval_T *tv)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
980 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
981 return (tv->v_lock & VAR_LOCKED)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
982 || (tv->v_type == VAR_LIST
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
983 && tv->vval.v_list != NULL
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
984 && (tv->vval.v_list->lv_lock & VAR_LOCKED))
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
985 || (tv->v_type == VAR_DICT
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
986 && tv->vval.v_dict != NULL
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
987 && (tv->vval.v_dict->dv_lock & VAR_LOCKED));
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
988 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
989
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
990 static int
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
991 func_equal(
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
992 typval_T *tv1,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
993 typval_T *tv2,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
994 int ic) // ignore case
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
995 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
996 char_u *s1, *s2;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
997 dict_T *d1, *d2;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
998 int a1, a2;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
999 int i;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1000
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1001 // empty and NULL function name considered the same
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1002 s1 = tv1->v_type == VAR_FUNC ? tv1->vval.v_string
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1003 : partial_name(tv1->vval.v_partial);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1004 if (s1 != NULL && *s1 == NUL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1005 s1 = NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1006 s2 = tv2->v_type == VAR_FUNC ? tv2->vval.v_string
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1007 : partial_name(tv2->vval.v_partial);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1008 if (s2 != NULL && *s2 == NUL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1009 s2 = NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1010 if (s1 == NULL || s2 == NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1011 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1012 if (s1 != s2)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1013 return FALSE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1014 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1015 else if (STRCMP(s1, s2) != 0)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1016 return FALSE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1017
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1018 // empty dict and NULL dict is different
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1019 d1 = tv1->v_type == VAR_FUNC ? NULL : tv1->vval.v_partial->pt_dict;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1020 d2 = tv2->v_type == VAR_FUNC ? NULL : tv2->vval.v_partial->pt_dict;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1021 if (d1 == NULL || d2 == NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1022 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1023 if (d1 != d2)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1024 return FALSE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1025 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1026 else if (!dict_equal(d1, d2, ic, TRUE))
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1027 return FALSE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1028
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1029 // empty list and no list considered the same
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1030 a1 = tv1->v_type == VAR_FUNC ? 0 : tv1->vval.v_partial->pt_argc;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1031 a2 = tv2->v_type == VAR_FUNC ? 0 : tv2->vval.v_partial->pt_argc;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1032 if (a1 != a2)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1033 return FALSE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1034 for (i = 0; i < a1; ++i)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1035 if (!tv_equal(tv1->vval.v_partial->pt_argv + i,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1036 tv2->vval.v_partial->pt_argv + i, ic, TRUE))
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1037 return FALSE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1038
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1039 return TRUE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1040 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1041
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1042 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1043 * Return TRUE if "tv1" and "tv2" have the same value.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1044 * Compares the items just like "==" would compare them, but strings and
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1045 * numbers are different. Floats and numbers are also different.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1046 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1047 int
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1048 tv_equal(
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1049 typval_T *tv1,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1050 typval_T *tv2,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1051 int ic, // ignore case
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1052 int recursive) // TRUE when used recursively
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1053 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1054 char_u buf1[NUMBUFLEN], buf2[NUMBUFLEN];
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1055 char_u *s1, *s2;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1056 static int recursive_cnt = 0; // catch recursive loops
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1057 int r;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1058 static int tv_equal_recurse_limit;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1059
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1060 // Catch lists and dicts that have an endless loop by limiting
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1061 // recursiveness to a limit. We guess they are equal then.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1062 // A fixed limit has the problem of still taking an awful long time.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1063 // Reduce the limit every time running into it. That should work fine for
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1064 // deeply linked structures that are not recursively linked and catch
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1065 // recursiveness quickly.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1066 if (!recursive)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1067 tv_equal_recurse_limit = 1000;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1068 if (recursive_cnt >= tv_equal_recurse_limit)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1069 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1070 --tv_equal_recurse_limit;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1071 return TRUE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1072 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1073
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1074 // For VAR_FUNC and VAR_PARTIAL compare the function name, bound dict and
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1075 // arguments.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1076 if ((tv1->v_type == VAR_FUNC
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1077 || (tv1->v_type == VAR_PARTIAL && tv1->vval.v_partial != NULL))
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1078 && (tv2->v_type == VAR_FUNC
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1079 || (tv2->v_type == VAR_PARTIAL && tv2->vval.v_partial != NULL)))
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1080 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1081 ++recursive_cnt;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1082 r = func_equal(tv1, tv2, ic);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1083 --recursive_cnt;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1084 return r;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1085 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1086
23909
5db7d275543c patch 8.2.2497: no error when using more than one character for a register
Bram Moolenaar <Bram@vim.org>
parents: 23788
diff changeset
1087 if (tv1->v_type != tv2->v_type
5db7d275543c patch 8.2.2497: no error when using more than one character for a register
Bram Moolenaar <Bram@vim.org>
parents: 23788
diff changeset
1088 && ((tv1->v_type != VAR_BOOL && tv1->v_type != VAR_SPECIAL)
5db7d275543c patch 8.2.2497: no error when using more than one character for a register
Bram Moolenaar <Bram@vim.org>
parents: 23788
diff changeset
1089 || (tv2->v_type != VAR_BOOL && tv2->v_type != VAR_SPECIAL)))
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1090 return FALSE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1091
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1092 switch (tv1->v_type)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1093 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1094 case VAR_LIST:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1095 ++recursive_cnt;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1096 r = list_equal(tv1->vval.v_list, tv2->vval.v_list, ic, TRUE);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1097 --recursive_cnt;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1098 return r;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1099
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1100 case VAR_DICT:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1101 ++recursive_cnt;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1102 r = dict_equal(tv1->vval.v_dict, tv2->vval.v_dict, ic, TRUE);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1103 --recursive_cnt;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1104 return r;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1105
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1106 case VAR_BLOB:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1107 return blob_equal(tv1->vval.v_blob, tv2->vval.v_blob);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1108
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1109 case VAR_NUMBER:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1110 case VAR_BOOL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1111 case VAR_SPECIAL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1112 return tv1->vval.v_number == tv2->vval.v_number;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1113
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1114 case VAR_STRING:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1115 s1 = tv_get_string_buf(tv1, buf1);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1116 s2 = tv_get_string_buf(tv2, buf2);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1117 return ((ic ? MB_STRICMP(s1, s2) : STRCMP(s1, s2)) == 0);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1118
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1119 case VAR_FLOAT:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1120 #ifdef FEAT_FLOAT
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1121 return tv1->vval.v_float == tv2->vval.v_float;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1122 #endif
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1123 case VAR_JOB:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1124 #ifdef FEAT_JOB_CHANNEL
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1125 return tv1->vval.v_job == tv2->vval.v_job;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1126 #endif
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1127 case VAR_CHANNEL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1128 #ifdef FEAT_JOB_CHANNEL
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1129 return tv1->vval.v_channel == tv2->vval.v_channel;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1130 #endif
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24424
diff changeset
1131 case VAR_INSTR:
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24424
diff changeset
1132 return tv1->vval.v_instr == tv2->vval.v_instr;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1133
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1134 case VAR_PARTIAL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1135 return tv1->vval.v_partial == tv2->vval.v_partial;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1136
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1137 case VAR_FUNC:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1138 return tv1->vval.v_string == tv2->vval.v_string;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1139
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1140 case VAR_UNKNOWN:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1141 case VAR_ANY:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1142 case VAR_VOID:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1143 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1144 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1145
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1146 // VAR_UNKNOWN can be the result of a invalid expression, let's say it
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1147 // does not equal anything, not even itself.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1148 return FALSE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1149 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1150
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1151 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1152 * Get an option value.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1153 * "arg" points to the '&' or '+' before the option name.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1154 * "arg" is advanced to character after the option name.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1155 * Return OK or FAIL.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1156 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1157 int
21120
4d844a65183d patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents: 20925
diff changeset
1158 eval_option(
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1159 char_u **arg,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1160 typval_T *rettv, // when NULL, only check if option exists
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1161 int evaluate)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1162 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1163 char_u *option_end;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1164 long numval;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1165 char_u *stringval;
23422
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
1166 getoption_T opt_type;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1167 int c;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1168 int working = (**arg == '+'); // has("+option")
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1169 int ret = OK;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1170 int opt_flags;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1171
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1172 // Isolate the option name and find its value.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1173 option_end = find_option_end(arg, &opt_flags);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1174 if (option_end == NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1175 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1176 if (rettv != NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1177 semsg(_("E112: Option name missing: %s"), *arg);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1178 return FAIL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1179 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1180
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1181 if (!evaluate)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1182 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1183 *arg = option_end;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1184 return OK;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1185 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1186
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1187 c = *option_end;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1188 *option_end = NUL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1189 opt_type = get_option_value(*arg, &numval,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1190 rettv == NULL ? NULL : &stringval, opt_flags);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1191
23422
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
1192 if (opt_type == gov_unknown)
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1193 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1194 if (rettv != NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1195 semsg(_(e_unknown_option), *arg);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1196 ret = FAIL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1197 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1198 else if (rettv != NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1199 {
23519
cb66613dd9d5 patch 8.2.2302: Vim9: using an option value may use uninitialized memory
Bram Moolenaar <Bram@vim.org>
parents: 23422
diff changeset
1200 rettv->v_lock = 0;
23422
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
1201 if (opt_type == gov_hidden_string)
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1202 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1203 rettv->v_type = VAR_STRING;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1204 rettv->vval.v_string = NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1205 }
23422
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
1206 else if (opt_type == gov_hidden_bool || opt_type == gov_hidden_number)
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1207 {
23422
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
1208 rettv->v_type = in_vim9script() && opt_type == gov_hidden_bool
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
1209 ? VAR_BOOL : VAR_NUMBER;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1210 rettv->vval.v_number = 0;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1211 }
23422
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
1212 else if (opt_type == gov_bool || opt_type == gov_number)
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1213 {
23422
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
1214 if (in_vim9script() && opt_type == gov_bool)
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
1215 {
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
1216 rettv->v_type = VAR_BOOL;
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
1217 rettv->vval.v_number = numval ? VVAL_TRUE : VVAL_FALSE;
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
1218 }
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
1219 else
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
1220 {
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
1221 rettv->v_type = VAR_NUMBER;
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
1222 rettv->vval.v_number = numval;
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
1223 }
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1224 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1225 else // string option
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1226 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1227 rettv->v_type = VAR_STRING;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1228 rettv->vval.v_string = stringval;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1229 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1230 }
23422
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
1231 else if (working && (opt_type == gov_hidden_bool
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
1232 || opt_type == gov_hidden_number
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
1233 || opt_type == gov_hidden_string))
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1234 ret = FAIL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1235
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1236 *option_end = c; // put back for error messages
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1237 *arg = option_end;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1238
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1239 return ret;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1240 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1241
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1242 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1243 * Allocate a variable for a number constant. Also deals with "0z" for blob.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1244 * Return OK or FAIL.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1245 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1246 int
21120
4d844a65183d patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents: 20925
diff changeset
1247 eval_number(
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1248 char_u **arg,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1249 typval_T *rettv,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1250 int evaluate,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1251 int want_string UNUSED)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1252 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1253 int len;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1254 #ifdef FEAT_FLOAT
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1255 char_u *p;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1256 int get_float = FALSE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1257
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1258 // We accept a float when the format matches
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1259 // "[0-9]\+\.[0-9]\+\([eE][+-]\?[0-9]\+\)\?". This is very
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1260 // strict to avoid backwards compatibility problems.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1261 // With script version 2 and later the leading digit can be
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1262 // omitted.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1263 // Don't look for a float after the "." operator, so that
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1264 // ":let vers = 1.2.3" doesn't fail.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1265 if (**arg == '.')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1266 p = *arg;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1267 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1268 p = skipdigits(*arg + 1);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1269 if (!want_string && p[0] == '.' && vim_isdigit(p[1]))
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1270 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1271 get_float = TRUE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1272 p = skipdigits(p + 2);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1273 if (*p == 'e' || *p == 'E')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1274 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1275 ++p;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1276 if (*p == '-' || *p == '+')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1277 ++p;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1278 if (!vim_isdigit(*p))
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1279 get_float = FALSE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1280 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1281 p = skipdigits(p + 1);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1282 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1283 if (ASCII_ISALPHA(*p) || *p == '.')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1284 get_float = FALSE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1285 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1286 if (get_float)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1287 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1288 float_T f;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1289
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1290 *arg += string2float(*arg, &f);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1291 if (evaluate)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1292 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1293 rettv->v_type = VAR_FLOAT;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1294 rettv->vval.v_float = f;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1295 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1296 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1297 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1298 #endif
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1299 if (**arg == '0' && ((*arg)[1] == 'z' || (*arg)[1] == 'Z'))
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1300 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1301 char_u *bp;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1302 blob_T *blob = NULL; // init for gcc
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1303
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1304 // Blob constant: 0z0123456789abcdef
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1305 if (evaluate)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1306 blob = blob_alloc();
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1307 for (bp = *arg + 2; vim_isxdigit(bp[0]); bp += 2)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1308 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1309 if (!vim_isxdigit(bp[1]))
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1310 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1311 if (blob != NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1312 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1313 emsg(_("E973: Blob literal should have an even number of hex characters"));
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1314 ga_clear(&blob->bv_ga);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1315 VIM_CLEAR(blob);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1316 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1317 return FAIL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1318 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1319 if (blob != NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1320 ga_append(&blob->bv_ga,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1321 (hex2nr(*bp) << 4) + hex2nr(*(bp+1)));
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1322 if (bp[2] == '.' && vim_isxdigit(bp[3]))
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1323 ++bp;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1324 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1325 if (blob != NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1326 rettv_blob_set(rettv, blob);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1327 *arg = bp;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1328 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1329 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1330 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1331 varnumber_T n;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1332
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1333 // decimal, hex or octal number
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1334 vim_str2nr(*arg, NULL, &len, current_sctx.sc_version >= 4
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1335 ? STR2NR_NO_OCT + STR2NR_QUOTE
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1336 : STR2NR_ALL, &n, NULL, 0, TRUE);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1337 if (len == 0)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1338 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1339 semsg(_(e_invexpr2), *arg);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1340 return FAIL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1341 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1342 *arg += len;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1343 if (evaluate)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1344 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1345 rettv->v_type = VAR_NUMBER;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1346 rettv->vval.v_number = n;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1347 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1348 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1349 return OK;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1350 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1351
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1352 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1353 * Allocate a variable for a string constant.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1354 * Return OK or FAIL.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1355 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1356 int
21120
4d844a65183d patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents: 20925
diff changeset
1357 eval_string(char_u **arg, typval_T *rettv, int evaluate)
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1358 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1359 char_u *p;
20925
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
1360 char_u *end;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1361 int extra = 0;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1362 int len;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1363
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1364 // Find the end of the string, skipping backslashed characters.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1365 for (p = *arg + 1; *p != NUL && *p != '"'; MB_PTR_ADV(p))
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1366 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1367 if (*p == '\\' && p[1] != NUL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1368 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1369 ++p;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1370 // A "\<x>" form occupies at least 4 characters, and produces up
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1371 // to 21 characters (3 * 6 for the char and 3 for a modifier):
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1372 // reserve space for 18 extra.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1373 // Each byte in the char could be encoded as K_SPECIAL K_EXTRA x.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1374 if (*p == '<')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1375 extra += 18;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1376 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1377 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1378
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1379 if (*p != '"')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1380 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1381 semsg(_("E114: Missing quote: %s"), *arg);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1382 return FAIL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1383 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1384
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1385 // If only parsing, set *arg and return here
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1386 if (!evaluate)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1387 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1388 *arg = p + 1;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1389 return OK;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1390 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1391
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1392 // Copy the string into allocated memory, handling backslashed
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1393 // characters.
20925
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
1394 rettv->v_type = VAR_STRING;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1395 len = (int)(p - *arg + extra);
20925
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
1396 rettv->vval.v_string = alloc(len);
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
1397 if (rettv->vval.v_string == NULL)
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1398 return FAIL;
20925
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
1399 end = rettv->vval.v_string;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1400
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1401 for (p = *arg + 1; *p != NUL && *p != '"'; )
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1402 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1403 if (*p == '\\')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1404 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1405 switch (*++p)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1406 {
20925
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
1407 case 'b': *end++ = BS; ++p; break;
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
1408 case 'e': *end++ = ESC; ++p; break;
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
1409 case 'f': *end++ = FF; ++p; break;
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
1410 case 'n': *end++ = NL; ++p; break;
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
1411 case 'r': *end++ = CAR; ++p; break;
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
1412 case 't': *end++ = TAB; ++p; break;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1413
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1414 case 'X': // hex: "\x1", "\x12"
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1415 case 'x':
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1416 case 'u': // Unicode: "\u0023"
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1417 case 'U':
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1418 if (vim_isxdigit(p[1]))
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1419 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1420 int n, nr;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1421 int c = toupper(*p);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1422
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1423 if (c == 'X')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1424 n = 2;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1425 else if (*p == 'u')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1426 n = 4;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1427 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1428 n = 8;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1429 nr = 0;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1430 while (--n >= 0 && vim_isxdigit(p[1]))
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1431 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1432 ++p;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1433 nr = (nr << 4) + hex2nr(*p);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1434 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1435 ++p;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1436 // For "\u" store the number according to
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1437 // 'encoding'.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1438 if (c != 'X')
20925
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
1439 end += (*mb_char2bytes)(nr, end);
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1440 else
20925
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
1441 *end++ = nr;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1442 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1443 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1444
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1445 // octal: "\1", "\12", "\123"
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1446 case '0':
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1447 case '1':
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1448 case '2':
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1449 case '3':
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1450 case '4':
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1451 case '5':
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1452 case '6':
20925
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
1453 case '7': *end = *p++ - '0';
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1454 if (*p >= '0' && *p <= '7')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1455 {
20925
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
1456 *end = (*end << 3) + *p++ - '0';
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1457 if (*p >= '0' && *p <= '7')
20925
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
1458 *end = (*end << 3) + *p++ - '0';
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1459 }
20925
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
1460 ++end;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1461 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1462
20627
8bce783af0cb patch 8.2.0867: using {xxx} for encoding a modifier is not nice
Bram Moolenaar <Bram@vim.org>
parents: 20603
diff changeset
1463 // Special key, e.g.: "\<C-W>"
20603
c2570baa2e4c patch 8.2.0855: GUI tests fail because the test doesn't use a modifier
Bram Moolenaar <Bram@vim.org>
parents: 20587
diff changeset
1464 case '<':
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1465 {
20603
c2570baa2e4c patch 8.2.0855: GUI tests fail because the test doesn't use a modifier
Bram Moolenaar <Bram@vim.org>
parents: 20587
diff changeset
1466 int flags = FSK_KEYCODE | FSK_IN_STRING;
c2570baa2e4c patch 8.2.0855: GUI tests fail because the test doesn't use a modifier
Bram Moolenaar <Bram@vim.org>
parents: 20587
diff changeset
1467
20627
8bce783af0cb patch 8.2.0867: using {xxx} for encoding a modifier is not nice
Bram Moolenaar <Bram@vim.org>
parents: 20603
diff changeset
1468 if (p[1] != '*')
20603
c2570baa2e4c patch 8.2.0855: GUI tests fail because the test doesn't use a modifier
Bram Moolenaar <Bram@vim.org>
parents: 20587
diff changeset
1469 flags |= FSK_SIMPLIFY;
20925
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
1470 extra = trans_special(&p, end, flags, NULL);
20603
c2570baa2e4c patch 8.2.0855: GUI tests fail because the test doesn't use a modifier
Bram Moolenaar <Bram@vim.org>
parents: 20587
diff changeset
1471 if (extra != 0)
c2570baa2e4c patch 8.2.0855: GUI tests fail because the test doesn't use a modifier
Bram Moolenaar <Bram@vim.org>
parents: 20587
diff changeset
1472 {
20925
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
1473 end += extra;
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
1474 if (end >= rettv->vval.v_string + len)
21120
4d844a65183d patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents: 20925
diff changeset
1475 iemsg("eval_string() used more space than allocated");
20603
c2570baa2e4c patch 8.2.0855: GUI tests fail because the test doesn't use a modifier
Bram Moolenaar <Bram@vim.org>
parents: 20587
diff changeset
1476 break;
c2570baa2e4c patch 8.2.0855: GUI tests fail because the test doesn't use a modifier
Bram Moolenaar <Bram@vim.org>
parents: 20587
diff changeset
1477 }
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1478 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1479 // FALLTHROUGH
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1480
20925
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
1481 default: MB_COPY_CHAR(p, end);
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1482 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1483 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1484 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1485 else
20925
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
1486 MB_COPY_CHAR(p, end);
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1487 }
20925
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
1488 *end = NUL;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1489 if (*p != NUL) // just in case
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1490 ++p;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1491 *arg = p;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1492
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1493 return OK;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1494 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1495
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1496 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1497 * Allocate a variable for a 'str''ing' constant.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1498 * Return OK or FAIL.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1499 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1500 int
21120
4d844a65183d patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents: 20925
diff changeset
1501 eval_lit_string(char_u **arg, typval_T *rettv, int evaluate)
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1502 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1503 char_u *p;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1504 char_u *str;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1505 int reduce = 0;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1506
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1507 // Find the end of the string, skipping ''.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1508 for (p = *arg + 1; *p != NUL; MB_PTR_ADV(p))
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1509 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1510 if (*p == '\'')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1511 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1512 if (p[1] != '\'')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1513 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1514 ++reduce;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1515 ++p;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1516 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1517 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1518
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1519 if (*p != '\'')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1520 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1521 semsg(_("E115: Missing quote: %s"), *arg);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1522 return FAIL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1523 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1524
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1525 // If only parsing return after setting "*arg"
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1526 if (!evaluate)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1527 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1528 *arg = p + 1;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1529 return OK;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1530 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1531
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1532 // Copy the string into allocated memory, handling '' to ' reduction.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1533 str = alloc((p - *arg) - reduce);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1534 if (str == NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1535 return FAIL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1536 rettv->v_type = VAR_STRING;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1537 rettv->vval.v_string = str;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1538
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1539 for (p = *arg + 1; *p != NUL; )
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1540 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1541 if (*p == '\'')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1542 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1543 if (p[1] != '\'')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1544 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1545 ++p;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1546 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1547 MB_COPY_CHAR(p, str);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1548 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1549 *str = NUL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1550 *arg = p + 1;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1551
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1552 return OK;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1553 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1554
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1555 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1556 * Return a string with the string representation of a variable.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1557 * If the memory is allocated "tofree" is set to it, otherwise NULL.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1558 * "numbuf" is used for a number.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1559 * Puts quotes around strings, so that they can be parsed back by eval().
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1560 * May return NULL.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1561 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1562 char_u *
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1563 tv2string(
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1564 typval_T *tv,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1565 char_u **tofree,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1566 char_u *numbuf,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1567 int copyID)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1568 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1569 return echo_string_core(tv, tofree, numbuf, copyID, FALSE, TRUE, FALSE);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1570 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1571
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1572 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1573 * Get the value of an environment variable.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1574 * "arg" is pointing to the '$'. It is advanced to after the name.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1575 * If the environment variable was not set, silently assume it is empty.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1576 * Return FAIL if the name is invalid.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1577 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1578 int
21120
4d844a65183d patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents: 20925
diff changeset
1579 eval_env_var(char_u **arg, typval_T *rettv, int evaluate)
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1580 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1581 char_u *string = NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1582 int len;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1583 int cc;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1584 char_u *name;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1585 int mustfree = FALSE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1586
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1587 ++*arg;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1588 name = *arg;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1589 len = get_env_len(arg);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1590 if (evaluate)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1591 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1592 if (len == 0)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1593 return FAIL; // invalid empty name
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1594
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1595 cc = name[len];
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1596 name[len] = NUL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1597 // first try vim_getenv(), fast for normal environment vars
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1598 string = vim_getenv(name, &mustfree);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1599 if (string != NULL && *string != NUL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1600 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1601 if (!mustfree)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1602 string = vim_strsave(string);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1603 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1604 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1605 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1606 if (mustfree)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1607 vim_free(string);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1608
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1609 // next try expanding things like $VIM and ${HOME}
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1610 string = expand_env_save(name - 1);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1611 if (string != NULL && *string == '$')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1612 VIM_CLEAR(string);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1613 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1614 name[len] = cc;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1615
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1616 rettv->v_type = VAR_STRING;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1617 rettv->vval.v_string = string;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1618 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1619
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1620 return OK;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1621 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1622
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1623 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1624 * Get the lnum from the first argument.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1625 * Also accepts ".", "$", etc., but that only works for the current buffer.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1626 * Returns -1 on error.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1627 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1628 linenr_T
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1629 tv_get_lnum(typval_T *argvars)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1630 {
23276
b79cdad3ea2e patch 8.2.2184: Vim9: no error when using "2" for a line number
Bram Moolenaar <Bram@vim.org>
parents: 23175
diff changeset
1631 linenr_T lnum = -1;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1632
21831
d8422de73113 patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21425
diff changeset
1633 if (argvars[0].v_type != VAR_STRING || !in_vim9script())
d8422de73113 patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21425
diff changeset
1634 lnum = (linenr_T)tv_get_number_chk(&argvars[0], NULL);
24260
ad065f64eb20 patch 8.2.2671: error for line number in legacy script
Bram Moolenaar <Bram@vim.org>
parents: 24258
diff changeset
1635 if (lnum <= 0 && argvars[0].v_type != VAR_NUMBER)
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1636 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1637 int fnum;
23563
87671ccc6c6b patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents: 23555
diff changeset
1638 pos_T *fp = var2fpos(&argvars[0], TRUE, &fnum, FALSE);
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1639
24260
ad065f64eb20 patch 8.2.2671: error for line number in legacy script
Bram Moolenaar <Bram@vim.org>
parents: 24258
diff changeset
1640 // no valid number, try using arg like line()
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1641 if (fp != NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1642 lnum = fp->lnum;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1643 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1644 return lnum;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1645 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1646
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1647 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1648 * Get the lnum from the first argument.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1649 * Also accepts "$", then "buf" is used.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1650 * Returns 0 on error.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1651 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1652 linenr_T
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1653 tv_get_lnum_buf(typval_T *argvars, buf_T *buf)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1654 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1655 if (argvars[0].v_type == VAR_STRING
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1656 && argvars[0].vval.v_string != NULL
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1657 && argvars[0].vval.v_string[0] == '$'
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1658 && buf != NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1659 return buf->b_ml.ml_line_count;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1660 return (linenr_T)tv_get_number_chk(&argvars[0], NULL);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1661 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1662
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1663 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1664 * Get buffer by number or pattern.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1665 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1666 buf_T *
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1667 tv_get_buf(typval_T *tv, int curtab_only)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1668 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1669 char_u *name = tv->vval.v_string;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1670 buf_T *buf;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1671
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1672 if (tv->v_type == VAR_NUMBER)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1673 return buflist_findnr((int)tv->vval.v_number);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1674 if (tv->v_type != VAR_STRING)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1675 return NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1676 if (name == NULL || *name == NUL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1677 return curbuf;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1678 if (name[0] == '$' && name[1] == NUL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1679 return lastbuf;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1680
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1681 buf = buflist_find_by_name(name, curtab_only);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1682
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1683 // If not found, try expanding the name, like done for bufexists().
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1684 if (buf == NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1685 buf = find_buffer(tv);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1686
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1687 return buf;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1688 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1689
22025
71f886a48ef5 patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
1690 /*
71f886a48ef5 patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
1691 * Like tv_get_buf() but give an error message is the type is wrong.
71f886a48ef5 patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
1692 */
71f886a48ef5 patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
1693 buf_T *
71f886a48ef5 patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
1694 tv_get_buf_from_arg(typval_T *tv)
71f886a48ef5 patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
1695 {
71f886a48ef5 patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
1696 buf_T *buf;
71f886a48ef5 patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
1697
71f886a48ef5 patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
1698 ++emsg_off;
71f886a48ef5 patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
1699 buf = tv_get_buf(tv, FALSE);
71f886a48ef5 patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
1700 --emsg_off;
71f886a48ef5 patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
1701 if (buf == NULL
71f886a48ef5 patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
1702 && tv->v_type != VAR_NUMBER
71f886a48ef5 patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
1703 && tv->v_type != VAR_STRING)
71f886a48ef5 patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
1704 // issue errmsg for type error
71f886a48ef5 patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
1705 (void)tv_get_number(tv);
71f886a48ef5 patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
1706 return buf;
71f886a48ef5 patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
1707 }
71f886a48ef5 patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
1708
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1709 #endif // FEAT_EVAL