annotate src/typval.c @ 26644:2fc1e528e0e1 v8.2.3851

patch 8.2.3851: Vim9: overhead when comparing string, dict or function Commit: https://github.com/vim/vim/commit/265f811f5a2dac81d9698f5202a661a04ed095f1 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Dec 19 12:33:05 2021 +0000 patch 8.2.3851: Vim9: overhead when comparing string, dict or function Problem: Vim9: overhead when comparing string, dict or function. Solution: Call the intented compare function directly. Refactor to avoid duplicated code.
author Bram Moolenaar <Bram@vim.org>
date Sun, 19 Dec 2021 13:45:03 +0100
parents 6fd15d82e898
children 1cee572f2fd7
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;
24936
345619f35112 patch 8.2.3005: Vim9: using a void value does not give a proper error message
Bram Moolenaar <Bram@vim.org>
parents: 24820
diff changeset
241 case VAR_VOID:
345619f35112 patch 8.2.3005: Vim9: using a void value does not give a proper error message
Bram Moolenaar <Bram@vim.org>
parents: 24820
diff changeset
242 emsg(_(e_cannot_use_void_value));
345619f35112 patch 8.2.3005: Vim9: using a void value does not give a proper error message
Bram Moolenaar <Bram@vim.org>
parents: 24820
diff changeset
243 break;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
244 case VAR_UNKNOWN:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
245 case VAR_ANY:
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24424
diff changeset
246 case VAR_INSTR:
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
247 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
248 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
249 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
250 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
251 n = -1;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
252 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
253 *denote = TRUE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
254 return n;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
255 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
256
21851
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
257 /*
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
258 * 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
259 * 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
260 * 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
261 * 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
262 * 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
263 * 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
264 */
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
265 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
266 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
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 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
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 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
271 }
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
272
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
273 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
274 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
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 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
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
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
279 /*
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
280 * 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
281 * 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
282 */
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
283 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
284 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
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 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
287 }
727820154b1a patch 8.2.1475: Vim9: can't use v:true for option flags
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
288
21861
cd8dafe937ba patch 8.2.1480: Vim9: skip expression in search() gives error
Bram Moolenaar <Bram@vim.org>
parents: 21851
diff changeset
289 /*
cd8dafe937ba patch 8.2.1480: Vim9: skip expression in search() gives error
Bram Moolenaar <Bram@vim.org>
parents: 21851
diff changeset
290 * 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
291 * 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
292 */
cd8dafe937ba patch 8.2.1480: Vim9: skip expression in search() gives error
Bram Moolenaar <Bram@vim.org>
parents: 21851
diff changeset
293 varnumber_T
cd8dafe937ba patch 8.2.1480: Vim9: skip expression in search() gives error
Bram Moolenaar <Bram@vim.org>
parents: 21851
diff changeset
294 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
295 {
cd8dafe937ba patch 8.2.1480: Vim9: skip expression in search() gives error
Bram Moolenaar <Bram@vim.org>
parents: 21851
diff changeset
296 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
297 }
cd8dafe937ba patch 8.2.1480: Vim9: skip expression in search() gives error
Bram Moolenaar <Bram@vim.org>
parents: 21851
diff changeset
298
24936
345619f35112 patch 8.2.3005: Vim9: using a void value does not give a proper error message
Bram Moolenaar <Bram@vim.org>
parents: 24820
diff changeset
299 #if defined(FEAT_FLOAT) || defined(PROTO)
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
300 float_T
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
301 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
302 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
303 switch (varp->v_type)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
304 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
305 case VAR_NUMBER:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
306 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
307 case VAR_FLOAT:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
308 return varp->vval.v_float;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
309 case VAR_FUNC:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
310 case VAR_PARTIAL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
311 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
312 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
313 case VAR_STRING:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
314 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
315 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
316 case VAR_LIST:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
317 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
318 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
319 case VAR_DICT:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
320 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
321 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
322 case VAR_BOOL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
323 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
324 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
325 case VAR_SPECIAL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
326 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
327 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
328 case VAR_JOB:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
329 # ifdef FEAT_JOB_CHANNEL
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
330 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
331 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
332 # endif
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
333 case VAR_CHANNEL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
334 # ifdef FEAT_JOB_CHANNEL
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
335 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
336 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
337 # endif
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
338 case VAR_BLOB:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
339 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
340 break;
24936
345619f35112 patch 8.2.3005: Vim9: using a void value does not give a proper error message
Bram Moolenaar <Bram@vim.org>
parents: 24820
diff changeset
341 case VAR_VOID:
345619f35112 patch 8.2.3005: Vim9: using a void value does not give a proper error message
Bram Moolenaar <Bram@vim.org>
parents: 24820
diff changeset
342 emsg(_(e_cannot_use_void_value));
345619f35112 patch 8.2.3005: Vim9: using a void value does not give a proper error message
Bram Moolenaar <Bram@vim.org>
parents: 24820
diff changeset
343 break;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
344 case VAR_UNKNOWN:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
345 case VAR_ANY:
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24424
diff changeset
346 case VAR_INSTR:
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
347 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
348 break;
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 return 0;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
351 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
352 #endif
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
353
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
354 /*
25272
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
355 * Give an error and return FAIL unless "args[idx]" 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
356 */
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 22930
diff changeset
357 int
24246
35603c7991d7 patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24210
diff changeset
358 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
359 {
24246
35603c7991d7 patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24210
diff changeset
360 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
361 {
26622
a28f91b893b2 patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
362 semsg(_(e_string_required_for_argument_nr), idx + 1);
23142
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 22930
diff changeset
363 return FAIL;
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 22930
diff changeset
364 }
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 22930
diff changeset
365 return OK;
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
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 22930
diff changeset
368 /*
24246
35603c7991d7 patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24210
diff changeset
369 * 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
370 */
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
371 int
24246
35603c7991d7 patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24210
diff changeset
372 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
373 {
24246
35603c7991d7 patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24210
diff changeset
374 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
375 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
376 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
377 {
24424
ddcda424f882 patch 8.2.2752
Bram Moolenaar <Bram@vim.org>
parents: 24260
diff changeset
378 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
379 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
380 }
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 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
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
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
384 /*
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
385 * Check for an optional string argument at 'idx'
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
386 */
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
387 int
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
388 check_for_opt_string_arg(typval_T *args, int idx)
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
389 {
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
390 return (args[idx].v_type == VAR_UNKNOWN
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
391 || check_for_string_arg(args, idx) != FAIL);
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
392 }
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
393
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
394 /*
25272
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
395 * Give an error and return FAIL unless "args[idx]" is a number.
25252
acda780ffc3e patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25198
diff changeset
396 */
acda780ffc3e patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25198
diff changeset
397 int
acda780ffc3e patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25198
diff changeset
398 check_for_number_arg(typval_T *args, int idx)
acda780ffc3e patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25198
diff changeset
399 {
acda780ffc3e patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25198
diff changeset
400 if (args[idx].v_type != VAR_NUMBER)
acda780ffc3e patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25198
diff changeset
401 {
26622
a28f91b893b2 patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
402 semsg(_(e_number_required_for_argument_nr), idx + 1);
25252
acda780ffc3e patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25198
diff changeset
403 return FAIL;
acda780ffc3e patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25198
diff changeset
404 }
acda780ffc3e patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25198
diff changeset
405 return OK;
acda780ffc3e patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25198
diff changeset
406 }
acda780ffc3e patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25198
diff changeset
407
acda780ffc3e patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25198
diff changeset
408 /*
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
409 * Check for an optional number argument at 'idx'
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
410 */
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
411 int
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
412 check_for_opt_number_arg(typval_T *args, int idx)
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
413 {
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
414 return (args[idx].v_type == VAR_UNKNOWN
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
415 || check_for_number_arg(args, idx) != FAIL);
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
416 }
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
417
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
418 /*
25368
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
419 * Give an error and return FAIL unless "args[idx]" is a float or a number.
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
420 */
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
421 int
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
422 check_for_float_or_nr_arg(typval_T *args, int idx)
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
423 {
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
424 if (args[idx].v_type != VAR_FLOAT && args[idx].v_type != VAR_NUMBER)
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
425 {
26622
a28f91b893b2 patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
426 semsg(_(e_float_or_number_required_for_argument_nr), idx + 1);
25368
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
427 return FAIL;
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
428 }
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
429 return OK;
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
430 }
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
431
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
432 /*
25272
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
433 * Give an error and return FAIL unless "args[idx]" is a bool.
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
434 */
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
435 int
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
436 check_for_bool_arg(typval_T *args, int idx)
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
437 {
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
438 if (args[idx].v_type != VAR_BOOL
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
439 && !(args[idx].v_type == VAR_NUMBER
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
440 && (args[idx].vval.v_number == 0
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
441 || args[idx].vval.v_number == 1)))
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
442 {
26622
a28f91b893b2 patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
443 semsg(_(e_bool_required_for_argument_nr), idx + 1);
25272
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
444 return FAIL;
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
445 }
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
446 return OK;
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
447 }
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
448
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
449 /*
25802
5ef704de7709 patch 8.2.3436: check for optional bool type has confusing return type
Bram Moolenaar <Bram@vim.org>
parents: 25622
diff changeset
450 * Check for an optional bool argument at 'idx'.
5ef704de7709 patch 8.2.3436: check for optional bool type has confusing return type
Bram Moolenaar <Bram@vim.org>
parents: 25622
diff changeset
451 * Return FAIL if the type is wrong.
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
452 */
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
453 int
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
454 check_for_opt_bool_arg(typval_T *args, int idx)
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
455 {
25802
5ef704de7709 patch 8.2.3436: check for optional bool type has confusing return type
Bram Moolenaar <Bram@vim.org>
parents: 25622
diff changeset
456 if (args[idx].v_type == VAR_UNKNOWN)
5ef704de7709 patch 8.2.3436: check for optional bool type has confusing return type
Bram Moolenaar <Bram@vim.org>
parents: 25622
diff changeset
457 return OK;
5ef704de7709 patch 8.2.3436: check for optional bool type has confusing return type
Bram Moolenaar <Bram@vim.org>
parents: 25622
diff changeset
458 return check_for_bool_arg(args, idx);
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
459 }
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
460
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
461 /*
25806
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25802
diff changeset
462 * Give an error and return FAIL unless "args[idx]" is a blob.
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25802
diff changeset
463 */
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25802
diff changeset
464 int
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25802
diff changeset
465 check_for_blob_arg(typval_T *args, int idx)
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25802
diff changeset
466 {
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25802
diff changeset
467 if (args[idx].v_type != VAR_BLOB)
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25802
diff changeset
468 {
26622
a28f91b893b2 patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
469 semsg(_(e_blob_required_for_argument_nr), idx + 1);
25806
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25802
diff changeset
470 return FAIL;
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25802
diff changeset
471 }
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25802
diff changeset
472 return OK;
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25802
diff changeset
473 }
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25802
diff changeset
474
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25802
diff changeset
475 /*
25272
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
476 * Give an error and return FAIL unless "args[idx]" is a list.
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
477 */
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
478 int
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
479 check_for_list_arg(typval_T *args, int idx)
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
480 {
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
481 if (args[idx].v_type != VAR_LIST)
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
482 {
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
483 semsg(_(e_list_required_for_argument_nr), idx + 1);
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
484 return FAIL;
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
485 }
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
486 return OK;
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
487 }
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
488
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
489 /*
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
490 * Check for an optional list argument at 'idx'
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
491 */
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
492 int
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
493 check_for_opt_list_arg(typval_T *args, int idx)
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
494 {
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
495 return (args[idx].v_type == VAR_UNKNOWN
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
496 || check_for_list_arg(args, idx) != FAIL);
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
497 }
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
498
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
499 /*
25272
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
500 * Give an error and return FAIL unless "args[idx]" is a dict.
25198
eafc0e07b188 patch 8.2.3135: Vim9: builtin function arguments not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
501 */
eafc0e07b188 patch 8.2.3135: Vim9: builtin function arguments not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
502 int
eafc0e07b188 patch 8.2.3135: Vim9: builtin function arguments not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
503 check_for_dict_arg(typval_T *args, int idx)
eafc0e07b188 patch 8.2.3135: Vim9: builtin function arguments not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
504 {
eafc0e07b188 patch 8.2.3135: Vim9: builtin function arguments not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
505 if (args[idx].v_type != VAR_DICT)
eafc0e07b188 patch 8.2.3135: Vim9: builtin function arguments not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
506 {
26622
a28f91b893b2 patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
507 semsg(_(e_dict_required_for_argument_nr), idx + 1);
25198
eafc0e07b188 patch 8.2.3135: Vim9: builtin function arguments not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
508 return FAIL;
eafc0e07b188 patch 8.2.3135: Vim9: builtin function arguments not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
509 }
eafc0e07b188 patch 8.2.3135: Vim9: builtin function arguments not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
510 return OK;
eafc0e07b188 patch 8.2.3135: Vim9: builtin function arguments not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
511 }
eafc0e07b188 patch 8.2.3135: Vim9: builtin function arguments not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
512
eafc0e07b188 patch 8.2.3135: Vim9: builtin function arguments not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
513 /*
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
514 * Check for an optional dict argument at 'idx'
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
515 */
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
516 int
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
517 check_for_opt_dict_arg(typval_T *args, int idx)
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
518 {
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
519 return (args[idx].v_type == VAR_UNKNOWN
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
520 || check_for_dict_arg(args, idx) != FAIL);
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
521 }
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
522
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
523 /*
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
524 * Give an error and return FAIL unless "args[idx]" is a channel or a job.
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
525 */
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
526 int
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
527 check_for_chan_or_job_arg(typval_T *args, int idx)
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
528 {
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
529 if (args[idx].v_type != VAR_CHANNEL && args[idx].v_type != VAR_JOB)
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
530 {
26622
a28f91b893b2 patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
531 semsg(_(e_chan_or_job_required_for_argument_nr), idx + 1);
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
532 return FAIL;
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
533 }
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
534 return OK;
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
535 }
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
536
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
537 /*
25348
75031a22be39 patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
538 * Give an error and return FAIL unless "args[idx]" is an optional channel or a
75031a22be39 patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
539 * job.
75031a22be39 patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
540 */
75031a22be39 patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
541 int
75031a22be39 patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
542 check_for_opt_chan_or_job_arg(typval_T *args, int idx)
75031a22be39 patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
543 {
75031a22be39 patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
544 return (args[idx].v_type == VAR_UNKNOWN
75031a22be39 patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
545 || check_for_chan_or_job_arg(args, idx) != FAIL);
75031a22be39 patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
546 }
75031a22be39 patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
547
75031a22be39 patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
548 /*
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
549 * Give an error and return FAIL unless "args[idx]" is a job.
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
550 */
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
551 int
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
552 check_for_job_arg(typval_T *args, int idx)
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
553 {
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
554 if (args[idx].v_type != VAR_JOB)
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
555 {
26622
a28f91b893b2 patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
556 semsg(_(e_job_required_for_argument_nr), idx + 1);
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
557 return FAIL;
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
558 }
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
559 return OK;
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
560 }
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
561
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
562 /*
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
563 * Check for an optional job argument at 'idx'.
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
564 */
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
565 int
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
566 check_for_opt_job_arg(typval_T *args, int idx)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
567 {
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
568 return (args[idx].v_type == VAR_UNKNOWN
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
569 || check_for_job_arg(args, idx) != FAIL);
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
570 }
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
571
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
572 /*
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
573 * Give an error and return FAIL unless "args[idx]" is a string or
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
574 * a number.
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
575 */
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
576 int
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
577 check_for_string_or_number_arg(typval_T *args, int idx)
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
578 {
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
579 if (args[idx].v_type != VAR_STRING && args[idx].v_type != VAR_NUMBER)
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
580 {
26622
a28f91b893b2 patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
581 semsg(_(e_string_or_number_required_for_argument_nr), idx + 1);
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
582 return FAIL;
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
583 }
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
584 return OK;
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
585 }
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
586
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
587 /*
25314
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
588 * Check for an optional string or number argument at 'idx'.
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
589 */
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
590 int
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
591 check_for_opt_string_or_number_arg(typval_T *args, int idx)
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
592 {
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
593 return (args[idx].v_type == VAR_UNKNOWN
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
594 || check_for_string_or_number_arg(args, idx) != FAIL);
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
595 }
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
596
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
597 /*
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
598 * Give an error and return FAIL unless "args[idx]" is a buffer number.
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
599 * Buffer number can be a number or a string.
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
600 */
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
601 int
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
602 check_for_buffer_arg(typval_T *args, int idx)
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
603 {
25314
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
604 return check_for_string_or_number_arg(args, idx);
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
605 }
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
606
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
607 /*
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
608 * Check for an optional buffer argument at 'idx'
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
609 */
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
610 int
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
611 check_for_opt_buffer_arg(typval_T *args, int idx)
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
612 {
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
613 return (args[idx].v_type == VAR_UNKNOWN
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
614 || check_for_buffer_arg(args, idx));
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
615 }
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
616
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
617 /*
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
618 * Give an error and return FAIL unless "args[idx]" is a line number.
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
619 * Line number can be a number or a string.
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
620 */
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
621 int
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
622 check_for_lnum_arg(typval_T *args, int idx)
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
623 {
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
624 return check_for_string_or_number_arg(args, idx);
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
625 }
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
626
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
627 /*
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
628 * Check for an optional line number argument at 'idx'
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
629 */
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
630 int
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
631 check_for_opt_lnum_arg(typval_T *args, int idx)
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
632 {
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
633 return (args[idx].v_type == VAR_UNKNOWN
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
634 || check_for_lnum_arg(args, idx));
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
635 }
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
636
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
637 /*
25338
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
638 * Give an error and return FAIL unless "args[idx]" is a string or a blob.
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
639 */
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
640 int
25314
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
641 check_for_string_or_blob_arg(typval_T *args, int idx)
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
642 {
25314
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
643 if (args[idx].v_type != VAR_STRING && args[idx].v_type != VAR_BLOB)
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
644 {
26622
a28f91b893b2 patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
645 semsg(_(e_string_or_blob_required_for_argument_nr), idx + 1);
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
646 return FAIL;
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
647 }
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
648 return OK;
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
649 }
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
650
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
651 /*
25338
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
652 * Give an error and return FAIL unless "args[idx]" is a string or a list.
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
653 */
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
654 int
25314
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
655 check_for_string_or_list_arg(typval_T *args, int idx)
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
656 {
25314
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
657 if (args[idx].v_type != VAR_STRING && args[idx].v_type != VAR_LIST)
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
658 {
26622
a28f91b893b2 patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
659 semsg(_(e_string_or_list_required_for_argument_nr), idx + 1);
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
660 return FAIL;
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
661 }
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
662 return OK;
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
663 }
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
664
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
665 /*
26638
6fd15d82e898 patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents: 26622
diff changeset
666 * Give an error and return FAIL unless "args[idx]" is a string, a list or a
6fd15d82e898 patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents: 26622
diff changeset
667 * blob.
6fd15d82e898 patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents: 26622
diff changeset
668 */
6fd15d82e898 patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents: 26622
diff changeset
669 int
6fd15d82e898 patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents: 26622
diff changeset
670 check_for_string_or_list_or_blob_arg(typval_T *args, int idx)
6fd15d82e898 patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents: 26622
diff changeset
671 {
6fd15d82e898 patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents: 26622
diff changeset
672 if (args[idx].v_type != VAR_STRING
6fd15d82e898 patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents: 26622
diff changeset
673 && args[idx].v_type != VAR_LIST
6fd15d82e898 patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents: 26622
diff changeset
674 && args[idx].v_type != VAR_BLOB)
6fd15d82e898 patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents: 26622
diff changeset
675 {
6fd15d82e898 patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents: 26622
diff changeset
676 semsg(_(e_string_list_or_blob_required_for_argument_nr), idx + 1);
6fd15d82e898 patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents: 26622
diff changeset
677 return FAIL;
6fd15d82e898 patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents: 26622
diff changeset
678 }
6fd15d82e898 patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents: 26622
diff changeset
679 return OK;
6fd15d82e898 patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents: 26622
diff changeset
680 }
6fd15d82e898 patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents: 26622
diff changeset
681
6fd15d82e898 patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents: 26622
diff changeset
682 /*
25368
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
683 * Check for an optional string or list argument at 'idx'
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
684 */
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
685 int
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
686 check_for_opt_string_or_list_arg(typval_T *args, int idx)
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
687 {
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
688 return (args[idx].v_type == VAR_UNKNOWN
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
689 || check_for_string_or_list_arg(args, idx));
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
690 }
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
691
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
692 /*
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
693 * Give an error and return FAIL unless "args[idx]" is a string or a dict.
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
694 */
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
695 int
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
696 check_for_string_or_dict_arg(typval_T *args, int idx)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
697 {
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
698 if (args[idx].v_type != VAR_STRING && args[idx].v_type != VAR_DICT)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
699 {
26622
a28f91b893b2 patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
700 semsg(_(e_string_or_dict_required_for_argument_nr), idx + 1);
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
701 return FAIL;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
702 }
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
703 return OK;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
704 }
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
705
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
706 /*
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
707 * Give an error and return FAIL unless "args[idx]" is a string or a number
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
708 * or a list.
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
709 */
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
710 int
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
711 check_for_string_or_number_or_list_arg(typval_T *args, int idx)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
712 {
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
713 if (args[idx].v_type != VAR_STRING
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
714 && args[idx].v_type != VAR_NUMBER
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
715 && args[idx].v_type != VAR_LIST)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
716 {
26638
6fd15d82e898 patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents: 26622
diff changeset
717 semsg(_(e_string_number_or_list_required_for_argument_nr), idx + 1);
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
718 return FAIL;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
719 }
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
720 return OK;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
721 }
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
722
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
723 /*
25390
a6c347a0c6e3 patch 8.2.3232: system() does not work without a second argument
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
724 * Give an error and return FAIL unless "args[idx]" is an optional string
a6c347a0c6e3 patch 8.2.3232: system() does not work without a second argument
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
725 * or number or a list
a6c347a0c6e3 patch 8.2.3232: system() does not work without a second argument
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
726 */
a6c347a0c6e3 patch 8.2.3232: system() does not work without a second argument
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
727 int
a6c347a0c6e3 patch 8.2.3232: system() does not work without a second argument
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
728 check_for_opt_string_or_number_or_list_arg(typval_T *args, int idx)
a6c347a0c6e3 patch 8.2.3232: system() does not work without a second argument
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
729 {
a6c347a0c6e3 patch 8.2.3232: system() does not work without a second argument
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
730 return (args[idx].v_type == VAR_UNKNOWN
a6c347a0c6e3 patch 8.2.3232: system() does not work without a second argument
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
731 || check_for_string_or_number_or_list_arg(args, idx) != FAIL);
a6c347a0c6e3 patch 8.2.3232: system() does not work without a second argument
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
732 }
a6c347a0c6e3 patch 8.2.3232: system() does not work without a second argument
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
733
a6c347a0c6e3 patch 8.2.3232: system() does not work without a second argument
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
734 /*
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
735 * Give an error and return FAIL unless "args[idx]" is a string or a list
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
736 * or a dict.
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
737 */
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
738 int
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
739 check_for_string_or_list_or_dict_arg(typval_T *args, int idx)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
740 {
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
741 if (args[idx].v_type != VAR_STRING
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
742 && args[idx].v_type != VAR_LIST
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
743 && args[idx].v_type != VAR_DICT)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
744 {
26622
a28f91b893b2 patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
745 semsg(_(e_string_list_or_dict_required_for_argument_nr), idx + 1);
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
746 return FAIL;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
747 }
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
748 return OK;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
749 }
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
750
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
751 /*
25338
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
752 * Give an error and return FAIL unless "args[idx]" is a list or a blob.
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
753 */
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
754 int
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
755 check_for_list_or_blob_arg(typval_T *args, int idx)
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
756 {
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
757 if (args[idx].v_type != VAR_LIST && args[idx].v_type != VAR_BLOB)
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
758 {
26638
6fd15d82e898 patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents: 26622
diff changeset
759 semsg(_(e_list_or_blob_required_for_argument_nr), idx + 1);
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
760 return FAIL;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
761 }
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
762 return OK;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
763 }
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
764
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
765 /*
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
766 * Give an error and return FAIL unless "args[idx]" is a list or dict
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
767 */
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
768 int
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
769 check_for_list_or_dict_arg(typval_T *args, int idx)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
770 {
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
771 if (args[idx].v_type != VAR_LIST
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
772 && args[idx].v_type != VAR_DICT)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
773 {
26622
a28f91b893b2 patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
774 semsg(_(e_list_or_dict_required_for_argument_nr), idx + 1);
25338
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
775 return FAIL;
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
776 }
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
777 return OK;
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
778 }
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
779
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
780 /*
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
781 * Give an error and return FAIL unless "args[idx]" is a list or dict or a
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
782 * blob.
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
783 */
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
784 int
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
785 check_for_list_or_dict_or_blob_arg(typval_T *args, int idx)
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
786 {
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
787 if (args[idx].v_type != VAR_LIST
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
788 && args[idx].v_type != VAR_DICT
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
789 && args[idx].v_type != VAR_BLOB)
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
790 {
26622
a28f91b893b2 patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
791 semsg(_(e_list_dict_or_blob_required_for_argument_nr), idx + 1);
25338
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
792 return FAIL;
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
793 }
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
794 return OK;
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
795 }
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
796
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
797 /*
26585
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
798 * Give an error and return FAIL unless "args[idx]" is a list or dict or a
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
799 * blob or a string.
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
800 */
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
801 int
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
802 check_for_list_or_dict_or_blob_or_string_arg(typval_T *args, int idx)
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
803 {
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
804 if (args[idx].v_type != VAR_LIST
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
805 && args[idx].v_type != VAR_DICT
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
806 && args[idx].v_type != VAR_BLOB
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
807 && args[idx].v_type != VAR_STRING)
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
808 {
26622
a28f91b893b2 patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
809 semsg(_(e_list_dict_blob_or_string_required_for_argument_nr), idx + 1);
26585
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
810 return FAIL;
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
811 }
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
812 return OK;
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
813 }
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
814
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
815 /*
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
816 * Give an error and return FAIL unless "args[idx]" is an optional buffer
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
817 * number or a dict.
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
818 */
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
819 int
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
820 check_for_opt_buffer_or_dict_arg(typval_T *args, int idx)
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
821 {
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
822 if (args[idx].v_type != VAR_UNKNOWN
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25368
diff changeset
823 && args[idx].v_type != VAR_STRING
25314
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
824 && args[idx].v_type != VAR_NUMBER
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
825 && args[idx].v_type != VAR_DICT)
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
826 {
26622
a28f91b893b2 patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
827 semsg(_(e_string_required_for_argument_nr), idx + 1);
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
828 return FAIL;
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
829 }
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
830 return OK;
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
831 }
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
832
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
833 /*
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
834 * 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
835 * 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
836 * 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
837 * 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
838 * 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
839 * Never returns NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
840 * 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
841 * NULL on error.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
842 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
843 char_u *
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
844 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
845 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
846 static char_u mybuf[NUMBUFLEN];
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
847
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
848 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
849 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
850
23786
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
851 /*
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
852 * 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
853 */
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
854 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
855 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
856 {
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
857 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
858 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
859 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
860
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
861 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
862 }
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
863
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
864 char_u *
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
865 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
866 {
24812
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 24614
diff changeset
867 char_u *res = tv_get_string_buf_chk(varp, buf);
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
868
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
869 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
870 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
871
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
872 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
873 * 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
874 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
875 char_u *
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
876 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
877 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
878 static char_u mybuf[NUMBUFLEN];
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
879
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
880 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
881 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
882
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
883 char_u *
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
884 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
885 {
23786
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
886 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
887 }
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
888
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
889 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
890 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
891 {
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
892 switch (varp->v_type)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
893 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
894 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
895 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
896 {
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
897 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
898 break;
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
899 }
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
900 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
901 (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
902 return buf;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
903 case VAR_FUNC:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
904 case VAR_PARTIAL:
25198
eafc0e07b188 patch 8.2.3135: Vim9: builtin function arguments not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
905 emsg(_("E729: Using a Funcref as a String"));
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
906 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
907 case VAR_LIST:
25198
eafc0e07b188 patch 8.2.3135: Vim9: builtin function arguments not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
908 emsg(_("E730: Using a List as a String"));
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
909 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
910 case VAR_DICT:
25198
eafc0e07b188 patch 8.2.3135: Vim9: builtin function arguments not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
911 emsg(_("E731: Using a Dictionary as a String"));
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
912 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
913 case VAR_FLOAT:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
914 #ifdef FEAT_FLOAT
24820
b1093c1ac109 patch 8.2.2948: substitute() accepts a number but not a float expression
Bram Moolenaar <Bram@vim.org>
parents: 24812
diff changeset
915 if (strict)
b1093c1ac109 patch 8.2.2948: substitute() accepts a number but not a float expression
Bram Moolenaar <Bram@vim.org>
parents: 24812
diff changeset
916 {
b1093c1ac109 patch 8.2.2948: substitute() accepts a number but not a float expression
Bram Moolenaar <Bram@vim.org>
parents: 24812
diff changeset
917 emsg(_(e_float_as_string));
b1093c1ac109 patch 8.2.2948: substitute() accepts a number but not a float expression
Bram Moolenaar <Bram@vim.org>
parents: 24812
diff changeset
918 break;
b1093c1ac109 patch 8.2.2948: substitute() accepts a number but not a float expression
Bram Moolenaar <Bram@vim.org>
parents: 24812
diff changeset
919 }
b1093c1ac109 patch 8.2.2948: substitute() accepts a number but not a float expression
Bram Moolenaar <Bram@vim.org>
parents: 24812
diff changeset
920 vim_snprintf((char *)buf, NUMBUFLEN, "%g", varp->vval.v_float);
b1093c1ac109 patch 8.2.2948: substitute() accepts a number but not a float expression
Bram Moolenaar <Bram@vim.org>
parents: 24812
diff changeset
921 return buf;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
922 #endif
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
923 case VAR_STRING:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
924 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
925 return varp->vval.v_string;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
926 return (char_u *)"";
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
927 case VAR_BOOL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
928 case VAR_SPECIAL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
929 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
930 return buf;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
931 case VAR_BLOB:
25198
eafc0e07b188 patch 8.2.3135: Vim9: builtin function arguments not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
932 emsg(_("E976: Using a Blob as a String"));
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
933 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
934 case VAR_JOB:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
935 #ifdef FEAT_JOB_CHANNEL
24812
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 24614
diff changeset
936 if (in_vim9script())
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
937 {
24812
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 24614
diff changeset
938 semsg(_(e_using_invalid_value_as_string_str), "job");
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 24614
diff changeset
939 break;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
940 }
24812
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 24614
diff changeset
941 return job_to_string_buf(varp, buf);
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
942 #endif
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
943 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
944 case VAR_CHANNEL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
945 #ifdef FEAT_JOB_CHANNEL
24812
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 24614
diff changeset
946 if (in_vim9script())
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
947 {
24812
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 24614
diff changeset
948 semsg(_(e_using_invalid_value_as_string_str), "channel");
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 24614
diff changeset
949 break;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
950 }
24812
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 24614
diff changeset
951 return channel_to_string_buf(varp, buf);
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
952 #endif
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
953 break;
24936
345619f35112 patch 8.2.3005: Vim9: using a void value does not give a proper error message
Bram Moolenaar <Bram@vim.org>
parents: 24820
diff changeset
954 case VAR_VOID:
345619f35112 patch 8.2.3005: Vim9: using a void value does not give a proper error message
Bram Moolenaar <Bram@vim.org>
parents: 24820
diff changeset
955 emsg(_(e_cannot_use_void_value));
345619f35112 patch 8.2.3005: Vim9: using a void value does not give a proper error message
Bram Moolenaar <Bram@vim.org>
parents: 24820
diff changeset
956 break;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
957 case VAR_UNKNOWN:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
958 case VAR_ANY:
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24424
diff changeset
959 case VAR_INSTR:
24614
07b3d21a8b4b patch 8.2.2846: Vim9: "echo Func()" does not give an error for using void
Bram Moolenaar <Bram@vim.org>
parents: 24610
diff changeset
960 semsg(_(e_using_invalid_value_as_string_str),
07b3d21a8b4b patch 8.2.2846: Vim9: "echo Func()" does not give an error for using void
Bram Moolenaar <Bram@vim.org>
parents: 24610
diff changeset
961 vartype_name(varp->v_type));
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
962 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
963 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
964 return NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
965 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
966
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
967 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
968 * 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
969 * string() on Dict, List, etc.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
970 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
971 char_u *
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
972 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
973 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
974 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
975 || varp->v_type == VAR_DICT
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
976 || varp->v_type == VAR_BLOB
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
977 || varp->v_type == VAR_FUNC
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
978 || varp->v_type == VAR_PARTIAL
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
979 || varp->v_type == VAR_FLOAT)
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 typval_T tmp;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
982
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
983 f_string(varp, &tmp);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
984 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
985 clear_tv(varp);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
986 *varp = tmp;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
987 return tmp.vval.v_string;
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 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
990 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
991
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
992 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
993 * 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
994 * 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
995 * TRUE.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
996 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
997 int
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
998 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
999 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1000 int lock = 0;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1001
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1002 switch (tv->v_type)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1003 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1004 case VAR_BLOB:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1005 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
1006 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
1007 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1008 case VAR_LIST:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1009 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
1010 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
1011 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1012 case VAR_DICT:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1013 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
1014 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
1015 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1016 default:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1017 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1018 }
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
1019 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
1020 || (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
1021 }
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 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1024 * 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
1025 * 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
1026 * 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
1027 * 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
1028 * make a copy later.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1029 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1030 void
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1031 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
1032 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1033 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
1034 to->v_lock = 0;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1035 switch (from->v_type)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1036 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1037 case VAR_NUMBER:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1038 case VAR_BOOL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1039 case VAR_SPECIAL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1040 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
1041 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1042 case VAR_FLOAT:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1043 #ifdef FEAT_FLOAT
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1044 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
1045 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1046 #endif
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1047 case VAR_JOB:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1048 #ifdef FEAT_JOB_CHANNEL
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1049 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
1050 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
1051 ++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
1052 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1053 #endif
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1054 case VAR_CHANNEL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1055 #ifdef FEAT_JOB_CHANNEL
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1056 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
1057 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
1058 ++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
1059 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1060 #endif
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24424
diff changeset
1061 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
1062 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
1063 break;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24424
diff changeset
1064
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1065 case VAR_STRING:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1066 case VAR_FUNC:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1067 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
1068 to->vval.v_string = NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1069 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1070 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1071 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
1072 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
1073 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
1074 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1075 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1076 case VAR_PARTIAL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1077 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
1078 to->vval.v_partial = NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1079 else
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 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
1082 ++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
1083 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1084 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1085 case VAR_BLOB:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1086 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
1087 to->vval.v_blob = NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1088 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1089 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1090 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
1091 ++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
1092 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1093 break;
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 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
1096 to->vval.v_list = NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1097 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1098 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1099 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
1100 ++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
1101 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1102 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1103 case VAR_DICT:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1104 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
1105 to->vval.v_dict = NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1106 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1107 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1108 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
1109 ++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
1110 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1111 break;
24940
0c415a0f54f9 patch 8.2.3007: Vim9: test for void value fails
Bram Moolenaar <Bram@vim.org>
parents: 24936
diff changeset
1112 case VAR_VOID:
0c415a0f54f9 patch 8.2.3007: Vim9: test for void value fails
Bram Moolenaar <Bram@vim.org>
parents: 24936
diff changeset
1113 emsg(_(e_cannot_use_void_value));
0c415a0f54f9 patch 8.2.3007: Vim9: test for void value fails
Bram Moolenaar <Bram@vim.org>
parents: 24936
diff changeset
1114 break;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1115 case VAR_UNKNOWN:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1116 case VAR_ANY:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1117 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
1118 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1119 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1120 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1121
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1122 /*
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1123 * Compare "tv1" and "tv2".
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1124 * Put the result in "tv1". Caller should clear "tv2".
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1125 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1126 int
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1127 typval_compare(
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1128 typval_T *tv1, // first operand
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1129 typval_T *tv2, // second operand
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1130 exprtype_T type, // operator
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1131 int ic) // ignore case
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1132 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1133 varnumber_T n1, n2;
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1134 int res = 0;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1135 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
1136
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1137 if (type_is && tv1->v_type != tv2->v_type)
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1138 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1139 // 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
1140 // it means TRUE.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1141 n1 = (type == EXPR_ISNOT);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1142 }
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1143 else if (tv1->v_type == VAR_BLOB || tv2->v_type == VAR_BLOB)
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1144 {
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1145 if (typval_compare_blob(tv1, tv2, type, &res) == FAIL)
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1146 {
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1147 clear_tv(tv1);
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1148 return FAIL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1149 }
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1150 n1 = res;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1151 }
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1152 else if (tv1->v_type == VAR_LIST || tv2->v_type == VAR_LIST)
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1153 {
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1154 if (typval_compare_list(tv1, tv2, type, ic, &res) == FAIL)
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1155 {
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1156 clear_tv(tv1);
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1157 return FAIL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1158 }
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1159 n1 = res;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1160 }
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1161 else if (tv1->v_type == VAR_DICT || tv2->v_type == VAR_DICT)
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1162 {
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1163 if (typval_compare_dict(tv1, tv2, type, ic, &res) == FAIL)
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1164 {
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1165 clear_tv(tv1);
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1166 return FAIL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1167 }
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1168 n1 = res;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1169 }
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1170 else if (tv1->v_type == VAR_FUNC || tv2->v_type == VAR_FUNC
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1171 || tv1->v_type == VAR_PARTIAL || tv2->v_type == VAR_PARTIAL)
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1172 {
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1173 if (typval_compare_func(tv1, tv2, type, ic, &res) == FAIL)
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1174 {
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1175 clear_tv(tv1);
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1176 return FAIL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1177 }
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1178 n1 = res;
20587
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 #ifdef FEAT_FLOAT
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1182 // 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
1183 // When using "=~" or "!~", always compare as string.
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1184 else if ((tv1->v_type == VAR_FLOAT || tv2->v_type == VAR_FLOAT)
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1185 && 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
1186 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1187 float_T f1, f2;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1188
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1189 f1 = tv_get_float(tv1);
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1190 f2 = tv_get_float(tv2);
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1191 n1 = FALSE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1192 switch (type)
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 case EXPR_IS:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1195 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
1196 case EXPR_ISNOT:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1197 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
1198 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
1199 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
1200 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
1201 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
1202 case EXPR_UNKNOWN:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1203 case EXPR_MATCH:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1204 default: break; // avoid gcc warning
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1205 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1206 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1207 #endif
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1208
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1209 // 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
1210 // When using "=~" or "!~", always compare as string.
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1211 else if ((tv1->v_type == VAR_NUMBER || tv2->v_type == VAR_NUMBER)
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1212 && 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
1213 {
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1214 n1 = tv_get_number(tv1);
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1215 n2 = tv_get_number(tv2);
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1216 switch (type)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1217 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1218 case EXPR_IS:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1219 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
1220 case EXPR_ISNOT:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1221 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
1222 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
1223 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
1224 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
1225 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
1226 case EXPR_UNKNOWN:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1227 case EXPR_MATCH:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1228 default: break; // avoid gcc warning
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 }
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1231 else if (in_vim9script() && (tv1->v_type == VAR_BOOL
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1232 || tv2->v_type == VAR_BOOL
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1233 || (tv1->v_type == VAR_SPECIAL
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1234 && tv2->v_type == VAR_SPECIAL)))
23555
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1235 {
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1236 if (tv1->v_type != tv2->v_type)
23555
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1237 {
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1238 semsg(_(e_cannot_compare_str_with_str),
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1239 vartype_name(tv1->v_type), vartype_name(tv2->v_type));
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1240 clear_tv(tv1);
23555
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1241 return FAIL;
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1242 }
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1243 n1 = tv1->vval.v_number;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1244 n2 = tv2->vval.v_number;
23555
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1245 switch (type)
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1246 {
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1247 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
1248 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
1249 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
1250 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
1251 default:
25278
55c85c3a43a0 patch 8.2.3176: Vim9: no type error for comparing number with string
Bram Moolenaar <Bram@vim.org>
parents: 25272
diff changeset
1252 semsg(_(e_invalid_operation_for_str),
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1253 vartype_name(tv1->v_type));
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1254 clear_tv(tv1);
23555
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1255 return FAIL;
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1256 }
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1257 }
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1258 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1259 {
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1260 if (typval_compare_string(tv1, tv2, type, ic, &res) == FAIL)
25278
55c85c3a43a0 patch 8.2.3176: Vim9: no type error for comparing number with string
Bram Moolenaar <Bram@vim.org>
parents: 25272
diff changeset
1261 {
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1262 clear_tv(tv1);
25278
55c85c3a43a0 patch 8.2.3176: Vim9: no type error for comparing number with string
Bram Moolenaar <Bram@vim.org>
parents: 25272
diff changeset
1263 return FAIL;
55c85c3a43a0 patch 8.2.3176: Vim9: no type error for comparing number with string
Bram Moolenaar <Bram@vim.org>
parents: 25272
diff changeset
1264 }
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1265 n1 = res;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1266 }
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1267 clear_tv(tv1);
21425
a6c316ef161a patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
1268 if (in_vim9script())
a6c316ef161a patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
1269 {
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1270 tv1->v_type = VAR_BOOL;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1271 tv1->vval.v_number = n1 ? VVAL_TRUE : VVAL_FALSE;
21425
a6c316ef161a patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
1272 }
a6c316ef161a patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
1273 else
a6c316ef161a patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
1274 {
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1275 tv1->v_type = VAR_NUMBER;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1276 tv1->vval.v_number = n1;
21425
a6c316ef161a patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
1277 }
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1278
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1279 return OK;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1280 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1281
23788
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
1282 /*
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1283 * Compare "tv1" to "tv2" as lists acording to "type" and "ic".
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1284 * Put the result, false or true, in "res".
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1285 * Return FAIL and give an error message when the comparison can't be done.
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1286 */
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1287 int
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1288 typval_compare_list(
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1289 typval_T *tv1,
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1290 typval_T *tv2,
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1291 exprtype_T type,
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1292 int ic,
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1293 int *res)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1294 {
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1295 int val = 0;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1296
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1297 if (type == EXPR_IS || type == EXPR_ISNOT)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1298 {
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1299 val = (tv1->v_type == tv2->v_type
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1300 && tv1->vval.v_list == tv2->vval.v_list);
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1301 if (type == EXPR_ISNOT)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1302 val = !val;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1303 }
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1304 else if (tv1->v_type != tv2->v_type
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1305 || (type != EXPR_EQUAL && type != EXPR_NEQUAL))
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1306 {
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1307 if (tv1->v_type != tv2->v_type)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1308 emsg(_("E691: Can only compare List with List"));
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1309 else
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1310 emsg(_("E692: Invalid operation for List"));
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1311 return FAIL;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1312 }
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1313 else
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1314 {
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1315 val = list_equal(tv1->vval.v_list, tv2->vval.v_list,
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1316 ic, FALSE);
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1317 if (type == EXPR_NEQUAL)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1318 val = !val;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1319 }
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1320 *res = val;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1321 return OK;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1322 }
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1323
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1324 /*
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1325 * Compare "tv1" to "tv2" as blobs acording to "type".
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1326 * Put the result, false or true, in "res".
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1327 * Return FAIL and give an error message when the comparison can't be done.
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1328 */
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1329 int
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1330 typval_compare_blob(
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1331 typval_T *tv1,
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1332 typval_T *tv2,
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1333 exprtype_T type,
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1334 int *res)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1335 {
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1336 int val = 0;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1337
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1338 if (type == EXPR_IS || type == EXPR_ISNOT)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1339 {
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1340 val = (tv1->v_type == tv2->v_type
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1341 && tv1->vval.v_blob == tv2->vval.v_blob);
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1342 if (type == EXPR_ISNOT)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1343 val = !val;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1344 }
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1345 else if (tv1->v_type != tv2->v_type
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1346 || (type != EXPR_EQUAL && type != EXPR_NEQUAL))
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1347 {
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1348 if (tv1->v_type != tv2->v_type)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1349 emsg(_("E977: Can only compare Blob with Blob"));
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1350 else
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1351 emsg(_(e_invalblob));
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1352 return FAIL;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1353 }
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1354 else
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1355 {
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1356 val = blob_equal(tv1->vval.v_blob, tv2->vval.v_blob);
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1357 if (type == EXPR_NEQUAL)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1358 val = !val;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1359 }
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1360 *res = val;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1361 return OK;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1362 }
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1363
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1364 /*
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1365 * Compare "tv1" to "tv2" as dictionaries acording to "type" and "ic".
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1366 * Put the result, false or true, in "res".
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1367 * Return FAIL and give an error message when the comparison can't be done.
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1368 */
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1369 int
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1370 typval_compare_dict(
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1371 typval_T *tv1,
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1372 typval_T *tv2,
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1373 exprtype_T type,
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1374 int ic,
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1375 int *res)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1376 {
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1377 int val;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1378
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1379 if (type == EXPR_IS || type == EXPR_ISNOT)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1380 {
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1381 val = (tv1->v_type == tv2->v_type
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1382 && tv1->vval.v_dict == tv2->vval.v_dict);
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1383 if (type == EXPR_ISNOT)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1384 val = !val;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1385 }
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1386 else if (tv1->v_type != tv2->v_type
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1387 || (type != EXPR_EQUAL && type != EXPR_NEQUAL))
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1388 {
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1389 if (tv1->v_type != tv2->v_type)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1390 emsg(_("E735: Can only compare Dictionary with Dictionary"));
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1391 else
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1392 emsg(_("E736: Invalid operation for Dictionary"));
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1393 return FAIL;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1394 }
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1395 else
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1396 {
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1397 val = dict_equal(tv1->vval.v_dict, tv2->vval.v_dict, ic, FALSE);
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1398 if (type == EXPR_NEQUAL)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1399 val = !val;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1400 }
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1401 *res = val;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1402 return OK;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1403 }
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1404
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1405 /*
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1406 * Compare "tv1" to "tv2" as funcrefs acording to "type" and "ic".
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1407 * Put the result, false or true, in "res".
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1408 * Return FAIL and give an error message when the comparison can't be done.
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1409 */
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1410 int
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1411 typval_compare_func(
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1412 typval_T *tv1,
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1413 typval_T *tv2,
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1414 exprtype_T type,
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1415 int ic,
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1416 int *res)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1417 {
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1418 int val = 0;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1419
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1420 if (type != EXPR_EQUAL && type != EXPR_NEQUAL
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1421 && type != EXPR_IS && type != EXPR_ISNOT)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1422 {
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1423 emsg(_("E694: Invalid operation for Funcrefs"));
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1424 return FAIL;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1425 }
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1426 if ((tv1->v_type == VAR_PARTIAL && tv1->vval.v_partial == NULL)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1427 || (tv2->v_type == VAR_PARTIAL && tv2->vval.v_partial == NULL))
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1428 // When both partials are NULL, then they are equal.
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1429 // Otherwise they are not equal.
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1430 val = (tv1->vval.v_partial == tv2->vval.v_partial);
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1431 else if (type == EXPR_IS || type == EXPR_ISNOT)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1432 {
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1433 if (tv1->v_type == VAR_FUNC && tv2->v_type == VAR_FUNC)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1434 // strings are considered the same if their value is
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1435 // the same
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1436 val = tv_equal(tv1, tv2, ic, FALSE);
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1437 else if (tv1->v_type == VAR_PARTIAL && tv2->v_type == VAR_PARTIAL)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1438 val = (tv1->vval.v_partial == tv2->vval.v_partial);
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1439 else
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1440 val = FALSE;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1441 }
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1442 else
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1443 val = tv_equal(tv1, tv2, ic, FALSE);
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1444 if (type == EXPR_NEQUAL || type == EXPR_ISNOT)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1445 val = !val;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1446 *res = val;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1447 return OK;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1448 }
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1449
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1450 /*
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1451 * Compare "tv1" to "tv2" as strings according to "type" and "ic".
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1452 * Put the result, false or true, in "res".
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1453 * Return FAIL and give an error message when the comparison can't be done.
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1454 */
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1455 int
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1456 typval_compare_string(
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1457 typval_T *tv1,
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1458 typval_T *tv2,
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1459 exprtype_T type,
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1460 int ic,
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1461 int *res)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1462 {
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1463 int i = 0;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1464 int val = FALSE;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1465 char_u *s1, *s2;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1466 char_u buf1[NUMBUFLEN], buf2[NUMBUFLEN];
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1467
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1468 if (in_vim9script()
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1469 && ((tv1->v_type != VAR_STRING && tv1->v_type != VAR_SPECIAL)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1470 || (tv2->v_type != VAR_STRING && tv2->v_type != VAR_SPECIAL)))
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1471 {
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1472 semsg(_(e_cannot_compare_str_with_str),
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1473 vartype_name(tv1->v_type), vartype_name(tv2->v_type));
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1474 return FAIL;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1475 }
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1476 s1 = tv_get_string_buf(tv1, buf1);
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1477 s2 = tv_get_string_buf(tv2, buf2);
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1478 if (type != EXPR_MATCH && type != EXPR_NOMATCH)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1479 i = ic ? MB_STRICMP(s1, s2) : STRCMP(s1, s2);
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1480 switch (type)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1481 {
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1482 case EXPR_IS:
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1483 case EXPR_EQUAL: val = (i == 0); break;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1484 case EXPR_ISNOT:
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1485 case EXPR_NEQUAL: val = (i != 0); break;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1486 case EXPR_GREATER: val = (i > 0); break;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1487 case EXPR_GEQUAL: val = (i >= 0); break;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1488 case EXPR_SMALLER: val = (i < 0); break;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1489 case EXPR_SEQUAL: val = (i <= 0); break;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1490
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1491 case EXPR_MATCH:
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1492 case EXPR_NOMATCH:
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1493 val = pattern_match(s2, s1, ic);
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1494 if (type == EXPR_NOMATCH)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1495 val = !val;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1496 break;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1497
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1498 default: break; // avoid gcc warning
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1499 }
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1500 *res = val;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1501 return OK;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1502 }
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1503 /*
23788
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
1504 * 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
1505 * 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
1506 * 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
1507 */
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1508 char_u *
23788
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
1509 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
1510 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1511 char_u *tofree;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1512 char_u numbuf[NUMBUFLEN];
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1513 char_u *ret = NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1514
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1515 if (arg == NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1516 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
1517 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
1518 {
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
1519 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
1520 : 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
1521 }
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
1522 else
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
1523 {
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
1524 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
1525 // 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
1526 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
1527 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
1528 }
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1529 return ret;
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 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1533 * 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
1534 * 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
1535 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1536 int
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1537 tv_islocked(typval_T *tv)
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 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
1540 || (tv->v_type == VAR_LIST
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1541 && tv->vval.v_list != NULL
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1542 && (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
1543 || (tv->v_type == VAR_DICT
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1544 && tv->vval.v_dict != NULL
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1545 && (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
1546 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1547
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1548 static int
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1549 func_equal(
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1550 typval_T *tv1,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1551 typval_T *tv2,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1552 int ic) // ignore case
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 char_u *s1, *s2;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1555 dict_T *d1, *d2;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1556 int a1, a2;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1557 int i;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1558
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1559 // 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
1560 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
1561 : 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
1562 if (s1 != NULL && *s1 == NUL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1563 s1 = NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1564 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
1565 : 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
1566 if (s2 != NULL && *s2 == NUL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1567 s2 = NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1568 if (s1 == NULL || s2 == NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1569 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1570 if (s1 != s2)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1571 return FALSE;
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 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
1574 return FALSE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1575
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1576 // 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
1577 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
1578 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
1579 if (d1 == NULL || d2 == NULL)
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 if (d1 != d2)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1582 return FALSE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1583 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1584 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
1585 return 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 // 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
1588 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
1589 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
1590 if (a1 != a2)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1591 return FALSE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1592 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
1593 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
1594 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
1595 return FALSE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1596
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1597 return TRUE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1598 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1599
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 * 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
1602 * 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
1603 * 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
1604 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1605 int
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1606 tv_equal(
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1607 typval_T *tv1,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1608 typval_T *tv2,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1609 int ic, // ignore case
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1610 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
1611 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1612 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
1613 char_u *s1, *s2;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1614 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
1615 int r;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1616 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
1617
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1618 // 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
1619 // 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
1620 // 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
1621 // 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
1622 // 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
1623 // recursiveness quickly.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1624 if (!recursive)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1625 tv_equal_recurse_limit = 1000;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1626 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
1627 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1628 --tv_equal_recurse_limit;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1629 return TRUE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1630 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1631
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1632 // 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
1633 // arguments.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1634 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
1635 || (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
1636 && (tv2->v_type == VAR_FUNC
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1637 || (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
1638 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1639 ++recursive_cnt;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1640 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
1641 --recursive_cnt;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1642 return r;
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
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
1645 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
1646 && ((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
1647 || (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
1648 return FALSE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1649
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1650 switch (tv1->v_type)
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 case VAR_LIST:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1653 ++recursive_cnt;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1654 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
1655 --recursive_cnt;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1656 return r;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1657
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1658 case VAR_DICT:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1659 ++recursive_cnt;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1660 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
1661 --recursive_cnt;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1662 return r;
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 case VAR_BLOB:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1665 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
1666
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1667 case VAR_NUMBER:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1668 case VAR_BOOL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1669 case VAR_SPECIAL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1670 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
1671
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1672 case VAR_STRING:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1673 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
1674 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
1675 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
1676
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1677 case VAR_FLOAT:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1678 #ifdef FEAT_FLOAT
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1679 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
1680 #endif
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1681 case VAR_JOB:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1682 #ifdef FEAT_JOB_CHANNEL
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1683 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
1684 #endif
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1685 case VAR_CHANNEL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1686 #ifdef FEAT_JOB_CHANNEL
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1687 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
1688 #endif
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24424
diff changeset
1689 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
1690 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
1691
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1692 case VAR_PARTIAL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1693 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
1694
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1695 case VAR_FUNC:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1696 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
1697
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1698 case VAR_UNKNOWN:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1699 case VAR_ANY:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1700 case VAR_VOID:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1701 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1702 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1703
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1704 // 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
1705 // 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
1706 return FALSE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1707 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1708
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1709 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1710 * Get an option value.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1711 * "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
1712 * "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
1713 * Return OK or FAIL.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1714 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1715 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
1716 eval_option(
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1717 char_u **arg,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1718 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
1719 int evaluate)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1720 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1721 char_u *option_end;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1722 long numval;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1723 char_u *stringval;
23422
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
1724 getoption_T opt_type;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1725 int c;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1726 int working = (**arg == '+'); // has("+option")
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1727 int ret = OK;
26441
65ab0b035dd8 patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents: 26342
diff changeset
1728 int scope;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1729
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1730 // Isolate the option name and find its value.
26441
65ab0b035dd8 patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents: 26342
diff changeset
1731 option_end = find_option_end(arg, &scope);
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1732 if (option_end == NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1733 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1734 if (rettv != NULL)
26602
fac6673086df patch 8.2.3830: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26585
diff changeset
1735 semsg(_(e_option_name_missing_str), *arg);
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1736 return FAIL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1737 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1738
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1739 if (!evaluate)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1740 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1741 *arg = option_end;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1742 return OK;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1743 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1744
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1745 c = *option_end;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1746 *option_end = NUL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1747 opt_type = get_option_value(*arg, &numval,
26441
65ab0b035dd8 patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents: 26342
diff changeset
1748 rettv == NULL ? NULL : &stringval, NULL, scope);
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1749
23422
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
1750 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
1751 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1752 if (rettv != NULL)
26602
fac6673086df patch 8.2.3830: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26585
diff changeset
1753 semsg(_(e_unknown_option_str), *arg);
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1754 ret = FAIL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1755 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1756 else if (rettv != NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1757 {
23519
cb66613dd9d5 patch 8.2.2302: Vim9: using an option value may use uninitialized memory
Bram Moolenaar <Bram@vim.org>
parents: 23422
diff changeset
1758 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
1759 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
1760 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1761 rettv->v_type = VAR_STRING;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1762 rettv->vval.v_string = NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1763 }
23422
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
1764 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
1765 {
23422
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
1766 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
1767 ? VAR_BOOL : VAR_NUMBER;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1768 rettv->vval.v_number = 0;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1769 }
23422
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
1770 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
1771 {
23422
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
1772 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
1773 {
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
1774 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
1775 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
1776 }
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
1777 else
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
1778 {
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
1779 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
1780 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
1781 }
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1782 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1783 else // string option
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1784 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1785 rettv->v_type = VAR_STRING;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1786 rettv->vval.v_string = stringval;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1787 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1788 }
23422
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
1789 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
1790 || 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
1791 || 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
1792 ret = FAIL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1793
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1794 *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
1795 *arg = option_end;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1796
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1797 return ret;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1798 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1799
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1800 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1801 * 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
1802 * Return OK or FAIL.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1803 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1804 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
1805 eval_number(
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1806 char_u **arg,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1807 typval_T *rettv,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1808 int evaluate,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1809 int want_string UNUSED)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1810 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1811 int len;
25622
15b54e0a576b patch 8.2.3347: check for legacy script is incomplete
Bram Moolenaar <Bram@vim.org>
parents: 25585
diff changeset
1812 int skip_quotes = !in_old_script(4);
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1813 #ifdef FEAT_FLOAT
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1814 char_u *p;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1815 int get_float = FALSE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1816
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1817 // 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
1818 // "[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
1819 // 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
1820 // 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
1821 // omitted.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1822 // 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
1823 // ":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
1824 if (**arg == '.')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1825 p = *arg;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1826 else
25557
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25443
diff changeset
1827 {
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25443
diff changeset
1828 p = *arg + 1;
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25443
diff changeset
1829 if (skip_quotes)
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25443
diff changeset
1830 for (;;)
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25443
diff changeset
1831 {
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25443
diff changeset
1832 if (*p == '\'')
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25443
diff changeset
1833 ++p;
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25443
diff changeset
1834 if (!vim_isdigit(*p))
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25443
diff changeset
1835 break;
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25443
diff changeset
1836 p = skipdigits(p);
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25443
diff changeset
1837 }
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25443
diff changeset
1838 else
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25443
diff changeset
1839 p = skipdigits(p);
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25443
diff changeset
1840 }
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1841 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
1842 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1843 get_float = TRUE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1844 p = skipdigits(p + 2);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1845 if (*p == 'e' || *p == 'E')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1846 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1847 ++p;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1848 if (*p == '-' || *p == '+')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1849 ++p;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1850 if (!vim_isdigit(*p))
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1851 get_float = FALSE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1852 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1853 p = skipdigits(p + 1);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1854 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1855 if (ASCII_ISALPHA(*p) || *p == '.')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1856 get_float = FALSE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1857 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1858 if (get_float)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1859 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1860 float_T f;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1861
25557
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25443
diff changeset
1862 *arg += string2float(*arg, &f, skip_quotes);
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1863 if (evaluate)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1864 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1865 rettv->v_type = VAR_FLOAT;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1866 rettv->vval.v_float = f;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1867 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1868 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1869 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1870 #endif
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1871 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
1872 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1873 char_u *bp;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1874 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
1875
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1876 // Blob constant: 0z0123456789abcdef
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1877 if (evaluate)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1878 blob = blob_alloc();
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1879 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
1880 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1881 if (!vim_isxdigit(bp[1]))
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1882 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1883 if (blob != NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1884 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1885 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
1886 ga_clear(&blob->bv_ga);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1887 VIM_CLEAR(blob);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1888 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1889 return FAIL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1890 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1891 if (blob != NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1892 ga_append(&blob->bv_ga,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1893 (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
1894 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
1895 ++bp;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1896 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1897 if (blob != NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1898 rettv_blob_set(rettv, blob);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1899 *arg = bp;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1900 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1901 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1902 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1903 varnumber_T n;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1904
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1905 // decimal, hex or octal number
25557
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25443
diff changeset
1906 vim_str2nr(*arg, NULL, &len, skip_quotes
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1907 ? STR2NR_NO_OCT + STR2NR_QUOTE
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1908 : 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
1909 if (len == 0)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1910 {
26342
936f77929f16 patch 8.2.3702: first key in dict is seen as curly expression and fails
Bram Moolenaar <Bram@vim.org>
parents: 25806
diff changeset
1911 if (evaluate)
936f77929f16 patch 8.2.3702: first key in dict is seen as curly expression and fails
Bram Moolenaar <Bram@vim.org>
parents: 25806
diff changeset
1912 semsg(_(e_invalid_expression_str), *arg);
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1913 return FAIL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1914 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1915 *arg += len;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1916 if (evaluate)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1917 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1918 rettv->v_type = VAR_NUMBER;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1919 rettv->vval.v_number = n;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1920 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1921 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1922 return OK;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1923 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1924
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1925 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1926 * 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
1927 * Return OK or FAIL.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1928 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1929 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
1930 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
1931 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1932 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
1933 char_u *end;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1934 int extra = 0;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1935 int len;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1936
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1937 // 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
1938 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
1939 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1940 if (*p == '\\' && p[1] != NUL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1941 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1942 ++p;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1943 // 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
1944 // 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
1945 // reserve space for 18 extra.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1946 // 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
1947 if (*p == '<')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1948 extra += 18;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1949 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1950 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1951
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1952 if (*p != '"')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1953 {
26602
fac6673086df patch 8.2.3830: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26585
diff changeset
1954 semsg(_(e_missing_double_quote_str), *arg);
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1955 return FAIL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1956 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1957
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1958 // 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
1959 if (!evaluate)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1960 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1961 *arg = p + 1;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1962 return OK;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1963 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1964
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1965 // 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
1966 // characters.
20925
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
1967 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
1968 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
1969 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
1970 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
1971 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
1972 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
1973
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1974 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
1975 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1976 if (*p == '\\')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1977 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1978 switch (*++p)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1979 {
20925
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
1980 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
1981 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
1982 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
1983 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
1984 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
1985 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
1986
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1987 case 'X': // hex: "\x1", "\x12"
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1988 case 'x':
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1989 case 'u': // Unicode: "\u0023"
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1990 case 'U':
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1991 if (vim_isxdigit(p[1]))
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1992 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1993 int n, nr;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1994 int c = toupper(*p);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1995
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1996 if (c == 'X')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1997 n = 2;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1998 else if (*p == 'u')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1999 n = 4;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2000 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2001 n = 8;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2002 nr = 0;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2003 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
2004 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2005 ++p;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2006 nr = (nr << 4) + hex2nr(*p);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2007 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2008 ++p;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2009 // 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
2010 // 'encoding'.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2011 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
2012 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
2013 else
20925
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
2014 *end++ = nr;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2015 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2016 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2017
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2018 // octal: "\1", "\12", "\123"
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2019 case '0':
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2020 case '1':
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2021 case '2':
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2022 case '3':
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2023 case '4':
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2024 case '5':
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2025 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
2026 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
2027 if (*p >= '0' && *p <= '7')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2028 {
20925
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
2029 *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
2030 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
2031 *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
2032 }
20925
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
2033 ++end;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2034 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2035
20627
8bce783af0cb patch 8.2.0867: using {xxx} for encoding a modifier is not nice
Bram Moolenaar <Bram@vim.org>
parents: 20603
diff changeset
2036 // 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
2037 case '<':
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2038 {
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
2039 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
2040
20627
8bce783af0cb patch 8.2.0867: using {xxx} for encoding a modifier is not nice
Bram Moolenaar <Bram@vim.org>
parents: 20603
diff changeset
2041 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
2042 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
2043 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
2044 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
2045 {
20925
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
2046 end += extra;
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
2047 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
2048 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
2049 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
2050 }
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2051 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2052 // FALLTHROUGH
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2053
20925
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
2054 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
2055 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2056 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2057 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2058 else
20925
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
2059 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
2060 }
20925
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
2061 *end = NUL;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2062 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
2063 ++p;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2064 *arg = p;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2065
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2066 return OK;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2067 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2068
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2069 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2070 * 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
2071 * Return OK or FAIL.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2072 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2073 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
2074 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
2075 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2076 char_u *p;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2077 char_u *str;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2078 int reduce = 0;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2079
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2080 // 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
2081 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
2082 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2083 if (*p == '\'')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2084 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2085 if (p[1] != '\'')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2086 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2087 ++reduce;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2088 ++p;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2089 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2090 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2091
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2092 if (*p != '\'')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2093 {
26602
fac6673086df patch 8.2.3830: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26585
diff changeset
2094 semsg(_(e_missing_single_quote_str), *arg);
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2095 return FAIL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2096 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2097
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2098 // 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
2099 if (!evaluate)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2100 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2101 *arg = p + 1;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2102 return OK;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2103 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2104
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2105 // 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
2106 str = alloc((p - *arg) - reduce);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2107 if (str == NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2108 return FAIL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2109 rettv->v_type = VAR_STRING;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2110 rettv->vval.v_string = str;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2111
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2112 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
2113 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2114 if (*p == '\'')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2115 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2116 if (p[1] != '\'')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2117 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2118 ++p;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2119 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2120 MB_COPY_CHAR(p, str);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2121 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2122 *str = NUL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2123 *arg = p + 1;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2124
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2125 return OK;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2126 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2127
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2128 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2129 * 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
2130 * 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
2131 * "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
2132 * 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
2133 * May return NULL.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2134 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2135 char_u *
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2136 tv2string(
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2137 typval_T *tv,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2138 char_u **tofree,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2139 char_u *numbuf,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2140 int copyID)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2141 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2142 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
2143 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2144
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2145 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2146 * 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
2147 * "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
2148 * 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
2149 * 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
2150 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2151 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
2152 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
2153 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2154 char_u *string = NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2155 int len;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2156 int cc;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2157 char_u *name;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2158 int mustfree = FALSE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2159
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2160 ++*arg;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2161 name = *arg;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2162 len = get_env_len(arg);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2163 if (evaluate)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2164 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2165 if (len == 0)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2166 return FAIL; // invalid empty name
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2167
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2168 cc = name[len];
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2169 name[len] = NUL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2170 // 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
2171 string = vim_getenv(name, &mustfree);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2172 if (string != NULL && *string != NUL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2173 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2174 if (!mustfree)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2175 string = vim_strsave(string);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2176 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2177 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2178 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2179 if (mustfree)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2180 vim_free(string);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2181
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2182 // 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
2183 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
2184 if (string != NULL && *string == '$')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2185 VIM_CLEAR(string);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2186 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2187 name[len] = cc;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2188
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2189 rettv->v_type = VAR_STRING;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2190 rettv->vval.v_string = string;
25585
10edc624b171 patch 8.2.3329: v_lock not set when getting value of environment variable
Bram Moolenaar <Bram@vim.org>
parents: 25563
diff changeset
2191 rettv->v_lock = 0;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2192 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2193
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2194 return OK;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2195 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2196
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2197 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2198 * 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
2199 * 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
2200 * Returns -1 on error.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2201 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2202 linenr_T
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2203 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
2204 {
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
2205 linenr_T lnum = -1;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2206
21831
d8422de73113 patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21425
diff changeset
2207 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
2208 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
2209 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
2210 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2211 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
2212 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
2213
24260
ad065f64eb20 patch 8.2.2671: error for line number in legacy script
Bram Moolenaar <Bram@vim.org>
parents: 24258
diff changeset
2214 // 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
2215 if (fp != NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2216 lnum = fp->lnum;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2217 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2218 return lnum;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2219 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2220
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2221 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2222 * 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
2223 * 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
2224 * Returns 0 on error.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2225 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2226 linenr_T
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2227 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
2228 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2229 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
2230 && 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
2231 && 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
2232 && buf != NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2233 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
2234 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
2235 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2236
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2237 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2238 * 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
2239 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2240 buf_T *
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2241 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
2242 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2243 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
2244 buf_T *buf;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2245
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2246 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
2247 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
2248 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
2249 return NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2250 if (name == NULL || *name == NUL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2251 return curbuf;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2252 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
2253 return lastbuf;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2254
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2255 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
2256
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2257 // 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
2258 if (buf == NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2259 buf = find_buffer(tv);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2260
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2261 return buf;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2262 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2263
22025
71f886a48ef5 patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
2264 /*
71f886a48ef5 patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
2265 * 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
2266 */
71f886a48ef5 patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
2267 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
2268 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
2269 {
71f886a48ef5 patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
2270 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
2271
71f886a48ef5 patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
2272 ++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
2273 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
2274 --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
2275 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
2276 && 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
2277 && 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
2278 // 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
2279 (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
2280 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
2281 }
71f886a48ef5 patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
2282
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2283 #endif // FEAT_EVAL