annotate src/typval.c @ 29247:5f314b2ed494 v8.2.5142

patch 8.2.5142: startup test fails if there is a status bar Commit: https://github.com/vim/vim/commit/fa04eae5a5b9394079bde2d37ce6f9f8a5567d48 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Jun 21 14:38:40 2022 +0100 patch 8.2.5142: startup test fails if there is a status bar Problem: Startup test fails if there is a status bar at the top of the screen. (Ernie Rael) Solution: Use a larger vertical offset in the test.
author Bram Moolenaar <Bram@vim.org>
date Tue, 21 Jun 2022 18:45:07 +0200
parents 006d525419fa
children 5063dfe96a59
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
26962
85866e069c24 patch 8.2.4010: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26958
diff changeset
194 emsg(_(e_using_float_as_number));
20587
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:
26952
b34ddbca305c patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26948
diff changeset
199 emsg(_(e_using_funcref_as_number));
20587
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:
26958
d92e0d85923f patch 8.2.4008: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26952
diff changeset
212 emsg(_(e_using_list_as_number));
20587
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:
26952
b34ddbca305c patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26948
diff changeset
215 emsg(_(e_using_dictionary_as_number));
20587
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
26948
51ddf6740ac6 patch 8.2.4003: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26913
diff changeset
224 emsg(_(e_using_special_as_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
26966
ac75c145f0a9 patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26962
diff changeset
230 emsg(_(e_using_job_as_number));
20587
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
26966
ac75c145f0a9 patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26962
diff changeset
235 emsg(_(e_using_channel_as_number));
20587
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:
26966
ac75c145f0a9 patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26962
diff changeset
239 emsg(_(e_using_blob_as_number));
20587
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)
26696
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
300 static float_T
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
301 tv_get_float_chk(typval_T *varp, int *error)
20587
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:
26966
ac75c145f0a9 patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26962
diff changeset
311 emsg(_(e_using_funcref_as_float));
20587
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:
26966
ac75c145f0a9 patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26962
diff changeset
314 emsg(_(e_using_string_as_float));
20587
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:
26966
ac75c145f0a9 patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26962
diff changeset
317 emsg(_(e_using_list_as_float));
20587
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:
26966
ac75c145f0a9 patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26962
diff changeset
320 emsg(_(e_using_dictionary_as_float));
20587
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:
27034
b31cc7630773 patch 8.2.4046: some error messages not in the right place
Bram Moolenaar <Bram@vim.org>
parents: 27018
diff changeset
323 emsg(_(e_using_boolean_value_as_float));
20587
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:
26966
ac75c145f0a9 patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26962
diff changeset
326 emsg(_(e_using_special_value_as_float));
20587
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
26966
ac75c145f0a9 patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26962
diff changeset
330 emsg(_(e_using_job_as_float));
20587
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
26966
ac75c145f0a9 patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26962
diff changeset
335 emsg(_(e_using_channel_as_float));
20587
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:
26966
ac75c145f0a9 patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26962
diff changeset
339 emsg(_(e_using_blob_as_float));
20587
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 }
26696
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
350 if (error != NULL)
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
351 *error = TRUE;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
352 return 0;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
353 }
26696
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
354
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
355 float_T
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
356 tv_get_float(typval_T *varp)
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
357 {
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
358 return tv_get_float_chk(varp, NULL);
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
359 }
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
360 #endif
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
361
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
362 /*
28674
38f7a132bba3 patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents: 28668
diff changeset
363 * Give an error and return FAIL unless "args[idx]" is unknown
38f7a132bba3 patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents: 28668
diff changeset
364 */
38f7a132bba3 patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents: 28668
diff changeset
365 int
38f7a132bba3 patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents: 28668
diff changeset
366 check_for_unknown_arg(typval_T *args, int idx)
38f7a132bba3 patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents: 28668
diff changeset
367 {
38f7a132bba3 patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents: 28668
diff changeset
368 if (args[idx].v_type != VAR_UNKNOWN)
38f7a132bba3 patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents: 28668
diff changeset
369 {
38f7a132bba3 patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents: 28668
diff changeset
370 semsg(_(e_too_many_arguments), idx + 1);
38f7a132bba3 patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents: 28668
diff changeset
371 return FAIL;
38f7a132bba3 patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents: 28668
diff changeset
372 }
38f7a132bba3 patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents: 28668
diff changeset
373 return OK;
38f7a132bba3 patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents: 28668
diff changeset
374 }
38f7a132bba3 patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents: 28668
diff changeset
375
38f7a132bba3 patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents: 28668
diff changeset
376 /*
25272
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
377 * 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
378 */
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 22930
diff changeset
379 int
24246
35603c7991d7 patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24210
diff changeset
380 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
381 {
24246
35603c7991d7 patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24210
diff changeset
382 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
383 {
26622
a28f91b893b2 patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
384 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
385 return FAIL;
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 22930
diff changeset
386 }
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 22930
diff changeset
387 return OK;
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 22930
diff changeset
388 }
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 22930
diff changeset
389
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 22930
diff changeset
390 /*
24246
35603c7991d7 patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24210
diff changeset
391 * 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
392 */
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
393 int
24246
35603c7991d7 patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24210
diff changeset
394 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
395 {
24246
35603c7991d7 patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24210
diff changeset
396 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
397 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
398 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
399 {
24424
ddcda424f882 patch 8.2.2752
Bram Moolenaar <Bram@vim.org>
parents: 24260
diff changeset
400 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
401 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
402 }
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
403 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
404 }
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
405
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
406 /*
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
407 * 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
408 */
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
409 int
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
410 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
411 {
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
412 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
413 || 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
414 }
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
415
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
416 /*
25272
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
417 * 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
418 */
acda780ffc3e patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25198
diff changeset
419 int
acda780ffc3e patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25198
diff changeset
420 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
421 {
acda780ffc3e patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25198
diff changeset
422 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
423 {
26622
a28f91b893b2 patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
424 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
425 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
426 }
acda780ffc3e patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25198
diff changeset
427 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
428 }
acda780ffc3e patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25198
diff changeset
429
acda780ffc3e patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25198
diff changeset
430 /*
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
431 * 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
432 */
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
433 int
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
434 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
435 {
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
436 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
437 || 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
438 }
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
439
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
440 /*
25368
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
441 * 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
442 */
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
443 int
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
444 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
445 {
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
446 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
447 {
26622
a28f91b893b2 patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
448 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
449 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
450 }
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
451 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
452 }
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
453
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
454 /*
25272
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
455 * 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
456 */
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
457 int
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
458 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
459 {
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
460 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
461 && !(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
462 && (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
463 || 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
464 {
26622
a28f91b893b2 patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
465 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
466 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
467 }
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
468 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
469 }
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
470
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
471 /*
25802
5ef704de7709 patch 8.2.3436: check for optional bool type has confusing return type
Bram Moolenaar <Bram@vim.org>
parents: 25622
diff changeset
472 * 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
473 * 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
474 */
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
475 int
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
476 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
477 {
25802
5ef704de7709 patch 8.2.3436: check for optional bool type has confusing return type
Bram Moolenaar <Bram@vim.org>
parents: 25622
diff changeset
478 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
479 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
480 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
481 }
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
482
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
483 /*
25806
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25802
diff changeset
484 * 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
485 */
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25802
diff changeset
486 int
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25802
diff changeset
487 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
488 {
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25802
diff changeset
489 if (args[idx].v_type != VAR_BLOB)
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25802
diff changeset
490 {
26622
a28f91b893b2 patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
491 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
492 return FAIL;
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25802
diff changeset
493 }
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25802
diff changeset
494 return OK;
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25802
diff changeset
495 }
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25802
diff changeset
496
8d55e978f95b patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents: 25802
diff changeset
497 /*
25272
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
498 * 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
499 */
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
500 int
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
501 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
502 {
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
503 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
504 {
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
505 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
506 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
507 }
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
508 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
509 }
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
510
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
511 /*
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
512 * 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
513 */
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
514 int
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
515 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
516 {
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
517 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
518 || 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
519 }
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
520
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
521 /*
25272
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
522 * 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
523 */
eafc0e07b188 patch 8.2.3135: Vim9: builtin function arguments not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
524 int
eafc0e07b188 patch 8.2.3135: Vim9: builtin function arguments not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
525 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
526 {
eafc0e07b188 patch 8.2.3135: Vim9: builtin function arguments not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
527 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
528 {
26622
a28f91b893b2 patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
529 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
530 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
531 }
eafc0e07b188 patch 8.2.3135: Vim9: builtin function arguments not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
532 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
533 }
eafc0e07b188 patch 8.2.3135: Vim9: builtin function arguments not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
534
eafc0e07b188 patch 8.2.3135: Vim9: builtin function arguments not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
535 /*
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
536 * 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
537 */
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
538 int
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
539 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
540 {
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
541 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
542 || 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
543 }
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
544
27018
268f6a3511df patch 8.2.4038: various code not used when features are disabled
Bram Moolenaar <Bram@vim.org>
parents: 26966
diff changeset
545 #if defined(FEAT_JOB_CHANNEL) || defined(PROTO)
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
546 /*
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
547 * 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
548 */
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
549 int
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
550 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
551 {
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
552 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
553 {
26622
a28f91b893b2 patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
554 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
555 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
556 }
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 OK;
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
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
560 /*
25348
75031a22be39 patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
561 * 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
562 * job.
75031a22be39 patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
563 */
75031a22be39 patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
564 int
75031a22be39 patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
565 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
566 {
75031a22be39 patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
567 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
568 || 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
569 }
75031a22be39 patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
570
75031a22be39 patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
571 /*
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
572 * 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
573 */
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
574 int
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
575 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
576 {
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
577 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
578 {
26622
a28f91b893b2 patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
579 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
580 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
581 }
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 OK;
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
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
585 /*
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
586 * 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
587 */
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
588 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
589 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
590 {
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
591 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
592 || 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
593 }
27018
268f6a3511df patch 8.2.4038: various code not used when features are disabled
Bram Moolenaar <Bram@vim.org>
parents: 26966
diff changeset
594 #endif
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
595
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
596 /*
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
597 * 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
598 * 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
599 */
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
600 int
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
601 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
602 {
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
603 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
604 {
26622
a28f91b893b2 patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
605 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
606 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
607 }
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
608 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
609 }
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
610
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
611 /*
25314
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
612 * 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
613 */
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
614 int
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
615 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
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 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
618 || 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
619 }
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 /*
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
622 * 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
623 * 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
624 */
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
625 int
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
626 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
627 {
25314
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
628 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
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
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
631 /*
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
632 * 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
633 */
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
634 int
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
635 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
636 {
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
637 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
638 || 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
639 }
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
640
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
641 /*
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
642 * 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
643 * 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
644 */
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
645 int
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
646 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
647 {
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
648 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
649 }
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
650
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
651 /*
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
652 * 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
653 */
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
654 int
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_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
656 {
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
657 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
658 || 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
659 }
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
660
27018
268f6a3511df patch 8.2.4038: various code not used when features are disabled
Bram Moolenaar <Bram@vim.org>
parents: 26966
diff changeset
661 #if defined(FEAT_JOB_CHANNEL) || defined(PROTO)
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
662 /*
25338
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
663 * 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
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 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
666 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
667 {
25314
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
668 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
669 {
26622
a28f91b893b2 patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
670 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
671 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
672 }
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
673 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
674 }
27018
268f6a3511df patch 8.2.4038: various code not used when features are disabled
Bram Moolenaar <Bram@vim.org>
parents: 26966
diff changeset
675 #endif
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
676
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
677 /*
25338
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
678 * 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
679 */
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
680 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
681 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
682 {
25314
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
683 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
684 {
26622
a28f91b893b2 patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
685 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
686 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
687 }
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
688 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
689 }
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
690
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
691 /*
26638
6fd15d82e898 patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents: 26622
diff changeset
692 * 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
693 * blob.
6fd15d82e898 patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents: 26622
diff changeset
694 */
6fd15d82e898 patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents: 26622
diff changeset
695 int
6fd15d82e898 patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents: 26622
diff changeset
696 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
697 {
6fd15d82e898 patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents: 26622
diff changeset
698 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
699 && 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
700 && 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
701 {
6fd15d82e898 patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents: 26622
diff changeset
702 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
703 return FAIL;
6fd15d82e898 patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents: 26622
diff changeset
704 }
6fd15d82e898 patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents: 26622
diff changeset
705 return OK;
6fd15d82e898 patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents: 26622
diff changeset
706 }
6fd15d82e898 patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents: 26622
diff changeset
707
6fd15d82e898 patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents: 26622
diff changeset
708 /*
25368
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
709 * 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
710 */
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
711 int
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
712 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
713 {
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
714 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
715 || 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
716 }
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
717
1ffa8eb30353 patch 8.2.3221: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
718 /*
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
719 * 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
720 */
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 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
722 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
723 {
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
724 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
725 {
26622
a28f91b893b2 patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
726 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
727 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
728 }
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
729 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
730 }
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
731
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
732 /*
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
733 * 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
734 * 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
735 */
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 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
737 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
738 {
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 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
740 && 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
741 && 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
742 {
26638
6fd15d82e898 patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents: 26622
diff changeset
743 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
744 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
745 }
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 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
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
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 /*
25390
a6c347a0c6e3 patch 8.2.3232: system() does not work without a second argument
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
750 * 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
751 * 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
752 */
a6c347a0c6e3 patch 8.2.3232: system() does not work without a second argument
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
753 int
a6c347a0c6e3 patch 8.2.3232: system() does not work without a second argument
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
754 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
755 {
a6c347a0c6e3 patch 8.2.3232: system() does not work without a second argument
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
756 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
757 || 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
758 }
a6c347a0c6e3 patch 8.2.3232: system() does not work without a second argument
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
759
a6c347a0c6e3 patch 8.2.3232: system() does not work without a second argument
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
760 /*
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
761 * 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
762 * 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
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 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
765 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
766 {
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 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
768 && 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
769 && 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
770 {
26622
a28f91b893b2 patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
771 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
772 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
773 }
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
774 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
775 }
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
776
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
777 /*
26731
7f4cc4e58f75 patch 8.2.3894: Vim9: no proper type check for first argument of call()
Bram Moolenaar <Bram@vim.org>
parents: 26696
diff changeset
778 * Give an error and return FAIL unless "args[idx]" is a string
7f4cc4e58f75 patch 8.2.3894: Vim9: no proper type check for first argument of call()
Bram Moolenaar <Bram@vim.org>
parents: 26696
diff changeset
779 * or a function reference.
7f4cc4e58f75 patch 8.2.3894: Vim9: no proper type check for first argument of call()
Bram Moolenaar <Bram@vim.org>
parents: 26696
diff changeset
780 */
7f4cc4e58f75 patch 8.2.3894: Vim9: no proper type check for first argument of call()
Bram Moolenaar <Bram@vim.org>
parents: 26696
diff changeset
781 int
7f4cc4e58f75 patch 8.2.3894: Vim9: no proper type check for first argument of call()
Bram Moolenaar <Bram@vim.org>
parents: 26696
diff changeset
782 check_for_string_or_func_arg(typval_T *args, int idx)
7f4cc4e58f75 patch 8.2.3894: Vim9: no proper type check for first argument of call()
Bram Moolenaar <Bram@vim.org>
parents: 26696
diff changeset
783 {
7f4cc4e58f75 patch 8.2.3894: Vim9: no proper type check for first argument of call()
Bram Moolenaar <Bram@vim.org>
parents: 26696
diff changeset
784 if (args[idx].v_type != VAR_PARTIAL
7f4cc4e58f75 patch 8.2.3894: Vim9: no proper type check for first argument of call()
Bram Moolenaar <Bram@vim.org>
parents: 26696
diff changeset
785 && args[idx].v_type != VAR_FUNC
7f4cc4e58f75 patch 8.2.3894: Vim9: no proper type check for first argument of call()
Bram Moolenaar <Bram@vim.org>
parents: 26696
diff changeset
786 && args[idx].v_type != VAR_STRING)
7f4cc4e58f75 patch 8.2.3894: Vim9: no proper type check for first argument of call()
Bram Moolenaar <Bram@vim.org>
parents: 26696
diff changeset
787 {
7f4cc4e58f75 patch 8.2.3894: Vim9: no proper type check for first argument of call()
Bram Moolenaar <Bram@vim.org>
parents: 26696
diff changeset
788 semsg(_(e_string_or_function_required_for_argument_nr), idx + 1);
7f4cc4e58f75 patch 8.2.3894: Vim9: no proper type check for first argument of call()
Bram Moolenaar <Bram@vim.org>
parents: 26696
diff changeset
789 return FAIL;
7f4cc4e58f75 patch 8.2.3894: Vim9: no proper type check for first argument of call()
Bram Moolenaar <Bram@vim.org>
parents: 26696
diff changeset
790 }
7f4cc4e58f75 patch 8.2.3894: Vim9: no proper type check for first argument of call()
Bram Moolenaar <Bram@vim.org>
parents: 26696
diff changeset
791 return OK;
7f4cc4e58f75 patch 8.2.3894: Vim9: no proper type check for first argument of call()
Bram Moolenaar <Bram@vim.org>
parents: 26696
diff changeset
792 }
7f4cc4e58f75 patch 8.2.3894: Vim9: no proper type check for first argument of call()
Bram Moolenaar <Bram@vim.org>
parents: 26696
diff changeset
793
7f4cc4e58f75 patch 8.2.3894: Vim9: no proper type check for first argument of call()
Bram Moolenaar <Bram@vim.org>
parents: 26696
diff changeset
794 /*
25338
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
795 * 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
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 int
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
798 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
799 {
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
800 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
801 {
26638
6fd15d82e898 patch 8.2.3848: cannot use reduce() for a string
Bram Moolenaar <Bram@vim.org>
parents: 26622
diff changeset
802 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
803 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
804 }
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
805 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
806 }
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
807
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
808 /*
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
809 * 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
810 */
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
811 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
812 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
813 {
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
814 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
815 && 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
816 {
26622
a28f91b893b2 patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
817 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
818 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
819 }
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
820 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
821 }
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
822
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
823 /*
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
824 * 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
825 * blob.
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
826 */
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
827 int
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
828 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
829 {
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
830 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
831 && 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
832 && 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
833 {
26622
a28f91b893b2 patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
834 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
835 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
836 }
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
837 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
838 }
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
839
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
840 /*
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
841 * 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
842 * 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
843 */
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
844 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
845 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
846 {
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
847 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
848 && 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
849 && 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
850 && 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
851 {
26622
a28f91b893b2 patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
852 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
853 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
854 }
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
855 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
856 }
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
857
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
858 /*
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
859 * 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
860 * 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
861 */
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
862 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
863 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
864 {
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
865 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
866 && 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
867 && 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
868 && 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
869 {
26622
a28f91b893b2 patch 8.2.3840: useless test for negative index in check functions
Bram Moolenaar <Bram@vim.org>
parents: 26602
diff changeset
870 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
871 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
872 }
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
873 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
874 }
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
875
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25278
diff changeset
876 /*
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
877 * 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
878 * 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
879 * 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
880 * 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
881 * 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
882 * Never returns NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
883 * 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
884 * NULL on error.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
885 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
886 char_u *
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
887 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
888 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
889 static char_u mybuf[NUMBUFLEN];
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
890
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
891 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
892 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
893
23786
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
894 /*
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
895 * 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
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 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
898 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
899 {
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
900 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
901 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
902 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
903
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
904 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
905 }
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
906
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
907 char_u *
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
908 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
909 {
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
910 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
911
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
912 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
913 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
914
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
915 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
916 * 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
917 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
918 char_u *
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
919 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
920 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
921 static char_u mybuf[NUMBUFLEN];
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
922
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
923 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
924 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
925
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
926 char_u *
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
927 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
928 {
23786
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
929 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
930 }
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
931
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
932 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
933 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
934 {
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
935 switch (varp->v_type)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
936 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
937 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
938 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
939 {
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
940 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
941 break;
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23563
diff changeset
942 }
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
943 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
944 (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
945 return buf;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
946 case VAR_FUNC:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
947 case VAR_PARTIAL:
26952
b34ddbca305c patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26948
diff changeset
948 emsg(_(e_using_funcref_as_string));
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
949 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
950 case VAR_LIST:
26952
b34ddbca305c patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26948
diff changeset
951 emsg(_(e_using_list_as_string));
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
952 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
953 case VAR_DICT:
26952
b34ddbca305c patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26948
diff changeset
954 emsg(_(e_using_dictionary_as_string));
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
955 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
956 case VAR_FLOAT:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
957 #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
958 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
959 {
26885
ed39730119bd patch 8.2.3971: build fails
Bram Moolenaar <Bram@vim.org>
parents: 26877
diff changeset
960 emsg(_(e_using_float_as_string));
24820
b1093c1ac109 patch 8.2.2948: substitute() accepts a number but not a float expression
Bram Moolenaar <Bram@vim.org>
parents: 24812
diff changeset
961 break;
b1093c1ac109 patch 8.2.2948: substitute() accepts a number but not a float expression
Bram Moolenaar <Bram@vim.org>
parents: 24812
diff changeset
962 }
b1093c1ac109 patch 8.2.2948: substitute() accepts a number but not a float expression
Bram Moolenaar <Bram@vim.org>
parents: 24812
diff changeset
963 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
964 return buf;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
965 #endif
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
966 case VAR_STRING:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
967 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
968 return varp->vval.v_string;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
969 return (char_u *)"";
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
970 case VAR_BOOL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
971 case VAR_SPECIAL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
972 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
973 return buf;
28809
d0241e74bfdb patch 8.2.4928: various white space and cosmetic mistakes
Bram Moolenaar <Bram@vim.org>
parents: 28718
diff changeset
974 case VAR_BLOB:
26966
ac75c145f0a9 patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26962
diff changeset
975 emsg(_(e_using_blob_as_string));
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
976 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
977 case VAR_JOB:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
978 #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
979 if (in_vim9script())
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
980 {
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
981 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
982 break;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
983 }
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
984 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
985 #endif
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
986 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
987 case VAR_CHANNEL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
988 #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
989 if (in_vim9script())
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
990 {
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
991 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
992 break;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
993 }
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
994 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
995 #endif
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
996 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
997 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
998 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
999 break;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1000 case VAR_UNKNOWN:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1001 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
1002 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
1003 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
1004 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
1005 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1006 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1007 return NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1008 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1009
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1010 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1011 * 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
1012 * string() on Dict, List, etc.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1013 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1014 char_u *
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1015 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
1016 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1017 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
1018 || varp->v_type == VAR_DICT
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1019 || varp->v_type == VAR_BLOB
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1020 || varp->v_type == VAR_FUNC
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1021 || varp->v_type == VAR_PARTIAL
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1022 || varp->v_type == VAR_FLOAT)
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 typval_T tmp;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1025
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1026 f_string(varp, &tmp);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1027 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
1028 clear_tv(varp);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1029 *varp = tmp;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1030 return tmp.vval.v_string;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1031 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1032 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
1033 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1034
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1035 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1036 * 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
1037 * 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
1038 * TRUE.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1039 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1040 int
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1041 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
1042 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1043 int lock = 0;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1044
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1045 switch (tv->v_type)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1046 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1047 case VAR_BLOB:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1048 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
1049 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
1050 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1051 case VAR_LIST:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1052 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
1053 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
1054 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1055 case VAR_DICT:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1056 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
1057 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
1058 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1059 default:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1060 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1061 }
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
1062 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
1063 || (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
1064 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1065
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1066 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1067 * 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
1068 * 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
1069 * 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
1070 * 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
1071 * make a copy later.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1072 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1073 void
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1074 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
1075 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1076 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
1077 to->v_lock = 0;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1078 switch (from->v_type)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1079 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1080 case VAR_NUMBER:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1081 case VAR_BOOL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1082 case VAR_SPECIAL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1083 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
1084 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1085 case VAR_FLOAT:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1086 #ifdef FEAT_FLOAT
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1087 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
1088 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1089 #endif
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1090 case VAR_JOB:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1091 #ifdef FEAT_JOB_CHANNEL
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1092 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
1093 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
1094 ++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
1095 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1096 #endif
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1097 case VAR_CHANNEL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1098 #ifdef FEAT_JOB_CHANNEL
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1099 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
1100 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
1101 ++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
1102 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1103 #endif
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24424
diff changeset
1104 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
1105 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
1106 break;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24424
diff changeset
1107
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1108 case VAR_STRING:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1109 case VAR_FUNC:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1110 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
1111 to->vval.v_string = NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1112 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1113 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1114 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
1115 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
1116 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
1117 }
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 case VAR_PARTIAL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1120 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
1121 to->vval.v_partial = NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1122 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1123 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1124 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
1125 ++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
1126 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1127 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1128 case VAR_BLOB:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1129 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
1130 to->vval.v_blob = NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1131 else
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 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
1134 ++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
1135 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1136 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1137 case VAR_LIST:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1138 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
1139 to->vval.v_list = NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1140 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1141 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1142 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
1143 ++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
1144 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1145 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1146 case VAR_DICT:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1147 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
1148 to->vval.v_dict = NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1149 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1150 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1151 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
1152 ++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
1153 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1154 break;
24940
0c415a0f54f9 patch 8.2.3007: Vim9: test for void value fails
Bram Moolenaar <Bram@vim.org>
parents: 24936
diff changeset
1155 case VAR_VOID:
0c415a0f54f9 patch 8.2.3007: Vim9: test for void value fails
Bram Moolenaar <Bram@vim.org>
parents: 24936
diff changeset
1156 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
1157 break;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1158 case VAR_UNKNOWN:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1159 case VAR_ANY:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1160 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
1161 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1162 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1163 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1164
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1165 /*
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1166 * 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
1167 * 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
1168 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1169 int
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1170 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
1171 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
1172 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
1173 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
1174 int ic) // ignore case
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1175 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1176 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
1177 int res = 0;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1178 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
1179
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1180 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
1181 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1182 // 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
1183 // it means TRUE.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1184 n1 = (type == EXPR_ISNOT);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1185 }
27924
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1186 else if (((tv1->v_type == VAR_SPECIAL && tv1->vval.v_number == VVAL_NULL)
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1187 || (tv2->v_type == VAR_SPECIAL
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1188 && tv2->vval.v_number == VVAL_NULL))
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1189 && tv1->v_type != tv2->v_type
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1190 && (type == EXPR_EQUAL || type == EXPR_NEQUAL))
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1191 {
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1192 n1 = typval_compare_null(tv1, tv2);
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1193 if (n1 == MAYBE)
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1194 {
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1195 clear_tv(tv1);
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1196 return FAIL;
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1197 }
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1198 if (type == EXPR_NEQUAL)
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1199 n1 = !n1;
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1200 }
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1201 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
1202 {
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1203 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
1204 {
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1205 clear_tv(tv1);
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1206 return FAIL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1207 }
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1208 n1 = res;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1209 }
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1210 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
1211 {
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1212 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
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 clear_tv(tv1);
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1215 return FAIL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1216 }
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1217 n1 = res;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1218 }
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1219 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
1220 {
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1221 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
1222 {
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1223 clear_tv(tv1);
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1224 return FAIL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1225 }
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1226 n1 = res;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1227 }
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1228 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
1229 || 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
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 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
1232 {
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1233 clear_tv(tv1);
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1234 return FAIL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
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 n1 = res;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1237 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1238
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1239 #ifdef FEAT_FLOAT
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1240 // 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
1241 // 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
1242 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
1243 && 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
1244 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1245 float_T f1, f2;
26696
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
1246 int error = FALSE;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1247
26696
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
1248 f1 = tv_get_float_chk(tv1, &error);
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
1249 if (!error)
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
1250 f2 = tv_get_float_chk(tv2, &error);
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
1251 if (error)
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
1252 {
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
1253 clear_tv(tv1);
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
1254 return FAIL;
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
1255 }
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1256 n1 = FALSE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1257 switch (type)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1258 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1259 case EXPR_IS:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1260 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
1261 case EXPR_ISNOT:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1262 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
1263 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
1264 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
1265 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
1266 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
1267 case EXPR_UNKNOWN:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1268 case EXPR_MATCH:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1269 default: break; // avoid gcc warning
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1270 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1271 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1272 #endif
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1273
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1274 // 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
1275 // 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
1276 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
1277 && 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
1278 {
26696
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
1279 int error = FALSE;
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
1280
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
1281 n1 = tv_get_number_chk(tv1, &error);
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
1282 if (!error)
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
1283 n2 = tv_get_number_chk(tv2, &error);
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
1284 if (error)
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
1285 {
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
1286 clear_tv(tv1);
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
1287 return FAIL;
1cee572f2fd7 patch 8.2.3877: function does not abort after a type error in compare
Bram Moolenaar <Bram@vim.org>
parents: 26644
diff changeset
1288 }
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1289 switch (type)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1290 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1291 case EXPR_IS:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1292 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
1293 case EXPR_ISNOT:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1294 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
1295 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
1296 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
1297 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
1298 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
1299 case EXPR_UNKNOWN:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1300 case EXPR_MATCH:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1301 default: break; // avoid gcc warning
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1302 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1303 }
26644
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 (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
1305 || 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
1306 || (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
1307 && 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
1308 {
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1309 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
1310 {
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1311 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
1312 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
1313 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
1314 return FAIL;
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1315 }
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1316 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
1317 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
1318 switch (type)
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1319 {
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1320 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
1321 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
1322 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
1323 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
1324 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
1325 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
1326 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
1327 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
1328 return FAIL;
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1329 }
0f7bb6f706f0 patch 8.2.2320: Vim9: no error for comparing bool with string
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1330 }
28217
662d2d5db9a6 patch 8.2.4634: Vim9: cannot initialize a variable to null_list
Bram Moolenaar <Bram@vim.org>
parents: 28103
diff changeset
1331 #ifdef FEAT_JOB_CHANNEL
662d2d5db9a6 patch 8.2.4634: Vim9: cannot initialize a variable to null_list
Bram Moolenaar <Bram@vim.org>
parents: 28103
diff changeset
1332 else if (tv1->v_type == tv2->v_type
662d2d5db9a6 patch 8.2.4634: Vim9: cannot initialize a variable to null_list
Bram Moolenaar <Bram@vim.org>
parents: 28103
diff changeset
1333 && (tv1->v_type == VAR_CHANNEL || tv1->v_type == VAR_JOB)
662d2d5db9a6 patch 8.2.4634: Vim9: cannot initialize a variable to null_list
Bram Moolenaar <Bram@vim.org>
parents: 28103
diff changeset
1334 && (type == EXPR_NEQUAL || type == EXPR_EQUAL))
662d2d5db9a6 patch 8.2.4634: Vim9: cannot initialize a variable to null_list
Bram Moolenaar <Bram@vim.org>
parents: 28103
diff changeset
1335 {
662d2d5db9a6 patch 8.2.4634: Vim9: cannot initialize a variable to null_list
Bram Moolenaar <Bram@vim.org>
parents: 28103
diff changeset
1336 if (tv1->v_type == VAR_CHANNEL)
662d2d5db9a6 patch 8.2.4634: Vim9: cannot initialize a variable to null_list
Bram Moolenaar <Bram@vim.org>
parents: 28103
diff changeset
1337 n1 = tv1->vval.v_channel == tv2->vval.v_channel;
662d2d5db9a6 patch 8.2.4634: Vim9: cannot initialize a variable to null_list
Bram Moolenaar <Bram@vim.org>
parents: 28103
diff changeset
1338 else
662d2d5db9a6 patch 8.2.4634: Vim9: cannot initialize a variable to null_list
Bram Moolenaar <Bram@vim.org>
parents: 28103
diff changeset
1339 n1 = tv1->vval.v_job == tv2->vval.v_job;
662d2d5db9a6 patch 8.2.4634: Vim9: cannot initialize a variable to null_list
Bram Moolenaar <Bram@vim.org>
parents: 28103
diff changeset
1340 if (type == EXPR_NEQUAL)
662d2d5db9a6 patch 8.2.4634: Vim9: cannot initialize a variable to null_list
Bram Moolenaar <Bram@vim.org>
parents: 28103
diff changeset
1341 n1 = !n1;
662d2d5db9a6 patch 8.2.4634: Vim9: cannot initialize a variable to null_list
Bram Moolenaar <Bram@vim.org>
parents: 28103
diff changeset
1342 }
662d2d5db9a6 patch 8.2.4634: Vim9: cannot initialize a variable to null_list
Bram Moolenaar <Bram@vim.org>
parents: 28103
diff changeset
1343 #endif
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1344 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1345 {
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1346 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
1347 {
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1348 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
1349 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
1350 }
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1351 n1 = res;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1352 }
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1353 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
1354 if (in_vim9script())
a6c316ef161a patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
1355 {
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1356 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
1357 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
1358 }
a6c316ef161a patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
1359 else
a6c316ef161a patch 8.2.1263: Vim9: comperators use 'ignorecase' in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
1360 {
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1361 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
1362 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
1363 }
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1364
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1365 return OK;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1366 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1367
23788
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
1368 /*
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1369 * 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
1370 * 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
1371 * 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
1372 */
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1373 int
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1374 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
1375 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
1376 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
1377 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
1378 int ic,
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1379 int *res)
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 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
1382
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_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
1384 {
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1385 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
1386 && 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
1387 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
1388 val = !val;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1389 }
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1390 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
1391 || (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
1392 {
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1393 if (tv1->v_type != tv2->v_type)
26952
b34ddbca305c patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26948
diff changeset
1394 emsg(_(e_can_only_compare_list_with_list));
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1395 else
26952
b34ddbca305c patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26948
diff changeset
1396 emsg(_(e_invalid_operation_for_list));
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1397 return FAIL;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1398 }
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1399 else
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 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
1402 ic, FALSE);
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1403 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
1404 val = !val;
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 *res = val;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1407 return OK;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1408 }
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 /*
28011
d10d5cc8e657 patch 8.2.4530: making comparison with null work changes legacy behavior
Bram Moolenaar <Bram@vim.org>
parents: 27928
diff changeset
1411 * Compare v:null with another type. Return TRUE if the value is NULL.
27924
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1412 */
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1413 int
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1414 typval_compare_null(typval_T *tv1, typval_T *tv2)
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1415 {
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1416 if ((tv1->v_type == VAR_SPECIAL && tv1->vval.v_number == VVAL_NULL)
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1417 || (tv2->v_type == VAR_SPECIAL && tv2->vval.v_number == VVAL_NULL))
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1418 {
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1419 typval_T *tv = tv1->v_type == VAR_SPECIAL ? tv2 : tv1;
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1420
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1421 switch (tv->v_type)
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1422 {
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1423 case VAR_BLOB: return tv->vval.v_blob == NULL;
27926
46c06f741d12 patch 8.2.4488: build error with +eval but without +channel or +job
Bram Moolenaar <Bram@vim.org>
parents: 27924
diff changeset
1424 #ifdef FEAT_JOB_CHANNEL
27924
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1425 case VAR_CHANNEL: return tv->vval.v_channel == NULL;
27926
46c06f741d12 patch 8.2.4488: build error with +eval but without +channel or +job
Bram Moolenaar <Bram@vim.org>
parents: 27924
diff changeset
1426 #endif
27924
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1427 case VAR_DICT: return tv->vval.v_dict == NULL;
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1428 case VAR_FUNC: return tv->vval.v_string == NULL;
27926
46c06f741d12 patch 8.2.4488: build error with +eval but without +channel or +job
Bram Moolenaar <Bram@vim.org>
parents: 27924
diff changeset
1429 #ifdef FEAT_JOB_CHANNEL
27924
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1430 case VAR_JOB: return tv->vval.v_job == NULL;
27926
46c06f741d12 patch 8.2.4488: build error with +eval but without +channel or +job
Bram Moolenaar <Bram@vim.org>
parents: 27924
diff changeset
1431 #endif
27924
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1432 case VAR_LIST: return tv->vval.v_list == NULL;
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1433 case VAR_PARTIAL: return tv->vval.v_partial == NULL;
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1434 case VAR_STRING: return tv->vval.v_string == NULL;
27928
ca7a207d83cd patch 8.2.4489: failing test for comparing v:null with number
Bram Moolenaar <Bram@vim.org>
parents: 27926
diff changeset
1435
ca7a207d83cd patch 8.2.4489: failing test for comparing v:null with number
Bram Moolenaar <Bram@vim.org>
parents: 27926
diff changeset
1436 case VAR_NUMBER: if (!in_vim9script())
ca7a207d83cd patch 8.2.4489: failing test for comparing v:null with number
Bram Moolenaar <Bram@vim.org>
parents: 27926
diff changeset
1437 return tv->vval.v_number == 0;
ca7a207d83cd patch 8.2.4489: failing test for comparing v:null with number
Bram Moolenaar <Bram@vim.org>
parents: 27926
diff changeset
1438 break;
ca7a207d83cd patch 8.2.4489: failing test for comparing v:null with number
Bram Moolenaar <Bram@vim.org>
parents: 27926
diff changeset
1439 #ifdef FEAT_FLOAT
ca7a207d83cd patch 8.2.4489: failing test for comparing v:null with number
Bram Moolenaar <Bram@vim.org>
parents: 27926
diff changeset
1440 case VAR_FLOAT: if (!in_vim9script())
ca7a207d83cd patch 8.2.4489: failing test for comparing v:null with number
Bram Moolenaar <Bram@vim.org>
parents: 27926
diff changeset
1441 return tv->vval.v_float == 0.0;
ca7a207d83cd patch 8.2.4489: failing test for comparing v:null with number
Bram Moolenaar <Bram@vim.org>
parents: 27926
diff changeset
1442 break;
ca7a207d83cd patch 8.2.4489: failing test for comparing v:null with number
Bram Moolenaar <Bram@vim.org>
parents: 27926
diff changeset
1443 #endif
27924
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1444 default: break;
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1445 }
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1446 }
28217
662d2d5db9a6 patch 8.2.4634: Vim9: cannot initialize a variable to null_list
Bram Moolenaar <Bram@vim.org>
parents: 28103
diff changeset
1447 // although comparing null with number, float or bool is not very useful
28103
1615d305c71d patch 8.2.4576: Vim9: error for comparing with null can be annoying
Bram Moolenaar <Bram@vim.org>
parents: 28019
diff changeset
1448 // we won't give an error
1615d305c71d patch 8.2.4576: Vim9: error for comparing with null can be annoying
Bram Moolenaar <Bram@vim.org>
parents: 28019
diff changeset
1449 return FALSE;
27924
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1450 }
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1451
e6e3abc28c7a patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents: 27034
diff changeset
1452 /*
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1453 * 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
1454 * 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
1455 * 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
1456 */
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1457 int
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1458 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
1459 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
1460 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
1461 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
1462 int *res)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1463 {
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 = 0;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1465
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1466 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
1467 {
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1468 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
1469 && 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
1470 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
1471 val = !val;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1472 }
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1473 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
1474 || (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
1475 {
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1476 if (tv1->v_type != tv2->v_type)
26966
ac75c145f0a9 patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26962
diff changeset
1477 emsg(_(e_can_only_compare_blob_with_blob));
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1478 else
26877
06a137af96f8 patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26782
diff changeset
1479 emsg(_(e_invalid_operation_for_blob));
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1480 return FAIL;
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 else
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1483 {
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1484 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
1485 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
1486 val = !val;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1487 }
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1488 *res = val;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1489 return OK;
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
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1492 /*
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1493 * 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
1494 * 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
1495 * 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
1496 */
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1497 int
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1498 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
1499 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
1500 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
1501 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
1502 int ic,
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1503 int *res)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1504 {
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1505 int val;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1506
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1507 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
1508 {
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1509 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
1510 && 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
1511 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
1512 val = !val;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1513 }
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1514 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
1515 || (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
1516 {
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1517 if (tv1->v_type != tv2->v_type)
26952
b34ddbca305c patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26948
diff changeset
1518 emsg(_(e_can_only_compare_dictionary_with_dictionary));
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1519 else
26952
b34ddbca305c patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26948
diff changeset
1520 emsg(_(e_invalid_operation_for_dictionary));
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1521 return FAIL;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1522 }
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1523 else
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1524 {
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1525 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
1526 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
1527 val = !val;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1528 }
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1529 *res = val;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1530 return OK;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1531 }
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1532
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1533 /*
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1534 * 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
1535 * 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
1536 * 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
1537 */
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1538 int
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1539 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
1540 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
1541 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
1542 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
1543 int ic,
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1544 int *res)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1545 {
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1546 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
1547
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1548 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
1549 && 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
1550 {
26952
b34ddbca305c patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26948
diff changeset
1551 emsg(_(e_invalid_operation_for_funcrefs));
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1552 return FAIL;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1553 }
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1554 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
1555 || (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
1556 // 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
1557 // 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
1558 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
1559 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
1560 {
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1561 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
1562 // 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
1563 // the same
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1564 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
1565 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
1566 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
1567 else
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1568 val = FALSE;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1569 }
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1570 else
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1571 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
1572 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
1573 val = !val;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1574 *res = val;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1575 return OK;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1576 }
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1577
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1578 /*
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1579 * 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
1580 * 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
1581 * 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
1582 */
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1583 int
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1584 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
1585 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
1586 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
1587 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
1588 int ic,
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1589 int *res)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1590 {
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1591 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
1592 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
1593 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
1594 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
1595
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1596 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
1597 && ((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
1598 || (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
1599 {
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1600 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
1601 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
1602 return FAIL;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1603 }
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1604 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
1605 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
1606 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
1607 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
1608 switch (type)
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1609 {
28019
53e2bf6032e5 patch 8.2.4534: Vim9: "is" operator with empty string and null returns true
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
1610 case EXPR_IS: if (in_vim9script())
53e2bf6032e5 patch 8.2.4534: Vim9: "is" operator with empty string and null returns true
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
1611 {
53e2bf6032e5 patch 8.2.4534: Vim9: "is" operator with empty string and null returns true
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
1612 // Really check it is the same string, not just
53e2bf6032e5 patch 8.2.4534: Vim9: "is" operator with empty string and null returns true
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
1613 // the same value.
53e2bf6032e5 patch 8.2.4534: Vim9: "is" operator with empty string and null returns true
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
1614 val = tv1->vval.v_string == tv2->vval.v_string;
53e2bf6032e5 patch 8.2.4534: Vim9: "is" operator with empty string and null returns true
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
1615 break;
53e2bf6032e5 patch 8.2.4534: Vim9: "is" operator with empty string and null returns true
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
1616 }
53e2bf6032e5 patch 8.2.4534: Vim9: "is" operator with empty string and null returns true
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
1617 // FALLTHROUGH
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1618 case EXPR_EQUAL: val = (i == 0); break;
28019
53e2bf6032e5 patch 8.2.4534: Vim9: "is" operator with empty string and null returns true
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
1619 case EXPR_ISNOT: if (in_vim9script())
53e2bf6032e5 patch 8.2.4534: Vim9: "is" operator with empty string and null returns true
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
1620 {
53e2bf6032e5 patch 8.2.4534: Vim9: "is" operator with empty string and null returns true
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
1621 // Really check it is not the same string, not
53e2bf6032e5 patch 8.2.4534: Vim9: "is" operator with empty string and null returns true
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
1622 // just a different value.
53e2bf6032e5 patch 8.2.4534: Vim9: "is" operator with empty string and null returns true
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
1623 val = tv1->vval.v_string != tv2->vval.v_string;
53e2bf6032e5 patch 8.2.4534: Vim9: "is" operator with empty string and null returns true
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
1624 break;
53e2bf6032e5 patch 8.2.4534: Vim9: "is" operator with empty string and null returns true
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
1625 }
53e2bf6032e5 patch 8.2.4534: Vim9: "is" operator with empty string and null returns true
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
1626 // FALLTHROUGH
26644
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1627 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
1628 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
1629 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
1630 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
1631 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
1632
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1633 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
1634 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
1635 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
1636 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
1637 val = !val;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1638 break;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1639
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1640 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
1641 }
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1642 *res = val;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1643 return OK;
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1644 }
2fc1e528e0e1 patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Bram Moolenaar <Bram@vim.org>
parents: 26638
diff changeset
1645 /*
23788
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
1646 * 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
1647 * 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
1648 * 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
1649 */
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1650 char_u *
23788
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
1651 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
1652 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1653 char_u *tofree;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1654 char_u numbuf[NUMBUFLEN];
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1655 char_u *ret = NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1656
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1657 if (arg == NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1658 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
1659 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
1660 {
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
1661 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
1662 : 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
1663 }
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
1664 else
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
1665 {
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
1666 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
1667 // 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
1668 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
1669 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
1670 }
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1671 return ret;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1672 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1673
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1674 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1675 * 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
1676 * 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
1677 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1678 int
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1679 tv_islocked(typval_T *tv)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1680 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1681 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
1682 || (tv->v_type == VAR_LIST
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1683 && tv->vval.v_list != NULL
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1684 && (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
1685 || (tv->v_type == VAR_DICT
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1686 && tv->vval.v_dict != NULL
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1687 && (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
1688 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1689
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1690 static int
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1691 func_equal(
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1692 typval_T *tv1,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1693 typval_T *tv2,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1694 int ic) // ignore case
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1695 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1696 char_u *s1, *s2;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1697 dict_T *d1, *d2;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1698 int a1, a2;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1699 int i;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1700
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1701 // 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
1702 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
1703 : 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
1704 if (s1 != NULL && *s1 == NUL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1705 s1 = NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1706 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
1707 : 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
1708 if (s2 != NULL && *s2 == NUL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1709 s2 = NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1710 if (s1 == NULL || s2 == NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1711 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1712 if (s1 != s2)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1713 return FALSE;
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 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
1716 return FALSE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1717
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1718 // 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
1719 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
1720 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
1721 if (d1 == NULL || d2 == NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1722 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1723 if (d1 != d2)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1724 return FALSE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1725 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1726 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
1727 return FALSE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1728
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1729 // 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
1730 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
1731 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
1732 if (a1 != a2)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1733 return FALSE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1734 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
1735 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
1736 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
1737 return FALSE;
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 return TRUE;
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
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1742 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1743 * 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
1744 * 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
1745 * 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
1746 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1747 int
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1748 tv_equal(
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1749 typval_T *tv1,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1750 typval_T *tv2,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1751 int ic, // ignore case
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1752 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
1753 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1754 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
1755 char_u *s1, *s2;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1756 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
1757 int r;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1758 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
1759
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1760 // 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
1761 // 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
1762 // 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
1763 // 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
1764 // 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
1765 // recursiveness quickly.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1766 if (!recursive)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1767 tv_equal_recurse_limit = 1000;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1768 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
1769 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1770 --tv_equal_recurse_limit;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1771 return TRUE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1772 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1773
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1774 // 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
1775 // arguments.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1776 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
1777 || (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
1778 && (tv2->v_type == VAR_FUNC
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1779 || (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
1780 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1781 ++recursive_cnt;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1782 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
1783 --recursive_cnt;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1784 return r;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1785 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1786
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
1787 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
1788 && ((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
1789 || (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
1790 return FALSE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1791
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1792 switch (tv1->v_type)
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 case VAR_LIST:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1795 ++recursive_cnt;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1796 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
1797 --recursive_cnt;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1798 return r;
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 case VAR_DICT:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1801 ++recursive_cnt;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1802 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
1803 --recursive_cnt;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1804 return r;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1805
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1806 case VAR_BLOB:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1807 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
1808
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1809 case VAR_NUMBER:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1810 case VAR_BOOL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1811 case VAR_SPECIAL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1812 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
1813
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1814 case VAR_STRING:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1815 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
1816 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
1817 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
1818
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1819 case VAR_FLOAT:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1820 #ifdef FEAT_FLOAT
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1821 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
1822 #endif
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1823 case VAR_JOB:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1824 #ifdef FEAT_JOB_CHANNEL
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1825 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
1826 #endif
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1827 case VAR_CHANNEL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1828 #ifdef FEAT_JOB_CHANNEL
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1829 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
1830 #endif
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24424
diff changeset
1831 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
1832 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
1833
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1834 case VAR_PARTIAL:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1835 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
1836
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1837 case VAR_FUNC:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1838 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
1839
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1840 case VAR_UNKNOWN:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1841 case VAR_ANY:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1842 case VAR_VOID:
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1843 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1844 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1845
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1846 // 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
1847 // 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
1848 return FALSE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1849 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1850
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1851 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1852 * Get an option value.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1853 * "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
1854 * "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
1855 * Return OK or FAIL.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1856 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1857 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
1858 eval_option(
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1859 char_u **arg,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1860 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
1861 int evaluate)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1862 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1863 char_u *option_end;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1864 long numval;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1865 char_u *stringval;
23422
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
1866 getoption_T opt_type;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1867 int c;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1868 int working = (**arg == '+'); // has("+option")
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1869 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
1870 int scope;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1871
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1872 // 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
1873 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
1874 if (option_end == NULL)
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 if (rettv != NULL)
26602
fac6673086df patch 8.2.3830: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26585
diff changeset
1877 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
1878 return FAIL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1879 }
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 (!evaluate)
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 *arg = option_end;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1884 return OK;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1885 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1886
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1887 c = *option_end;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1888 *option_end = NUL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1889 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
1890 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
1891
23422
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
1892 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
1893 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1894 if (rettv != NULL)
26602
fac6673086df patch 8.2.3830: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26585
diff changeset
1895 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
1896 ret = FAIL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1897 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1898 else if (rettv != NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1899 {
23519
cb66613dd9d5 patch 8.2.2302: Vim9: using an option value may use uninitialized memory
Bram Moolenaar <Bram@vim.org>
parents: 23422
diff changeset
1900 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
1901 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
1902 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1903 rettv->v_type = VAR_STRING;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1904 rettv->vval.v_string = NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1905 }
23422
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
1906 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
1907 {
23422
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
1908 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
1909 ? VAR_BOOL : VAR_NUMBER;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1910 rettv->vval.v_number = 0;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1911 }
23422
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
1912 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
1913 {
23422
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
1914 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
1915 {
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
1916 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
1917 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
1918 }
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
1919 else
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
1920 {
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
1921 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
1922 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
1923 }
20587
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 else // string option
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1926 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1927 rettv->v_type = VAR_STRING;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1928 rettv->vval.v_string = stringval;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1929 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1930 }
23422
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
1931 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
1932 || 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
1933 || 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
1934 ret = FAIL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1935
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1936 *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
1937 *arg = option_end;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1938
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1939 return ret;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1940 }
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 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1943 * 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
1944 * Return OK or FAIL.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1945 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1946 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
1947 eval_number(
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1948 char_u **arg,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1949 typval_T *rettv,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1950 int evaluate,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1951 int want_string UNUSED)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1952 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1953 int len;
25622
15b54e0a576b patch 8.2.3347: check for legacy script is incomplete
Bram Moolenaar <Bram@vim.org>
parents: 25585
diff changeset
1954 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
1955 #ifdef FEAT_FLOAT
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1956 char_u *p;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1957 int get_float = FALSE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1958
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1959 // 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
1960 // "[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
1961 // 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
1962 // 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
1963 // omitted.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1964 // 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
1965 // ":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
1966 if (**arg == '.')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1967 p = *arg;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1968 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
1969 {
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25443
diff changeset
1970 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
1971 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
1972 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
1973 {
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25443
diff changeset
1974 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
1975 ++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
1976 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
1977 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
1978 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
1979 }
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25443
diff changeset
1980 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
1981 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
1982 }
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1983 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
1984 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1985 get_float = TRUE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1986 p = skipdigits(p + 2);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1987 if (*p == 'e' || *p == 'E')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1988 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1989 ++p;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1990 if (*p == '-' || *p == '+')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1991 ++p;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1992 if (!vim_isdigit(*p))
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1993 get_float = FALSE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1994 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1995 p = skipdigits(p + 1);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1996 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1997 if (ASCII_ISALPHA(*p) || *p == '.')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1998 get_float = FALSE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1999 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2000 if (get_float)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2001 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2002 float_T f;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2003
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
2004 *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
2005 if (evaluate)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2006 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2007 rettv->v_type = VAR_FLOAT;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2008 rettv->vval.v_float = f;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2009 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2010 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2011 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2012 #endif
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2013 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
2014 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2015 char_u *bp;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2016 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
2017
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2018 // Blob constant: 0z0123456789abcdef
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2019 if (evaluate)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2020 blob = blob_alloc();
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2021 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
2022 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2023 if (!vim_isxdigit(bp[1]))
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2024 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2025 if (blob != NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2026 {
26966
ac75c145f0a9 patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26962
diff changeset
2027 emsg(_(e_blob_literal_should_have_an_even_number_of_hex_characters));
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2028 ga_clear(&blob->bv_ga);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2029 VIM_CLEAR(blob);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2030 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2031 return FAIL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2032 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2033 if (blob != NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2034 ga_append(&blob->bv_ga,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2035 (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
2036 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
2037 ++bp;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2038 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2039 if (blob != NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2040 rettv_blob_set(rettv, blob);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2041 *arg = bp;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2042 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2043 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2044 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2045 varnumber_T n;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2046
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2047 // 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
2048 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
2049 ? STR2NR_NO_OCT + STR2NR_QUOTE
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2050 : 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
2051 if (len == 0)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2052 {
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
2053 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
2054 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
2055 return FAIL;
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 *arg += len;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2058 if (evaluate)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2059 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2060 rettv->v_type = VAR_NUMBER;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2061 rettv->vval.v_number = n;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2062 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2063 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2064 return OK;
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
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2067 /*
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2068 * Evaluate a string constant and put the result in "rettv".
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2069 * "*arg" points to the double quote or to after it when "interpolate" is TRUE.
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2070 * When "interpolate" is TRUE reduce "{{" to "{", reduce "}}" to "}" and stop
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2071 * at a single "{".
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2072 * Return OK or FAIL.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2073 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2074 int
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2075 eval_string(char_u **arg, typval_T *rettv, int evaluate, int interpolate)
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2076 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2077 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
2078 char_u *end;
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2079 int extra = interpolate ? 1 : 0;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2080 int off = interpolate ? 0 : 1;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2081 int len;
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 // Find the end of the string, skipping backslashed characters.
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2084 for (p = *arg + off; *p != NUL && *p != '"'; MB_PTR_ADV(p))
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2085 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2086 if (*p == '\\' && p[1] != NUL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2087 {
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 // A "\<x>" form occupies at least 4 characters, and produces up
28668
53c608c7ea9e patch 8.2.4858: K_SPECIAL may be escaped twice
Bram Moolenaar <Bram@vim.org>
parents: 28217
diff changeset
2090 // to 9 characters (6 for the char and 3 for a modifier):
53c608c7ea9e patch 8.2.4858: K_SPECIAL may be escaped twice
Bram Moolenaar <Bram@vim.org>
parents: 28217
diff changeset
2091 // reserve space for 5 extra.
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2092 if (*p == '<')
28668
53c608c7ea9e patch 8.2.4858: K_SPECIAL may be escaped twice
Bram Moolenaar <Bram@vim.org>
parents: 28217
diff changeset
2093 extra += 5;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2094 }
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2095 else if (interpolate && (*p == '{' || *p == '}'))
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2096 {
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2097 if (*p == '{' && p[1] != '{') // start of expression
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2098 break;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2099 ++p;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2100 if (p[-1] == '}' && *p != '}') // single '}' is an error
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2101 {
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2102 semsg(_(e_stray_closing_curly_str), *arg);
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2103 return FAIL;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2104 }
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2105 --extra; // "{{" becomes "{", "}}" becomes "}"
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2106 }
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2107 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2108
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2109 if (*p != '"' && !(interpolate && *p == '{'))
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2110 {
26602
fac6673086df patch 8.2.3830: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26585
diff changeset
2111 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
2112 return FAIL;
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
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2115 // 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
2116 if (!evaluate)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2117 {
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2118 *arg = p + off;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2119 return OK;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2120 }
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 // 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
2123 // characters.
20925
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
2124 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
2125 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
2126 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
2127 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
2128 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
2129 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
2130
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2131 for (p = *arg + off; *p != NUL && *p != '"'; )
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2132 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2133 if (*p == '\\')
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 switch (*++p)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2136 {
20925
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
2137 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
2138 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
2139 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
2140 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
2141 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
2142 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
2143
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2144 case 'X': // hex: "\x1", "\x12"
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2145 case 'x':
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2146 case 'u': // Unicode: "\u0023"
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2147 case 'U':
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2148 if (vim_isxdigit(p[1]))
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2149 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2150 int n, nr;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2151 int c = toupper(*p);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2152
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2153 if (c == 'X')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2154 n = 2;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2155 else if (*p == 'u')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2156 n = 4;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2157 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2158 n = 8;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2159 nr = 0;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2160 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
2161 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2162 ++p;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2163 nr = (nr << 4) + hex2nr(*p);
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 ++p;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2166 // 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
2167 // 'encoding'.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2168 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
2169 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
2170 else
20925
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
2171 *end++ = nr;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2172 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2173 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2174
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2175 // octal: "\1", "\12", "\123"
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2176 case '0':
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2177 case '1':
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2178 case '2':
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2179 case '3':
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2180 case '4':
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2181 case '5':
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2182 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
2183 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
2184 if (*p >= '0' && *p <= '7')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2185 {
20925
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
2186 *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
2187 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
2188 *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
2189 }
20925
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
2190 ++end;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2191 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2192
20627
8bce783af0cb patch 8.2.0867: using {xxx} for encoding a modifier is not nice
Bram Moolenaar <Bram@vim.org>
parents: 20603
diff changeset
2193 // 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
2194 case '<':
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2195 {
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
2196 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
2197
20627
8bce783af0cb patch 8.2.0867: using {xxx} for encoding a modifier is not nice
Bram Moolenaar <Bram@vim.org>
parents: 20603
diff changeset
2198 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
2199 flags |= FSK_SIMPLIFY;
28668
53c608c7ea9e patch 8.2.4858: K_SPECIAL may be escaped twice
Bram Moolenaar <Bram@vim.org>
parents: 28217
diff changeset
2200 extra = trans_special(&p, end, flags, FALSE, 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
2201 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
2202 {
20925
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
2203 end += extra;
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
2204 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
2205 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
2206 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
2207 }
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2208 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2209 // FALLTHROUGH
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2210
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2211 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
2212 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2213 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2214 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2215 else
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2216 {
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2217 if (interpolate && (*p == '{' || *p == '}'))
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2218 {
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2219 if (*p == '{' && p[1] != '{') // start of expression
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2220 break;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2221 ++p; // reduce "{{" to "{" and "}}" to "}"
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2222 }
20925
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
2223 MB_COPY_CHAR(p, end);
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2224 }
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2225 }
20925
0aeac2b45846 patch 8.2.1014: using "name" for a string result is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20627
diff changeset
2226 *end = NUL;
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2227 if (*p == '"' && !interpolate)
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2228 ++p;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2229 *arg = p;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2230
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2231 return OK;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2232 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2233
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2234 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2235 * Allocate a variable for a 'str''ing' constant.
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2236 * When "interpolate" is TRUE reduce "{{" to "{" and stop at a single "{".
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2237 * Return OK when a "rettv" was set to the string.
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2238 * Return FAIL on error, "rettv" is not set.
20587
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 int
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2241 eval_lit_string(char_u **arg, typval_T *rettv, int evaluate, int interpolate)
20587
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 *p;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2244 char_u *str;
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2245 int reduce = interpolate ? -1 : 0;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2246 int off = interpolate ? 0 : 1;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2247
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2248 // Find the end of the string, skipping ''.
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2249 for (p = *arg + off; *p != NUL; MB_PTR_ADV(p))
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2250 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2251 if (*p == '\'')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2252 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2253 if (p[1] != '\'')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2254 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2255 ++reduce;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2256 ++p;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2257 }
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2258 else if (interpolate)
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2259 {
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2260 if (*p == '{')
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2261 {
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2262 if (p[1] != '{')
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2263 break;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2264 ++p;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2265 ++reduce;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2266 }
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2267 else if (*p == '}')
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2268 {
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2269 ++p;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2270 if (*p != '}')
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2271 {
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2272 semsg(_(e_stray_closing_curly_str), *arg);
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2273 return FAIL;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2274 }
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2275 ++reduce;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2276 }
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2277 }
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2278 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2279
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2280 if (*p != '\'' && !(interpolate && *p == '{'))
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2281 {
26602
fac6673086df patch 8.2.3830: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26585
diff changeset
2282 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
2283 return FAIL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2284 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2285
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2286 // 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
2287 if (!evaluate)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2288 {
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2289 *arg = p + off;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2290 return OK;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2291 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2292
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2293 // Copy the string into allocated memory, handling '' to ' reduction and
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2294 // any expressions.
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2295 str = alloc((p - *arg) - reduce);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2296 if (str == NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2297 return FAIL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2298 rettv->v_type = VAR_STRING;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2299 rettv->vval.v_string = str;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2300
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2301 for (p = *arg + off; *p != NUL; )
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2302 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2303 if (*p == '\'')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2304 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2305 if (p[1] != '\'')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2306 break;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2307 ++p;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2308 }
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2309 else if (interpolate && (*p == '{' || *p == '}'))
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2310 {
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2311 if (*p == '{' && p[1] != '{')
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2312 break;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2313 ++p;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2314 }
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2315 MB_COPY_CHAR(p, str);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2316 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2317 *str = NUL;
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2318 *arg = p + off;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2319
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2320 return OK;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2321 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2322
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2323 /*
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2324 * Evaluate a single or double quoted string possibly containing expressions.
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2325 * "arg" points to the '$'. The result is put in "rettv".
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2326 * Returns OK or FAIL.
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2327 */
28718
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28674
diff changeset
2328 int
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28674
diff changeset
2329 eval_interp_string(char_u **arg, typval_T *rettv, int evaluate)
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28674
diff changeset
2330 {
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28674
diff changeset
2331 typval_T tv;
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2332 int ret = OK;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2333 int quote;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2334 garray_T ga;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2335 char_u *p;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2336
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2337 ga_init2(&ga, 1, 80);
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2338
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2339 // *arg is on the '$' character, move it to the first string character.
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2340 ++*arg;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2341 quote = **arg;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2342 ++*arg;
28718
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28674
diff changeset
2343
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2344 for (;;)
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2345 {
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2346 // Get the string up to the matching quote or to a single '{'.
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2347 // "arg" is advanced to either the quote or the '{'.
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2348 if (quote == '"')
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2349 ret = eval_string(arg, &tv, evaluate, TRUE);
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2350 else
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2351 ret = eval_lit_string(arg, &tv, evaluate, TRUE);
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2352 if (ret == FAIL)
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2353 break;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2354 if (evaluate)
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2355 {
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2356 ga_concat(&ga, tv.vval.v_string);
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2357 clear_tv(&tv);
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2358 }
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2359
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2360 if (**arg != '{')
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2361 {
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2362 // found terminating quote
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2363 ++*arg;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2364 break;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2365 }
28821
006d525419fa patch 8.2.4934: string interpolation fails when not evaluating
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
2366 p = eval_one_expr_in_str(*arg, &ga, evaluate);
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2367 if (p == NULL)
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2368 {
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2369 ret = FAIL;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2370 break;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2371 }
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2372 *arg = p;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2373 }
28718
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28674
diff changeset
2374
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28674
diff changeset
2375 rettv->v_type = VAR_STRING;
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2376 if (ret == FAIL || !evaluate || ga_append(&ga, NUL) == FAIL)
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2377 {
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2378 ga_clear(&ga);
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2379 rettv->vval.v_string = NULL;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2380 return ret;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2381 }
28718
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28674
diff changeset
2382
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2383 rettv->vval.v_string = ga.ga_data;
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
2384 return OK;
28718
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28674
diff changeset
2385 }
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28674
diff changeset
2386
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2387 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2388 * 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
2389 * 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
2390 * "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
2391 * 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
2392 * May return NULL.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2393 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2394 char_u *
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2395 tv2string(
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2396 typval_T *tv,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2397 char_u **tofree,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2398 char_u *numbuf,
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2399 int copyID)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2400 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2401 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
2402 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2403
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2404 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2405 * 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
2406 * "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
2407 * 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
2408 * 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
2409 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2410 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
2411 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
2412 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2413 char_u *string = NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2414 int len;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2415 int cc;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2416 char_u *name;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2417 int mustfree = FALSE;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2418
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2419 ++*arg;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2420 name = *arg;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2421 len = get_env_len(arg);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2422 if (evaluate)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2423 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2424 if (len == 0)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2425 return FAIL; // invalid empty name
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2426
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2427 cc = name[len];
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2428 name[len] = NUL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2429 // 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
2430 string = vim_getenv(name, &mustfree);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2431 if (string != NULL && *string != NUL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2432 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2433 if (!mustfree)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2434 string = vim_strsave(string);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2435 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2436 else
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2437 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2438 if (mustfree)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2439 vim_free(string);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2440
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2441 // 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
2442 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
2443 if (string != NULL && *string == '$')
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2444 VIM_CLEAR(string);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2445 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2446 name[len] = cc;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2447
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2448 rettv->v_type = VAR_STRING;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2449 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
2450 rettv->v_lock = 0;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2451 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2452
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2453 return OK;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2454 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2455
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2456 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2457 * 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
2458 * 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
2459 * Returns -1 on error.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2460 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2461 linenr_T
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2462 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
2463 {
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
2464 linenr_T lnum = -1;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2465
21831
d8422de73113 patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21425
diff changeset
2466 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
2467 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
2468 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
2469 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2470 int fnum;
26782
b7b82279426f patch 8.2.3919: Vim9: wrong argument for append() results in two errors
Bram Moolenaar <Bram@vim.org>
parents: 26731
diff changeset
2471 pos_T *fp;
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2472
24260
ad065f64eb20 patch 8.2.2671: error for line number in legacy script
Bram Moolenaar <Bram@vim.org>
parents: 24258
diff changeset
2473 // no valid number, try using arg like line()
26782
b7b82279426f patch 8.2.3919: Vim9: wrong argument for append() results in two errors
Bram Moolenaar <Bram@vim.org>
parents: 26731
diff changeset
2474 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
2475 if (fp != NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2476 lnum = fp->lnum;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2477 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2478 return lnum;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2479 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2480
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2481 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2482 * 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
2483 * 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
2484 * Returns 0 on error.
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2485 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2486 linenr_T
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2487 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
2488 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2489 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
2490 && 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
2491 && argvars[0].vval.v_string[0] == '$'
26782
b7b82279426f patch 8.2.3919: Vim9: wrong argument for append() results in two errors
Bram Moolenaar <Bram@vim.org>
parents: 26731
diff changeset
2492 && argvars[0].vval.v_string[1] == NUL
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2493 && buf != NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2494 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
2495 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
2496 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2497
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2498 /*
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2499 * 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
2500 */
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2501 buf_T *
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2502 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
2503 {
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2504 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
2505 buf_T *buf;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2506
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2507 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
2508 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
2509 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
2510 return NULL;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2511 if (name == NULL || *name == NUL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2512 return curbuf;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2513 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
2514 return lastbuf;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2515
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2516 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
2517
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2518 // 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
2519 if (buf == NULL)
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2520 buf = find_buffer(tv);
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2521
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2522 return buf;
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2523 }
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2524
22025
71f886a48ef5 patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
2525 /*
71f886a48ef5 patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
2526 * 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
2527 */
71f886a48ef5 patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
2528 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
2529 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
2530 {
71f886a48ef5 patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
2531 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
2532
71f886a48ef5 patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
2533 ++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
2534 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
2535 --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
2536 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
2537 && 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
2538 && 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
2539 // 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
2540 (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
2541 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
2542 }
71f886a48ef5 patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Bram Moolenaar <Bram@vim.org>
parents: 21913
diff changeset
2543
20587
f502455965c0 patch 8.2.0847: typval related code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2544 #endif // FEAT_EVAL