annotate src/vim9type.c @ 23418:681f042ae5ac v8.2.2252

patch 8.2.2252: Vim9: crash when using lambda without return type in dict Commit: https://github.com/vim/vim/commit/6b55377303968e1624339cd95053201d5acdcaa2 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Dec 31 13:31:23 2020 +0100 patch 8.2.2252: Vim9: crash when using lambda without return type in dict Problem: Vim9: crash when using lambda without return type in dict. Solution: Without a return type use t_unknown. (closes https://github.com/vim/vim/issues/7587)
author Bram Moolenaar <Bram@vim.org>
date Thu, 31 Dec 2020 13:45:04 +0100
parents f181fe2150ab
children 62fe9a7fd582
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2 *
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 *
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 */
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 /*
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 * vim9type.c: handling of types
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 */
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 #define USING_FLOAT_STUFF
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15 #include "vim.h"
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17 #if defined(FEAT_EVAL) || defined(PROTO)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19 #ifdef VMS
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 # include <float.h>
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 #endif
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23 /*
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 * Allocate memory for a type_T and add the pointer to type_gap, so that it can
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
25 * be easily freed later.
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26 */
22184
2463b3d89ce2 patch 8.2.1641: Vim9: cannot use 0 or 1 where a bool is expected
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
27 type_T *
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
28 get_type_ptr(garray_T *type_gap)
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30 type_T *type;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32 if (ga_grow(type_gap, 1) == FAIL)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33 return NULL;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34 type = ALLOC_CLEAR_ONE(type_T);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 if (type != NULL)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37 ((type_T **)type_gap->ga_data)[type_gap->ga_len] = type;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 ++type_gap->ga_len;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40 return type;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43 void
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44 clear_type_list(garray_T *gap)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 while (gap->ga_len > 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 vim_free(((type_T **)gap->ga_data)[--gap->ga_len]);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48 ga_clear(gap);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
51 /*
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
52 * Take a type that is using entries in a growarray and turn it into a type
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
53 * with allocated entries.
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
54 */
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
55 type_T *
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
56 alloc_type(type_T *type)
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
57 {
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
58 type_T *ret;
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
59
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
60 if (type == NULL)
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
61 return NULL;
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
62
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
63 // A fixed type never contains allocated types, return as-is.
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
64 if (type->tt_flags & TTFLAG_STATIC)
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
65 return type;
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
66
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
67 ret = ALLOC_ONE(type_T);
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
68 *ret = *type;
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
69
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
70 if (ret->tt_member != NULL)
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
71 ret->tt_member = alloc_type(ret->tt_member);
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
72 if (type->tt_args != NULL)
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
73 {
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
74 int i;
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
75
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
76 ret->tt_args = ALLOC_MULT(type_T *, type->tt_argcount);
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
77 if (ret->tt_args != NULL)
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
78 for (i = 0; i < type->tt_argcount; ++i)
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
79 ret->tt_args[i] = alloc_type(type->tt_args[i]);
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
80 }
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
81
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
82 return ret;
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
83 }
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
84
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
85 /*
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
86 * Free a type that was created with alloc_type().
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
87 */
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
88 void
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
89 free_type(type_T *type)
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
90 {
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
91 int i;
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
92
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
93 if (type == NULL || (type->tt_flags & TTFLAG_STATIC))
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
94 return;
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
95 if (type->tt_args != NULL)
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
96 {
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
97 for (i = 0; i < type->tt_argcount; ++i)
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
98 free_type(type->tt_args[i]);
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
99 vim_free(type->tt_args);
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
100 }
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
101 free_type(type->tt_member);
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
102 vim_free(type);
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
103 }
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
104
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105 type_T *
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106 get_list_type(type_T *member_type, garray_T *type_gap)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108 type_T *type;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
110 // recognize commonly used types
22804
af26fadf333d patch 8.2.1950: Vim9: crash when compiling function fails when getting type
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
111 if (member_type == NULL || member_type->tt_type == VAR_ANY)
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
112 return &t_list_any;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
113 if (member_type->tt_type == VAR_VOID
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114 || member_type->tt_type == VAR_UNKNOWN)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
115 return &t_list_empty;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
116 if (member_type->tt_type == VAR_BOOL)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
117 return &t_list_bool;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
118 if (member_type->tt_type == VAR_NUMBER)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
119 return &t_list_number;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
120 if (member_type->tt_type == VAR_STRING)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
121 return &t_list_string;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
122
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
123 // Not a common type, create a new entry.
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
124 type = get_type_ptr(type_gap);
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
125 if (type == NULL)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
126 return &t_any;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
127 type->tt_type = VAR_LIST;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
128 type->tt_member = member_type;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
129 type->tt_argcount = 0;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
130 type->tt_args = NULL;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
131 return type;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
132 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
133
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
134 type_T *
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135 get_dict_type(type_T *member_type, garray_T *type_gap)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
136 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
137 type_T *type;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
138
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
139 // recognize commonly used types
22804
af26fadf333d patch 8.2.1950: Vim9: crash when compiling function fails when getting type
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
140 if (member_type == NULL || member_type->tt_type == VAR_ANY)
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
141 return &t_dict_any;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
142 if (member_type->tt_type == VAR_VOID
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
143 || member_type->tt_type == VAR_UNKNOWN)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
144 return &t_dict_empty;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
145 if (member_type->tt_type == VAR_BOOL)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
146 return &t_dict_bool;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
147 if (member_type->tt_type == VAR_NUMBER)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
148 return &t_dict_number;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
149 if (member_type->tt_type == VAR_STRING)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
150 return &t_dict_string;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
151
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
152 // Not a common type, create a new entry.
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
153 type = get_type_ptr(type_gap);
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
154 if (type == NULL)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
155 return &t_any;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
156 type->tt_type = VAR_DICT;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
157 type->tt_member = member_type;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
158 type->tt_argcount = 0;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
159 type->tt_args = NULL;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
160 return type;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
161 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
162
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
163 /*
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
164 * Allocate a new type for a function.
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
165 */
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
166 type_T *
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
167 alloc_func_type(type_T *ret_type, int argcount, garray_T *type_gap)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
168 {
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
169 type_T *type = get_type_ptr(type_gap);
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
170
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
171 if (type == NULL)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
172 return &t_any;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
173 type->tt_type = VAR_FUNC;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
174 type->tt_member = ret_type;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
175 type->tt_argcount = argcount;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
176 type->tt_args = NULL;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
177 return type;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
178 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
179
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
180 /*
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
181 * Get a function type, based on the return type "ret_type".
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
182 * If "argcount" is -1 or 0 a predefined type can be used.
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
183 * If "argcount" > 0 always create a new type, so that arguments can be added.
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
184 */
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
185 type_T *
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
186 get_func_type(type_T *ret_type, int argcount, garray_T *type_gap)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
187 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
188 // recognize commonly used types
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
189 if (argcount <= 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
191 if (ret_type == &t_unknown)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
192 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
193 // (argcount == 0) is not possible
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
194 return &t_func_unknown;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
195 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
196 if (ret_type == &t_void)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
197 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
198 if (argcount == 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
199 return &t_func_0_void;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
200 else
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
201 return &t_func_void;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
202 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
203 if (ret_type == &t_any)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
204 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
205 if (argcount == 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
206 return &t_func_0_any;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
207 else
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
208 return &t_func_any;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
209 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
210 if (ret_type == &t_number)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
211 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
212 if (argcount == 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
213 return &t_func_0_number;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
214 else
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
215 return &t_func_number;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
216 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
217 if (ret_type == &t_string)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
218 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
219 if (argcount == 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
220 return &t_func_0_string;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
221 else
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
222 return &t_func_string;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
223 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
224 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
225
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
226 return alloc_func_type(ret_type, argcount, type_gap);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
227 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
228
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
229 /*
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
230 * For a function type, reserve space for "argcount" argument types (including
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
231 * vararg).
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
232 */
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
233 int
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
234 func_type_add_arg_types(
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
235 type_T *functype,
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
236 int argcount,
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
237 garray_T *type_gap)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
238 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
239 // To make it easy to free the space needed for the argument types, add the
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
240 // pointer to type_gap.
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
241 if (ga_grow(type_gap, 1) == FAIL)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
242 return FAIL;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
243 functype->tt_args = ALLOC_CLEAR_MULT(type_T *, argcount);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
244 if (functype->tt_args == NULL)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
245 return FAIL;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
246 ((type_T **)type_gap->ga_data)[type_gap->ga_len] =
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
247 (void *)functype->tt_args;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
248 ++type_gap->ga_len;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
249 return OK;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
250 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
251
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
252 /*
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
253 * Get a type_T for a typval_T.
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
254 * "type_gap" is used to temporarily create types in.
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
255 */
22202
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
256 static type_T *
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
257 typval2type_int(typval_T *tv, garray_T *type_gap)
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
258 {
22190
da851f3b6a0b patch 8.2.1644: Vim9: cannot assign 1 and 0 to bool at script level
Bram Moolenaar <Bram@vim.org>
parents: 22184
diff changeset
259 type_T *type;
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
260 type_T *member_type = &t_any;
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
261 int argcount = 0;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
262
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
263 if (tv->v_type == VAR_NUMBER)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
264 return &t_number;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
265 if (tv->v_type == VAR_BOOL)
22202
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
266 return &t_bool;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
267 if (tv->v_type == VAR_STRING)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
268 return &t_string;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
269
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
270 if (tv->v_type == VAR_LIST)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
271 {
22419
6a9e5c087c86 patch 8.2.1758: Vim9: type of unmaterialized list is wrong
Bram Moolenaar <Bram@vim.org>
parents: 22347
diff changeset
272 list_T *l = tv->vval.v_list;
6a9e5c087c86 patch 8.2.1758: Vim9: type of unmaterialized list is wrong
Bram Moolenaar <Bram@vim.org>
parents: 22347
diff changeset
273 listitem_T *li;
21803
e591b448a670 patch 8.2.1451: Vim9: list type at script level only uses first item
Bram Moolenaar <Bram@vim.org>
parents: 21789
diff changeset
274
22419
6a9e5c087c86 patch 8.2.1758: Vim9: type of unmaterialized list is wrong
Bram Moolenaar <Bram@vim.org>
parents: 22347
diff changeset
275 if (l == NULL || l->lv_first == NULL)
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
276 return &t_list_empty;
22419
6a9e5c087c86 patch 8.2.1758: Vim9: type of unmaterialized list is wrong
Bram Moolenaar <Bram@vim.org>
parents: 22347
diff changeset
277 if (l->lv_first == &range_list_item)
6a9e5c087c86 patch 8.2.1758: Vim9: type of unmaterialized list is wrong
Bram Moolenaar <Bram@vim.org>
parents: 22347
diff changeset
278 return &t_list_number;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
279
21803
e591b448a670 patch 8.2.1451: Vim9: list type at script level only uses first item
Bram Moolenaar <Bram@vim.org>
parents: 21789
diff changeset
280 // Use the common type of all members.
22419
6a9e5c087c86 patch 8.2.1758: Vim9: type of unmaterialized list is wrong
Bram Moolenaar <Bram@vim.org>
parents: 22347
diff changeset
281 member_type = typval2type(&l->lv_first->li_tv, type_gap);
6a9e5c087c86 patch 8.2.1758: Vim9: type of unmaterialized list is wrong
Bram Moolenaar <Bram@vim.org>
parents: 22347
diff changeset
282 for (li = l->lv_first->li_next; li != NULL; li = li->li_next)
21803
e591b448a670 patch 8.2.1451: Vim9: list type at script level only uses first item
Bram Moolenaar <Bram@vim.org>
parents: 21789
diff changeset
283 common_type(typval2type(&li->li_tv, type_gap),
e591b448a670 patch 8.2.1451: Vim9: list type at script level only uses first item
Bram Moolenaar <Bram@vim.org>
parents: 21789
diff changeset
284 member_type, &member_type, type_gap);
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
285 return get_list_type(member_type, type_gap);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
286 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
287
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
288 if (tv->v_type == VAR_DICT)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
289 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
290 dict_iterator_T iter;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
291 typval_T *value;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
292
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
293 if (tv->vval.v_dict == NULL
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
294 || tv->vval.v_dict->dv_hashtab.ht_used == 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
295 return &t_dict_empty;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
296
21803
e591b448a670 patch 8.2.1451: Vim9: list type at script level only uses first item
Bram Moolenaar <Bram@vim.org>
parents: 21789
diff changeset
297 // Use the common type of all values.
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
298 dict_iterate_start(tv, &iter);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
299 dict_iterate_next(&iter, &value);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
300 member_type = typval2type(value, type_gap);
21803
e591b448a670 patch 8.2.1451: Vim9: list type at script level only uses first item
Bram Moolenaar <Bram@vim.org>
parents: 21789
diff changeset
301 while (dict_iterate_next(&iter, &value) != NULL)
e591b448a670 patch 8.2.1451: Vim9: list type at script level only uses first item
Bram Moolenaar <Bram@vim.org>
parents: 21789
diff changeset
302 common_type(typval2type(value, type_gap),
e591b448a670 patch 8.2.1451: Vim9: list type at script level only uses first item
Bram Moolenaar <Bram@vim.org>
parents: 21789
diff changeset
303 member_type, &member_type, type_gap);
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
304 return get_dict_type(member_type, type_gap);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
305 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
306
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
307 if (tv->v_type == VAR_FUNC || tv->v_type == VAR_PARTIAL)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
308 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
309 char_u *name = NULL;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
310 ufunc_T *ufunc = NULL;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
311
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
312 if (tv->v_type == VAR_PARTIAL)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
313 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
314 if (tv->vval.v_partial->pt_func != NULL)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
315 ufunc = tv->vval.v_partial->pt_func;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
316 else
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
317 name = tv->vval.v_partial->pt_name;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
318 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
319 else
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
320 name = tv->vval.v_string;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
321 if (name != NULL)
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
322 {
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
323 int idx = find_internal_func(name);
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
324
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
325 if (idx >= 0)
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
326 {
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
327 // TODO: get actual arg count and types
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
328 argcount = -1;
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
329 member_type = internal_func_ret_type(idx, 0, NULL);
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
330 }
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
331 else
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
332 ufunc = find_func(name, FALSE, NULL);
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
333 }
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
334 if (ufunc != NULL)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
335 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
336 // May need to get the argument types from default values by
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
337 // compiling the function.
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
338 if (ufunc->uf_def_status == UF_TO_BE_COMPILED
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
339 && compile_def_function(ufunc, TRUE, NULL) == FAIL)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
340 return NULL;
23338
9c5275b1c763 patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23334
diff changeset
341 if (ufunc->uf_func_type == NULL)
9c5275b1c763 patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23334
diff changeset
342 set_function_type(ufunc);
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
343 if (ufunc->uf_func_type != NULL)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
344 return ufunc->uf_func_type;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
345 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
346 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
347
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
348 type = get_type_ptr(type_gap);
22190
da851f3b6a0b patch 8.2.1644: Vim9: cannot assign 1 and 0 to bool at script level
Bram Moolenaar <Bram@vim.org>
parents: 22184
diff changeset
349 if (type == NULL)
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
350 return NULL;
22190
da851f3b6a0b patch 8.2.1644: Vim9: cannot assign 1 and 0 to bool at script level
Bram Moolenaar <Bram@vim.org>
parents: 22184
diff changeset
351 type->tt_type = tv->v_type;
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
352 type->tt_argcount = argcount;
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
353 type->tt_member = member_type;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
354
22190
da851f3b6a0b patch 8.2.1644: Vim9: cannot assign 1 and 0 to bool at script level
Bram Moolenaar <Bram@vim.org>
parents: 22184
diff changeset
355 return type;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
356 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
357
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
358 /*
22202
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
359 * Return TRUE if "tv" is not a bool but should be converted to bool.
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
360 */
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
361 int
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
362 need_convert_to_bool(type_T *type, typval_T *tv)
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
363 {
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
364 return type != NULL && type == &t_bool && tv->v_type != VAR_BOOL
22494
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
365 && (tv->v_type == VAR_NUMBER
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
366 && (tv->vval.v_number == 0 || tv->vval.v_number == 1));
22202
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
367 }
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
368
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
369 /*
22494
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
370 * Get a type_T for a typval_T.
22202
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
371 * "type_list" is used to temporarily create types in.
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
372 */
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
373 type_T *
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
374 typval2type(typval_T *tv, garray_T *type_gap)
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
375 {
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
376 type_T *type = typval2type_int(tv, type_gap);
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
377
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
378 if (type != NULL && type != &t_bool
22494
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
379 && (tv->v_type == VAR_NUMBER
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
380 && (tv->vval.v_number == 0 || tv->vval.v_number == 1)))
23334
4b4f695e9cd1 patch 8.2.2210: Vim9: allocating a type to set TTFLAG_BOOL_OK
Bram Moolenaar <Bram@vim.org>
parents: 23332
diff changeset
381 // Number 0 and 1 and expression with "&&" or "||" can also be used for
4b4f695e9cd1 patch 8.2.2210: Vim9: allocating a type to set TTFLAG_BOOL_OK
Bram Moolenaar <Bram@vim.org>
parents: 23332
diff changeset
382 // bool.
4b4f695e9cd1 patch 8.2.2210: Vim9: allocating a type to set TTFLAG_BOOL_OK
Bram Moolenaar <Bram@vim.org>
parents: 23332
diff changeset
383 type = &t_number_bool;
22202
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
384 return type;
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
385 }
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
386
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
387 /*
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
388 * Get a type_T for a typval_T, used for v: variables.
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
389 * "type_list" is used to temporarily create types in.
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
390 */
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
391 type_T *
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
392 typval2type_vimvar(typval_T *tv, garray_T *type_gap)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
393 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
394 if (tv->v_type == VAR_LIST) // e.g. for v:oldfiles
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
395 return &t_list_string;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
396 if (tv->v_type == VAR_DICT) // e.g. for v:completed_item
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
397 return &t_dict_any;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
398 return typval2type(tv, type_gap);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
399 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
400
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
401
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
402 /*
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
403 * Return FAIL if "expected" and "actual" don't match.
22804
af26fadf333d patch 8.2.1950: Vim9: crash when compiling function fails when getting type
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
404 * When "argidx" > 0 it is included in the error message.
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
405 */
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
406 int
22004
a9e60176dcd3 patch 8.2.1551: Vim9: error for argument type does not mention the number
Bram Moolenaar <Bram@vim.org>
parents: 21909
diff changeset
407 check_typval_type(type_T *expected, typval_T *actual_tv, int argidx)
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
408 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
409 garray_T type_list;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
410 type_T *actual_type;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
411 int res = FAIL;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
412
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
413 ga_init2(&type_list, sizeof(type_T *), 10);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
414 actual_type = typval2type(actual_tv, &type_list);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
415 if (actual_type != NULL)
22004
a9e60176dcd3 patch 8.2.1551: Vim9: error for argument type does not mention the number
Bram Moolenaar <Bram@vim.org>
parents: 21909
diff changeset
416 res = check_type(expected, actual_type, TRUE, argidx);
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
417 clear_type_list(&type_list);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
418 return res;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
419 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
420
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
421 void
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
422 type_mismatch(type_T *expected, type_T *actual)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
423 {
22004
a9e60176dcd3 patch 8.2.1551: Vim9: error for argument type does not mention the number
Bram Moolenaar <Bram@vim.org>
parents: 21909
diff changeset
424 arg_type_mismatch(expected, actual, 0);
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
425 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
426
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
427 void
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
428 arg_type_mismatch(type_T *expected, type_T *actual, int argidx)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
429 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
430 char *tofree1, *tofree2;
22004
a9e60176dcd3 patch 8.2.1551: Vim9: error for argument type does not mention the number
Bram Moolenaar <Bram@vim.org>
parents: 21909
diff changeset
431 char *typename1 = type_name(expected, &tofree1);
a9e60176dcd3 patch 8.2.1551: Vim9: error for argument type does not mention the number
Bram Moolenaar <Bram@vim.org>
parents: 21909
diff changeset
432 char *typename2 = type_name(actual, &tofree2);
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
433
22004
a9e60176dcd3 patch 8.2.1551: Vim9: error for argument type does not mention the number
Bram Moolenaar <Bram@vim.org>
parents: 21909
diff changeset
434 if (argidx > 0)
a9e60176dcd3 patch 8.2.1551: Vim9: error for argument type does not mention the number
Bram Moolenaar <Bram@vim.org>
parents: 21909
diff changeset
435 semsg(_(e_argument_nr_type_mismatch_expected_str_but_got_str),
a9e60176dcd3 patch 8.2.1551: Vim9: error for argument type does not mention the number
Bram Moolenaar <Bram@vim.org>
parents: 21909
diff changeset
436 argidx, typename1, typename2);
a9e60176dcd3 patch 8.2.1551: Vim9: error for argument type does not mention the number
Bram Moolenaar <Bram@vim.org>
parents: 21909
diff changeset
437 else
a9e60176dcd3 patch 8.2.1551: Vim9: error for argument type does not mention the number
Bram Moolenaar <Bram@vim.org>
parents: 21909
diff changeset
438 semsg(_(e_type_mismatch_expected_str_but_got_str),
a9e60176dcd3 patch 8.2.1551: Vim9: error for argument type does not mention the number
Bram Moolenaar <Bram@vim.org>
parents: 21909
diff changeset
439 typename1, typename2);
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
440 vim_free(tofree1);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
441 vim_free(tofree2);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
442 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
443
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
444 /*
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
445 * Check if the expected and actual types match.
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
446 * Does not allow for assigning "any" to a specific type.
22004
a9e60176dcd3 patch 8.2.1551: Vim9: error for argument type does not mention the number
Bram Moolenaar <Bram@vim.org>
parents: 21909
diff changeset
447 * When "argidx" > 0 it is included in the error message.
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
448 */
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
449 int
22004
a9e60176dcd3 patch 8.2.1551: Vim9: error for argument type does not mention the number
Bram Moolenaar <Bram@vim.org>
parents: 21909
diff changeset
450 check_type(type_T *expected, type_T *actual, int give_msg, int argidx)
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
451 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
452 int ret = OK;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
453
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
454 // When expected is "unknown" we accept any actual type.
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
455 // When expected is "any" we accept any actual type except "void".
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
456 if (expected->tt_type != VAR_UNKNOWN
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
457 && !(expected->tt_type == VAR_ANY && actual->tt_type != VAR_VOID))
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
458
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
459 {
22347
712bc35842aa patch 8.2.1722: Vim9: cannot assign a lambda to a variable of type function
Bram Moolenaar <Bram@vim.org>
parents: 22322
diff changeset
460 // tt_type should match, except that a "partial" can be assigned to a
712bc35842aa patch 8.2.1722: Vim9: cannot assign a lambda to a variable of type function
Bram Moolenaar <Bram@vim.org>
parents: 22322
diff changeset
461 // variable with type "func".
712bc35842aa patch 8.2.1722: Vim9: cannot assign a lambda to a variable of type function
Bram Moolenaar <Bram@vim.org>
parents: 22322
diff changeset
462 if (!(expected->tt_type == actual->tt_type
712bc35842aa patch 8.2.1722: Vim9: cannot assign a lambda to a variable of type function
Bram Moolenaar <Bram@vim.org>
parents: 22322
diff changeset
463 || (expected->tt_type == VAR_FUNC
712bc35842aa patch 8.2.1722: Vim9: cannot assign a lambda to a variable of type function
Bram Moolenaar <Bram@vim.org>
parents: 22322
diff changeset
464 && actual->tt_type == VAR_PARTIAL)))
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
465 {
22202
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
466 if (expected->tt_type == VAR_BOOL
22184
2463b3d89ce2 patch 8.2.1641: Vim9: cannot use 0 or 1 where a bool is expected
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
467 && (actual->tt_flags & TTFLAG_BOOL_OK))
2463b3d89ce2 patch 8.2.1641: Vim9: cannot use 0 or 1 where a bool is expected
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
468 // Using number 0 or 1 for bool is OK.
2463b3d89ce2 patch 8.2.1641: Vim9: cannot use 0 or 1 where a bool is expected
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
469 return OK;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
470 if (give_msg)
22004
a9e60176dcd3 patch 8.2.1551: Vim9: error for argument type does not mention the number
Bram Moolenaar <Bram@vim.org>
parents: 21909
diff changeset
471 arg_type_mismatch(expected, actual, argidx);
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
472 return FAIL;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
473 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
474 if (expected->tt_type == VAR_DICT || expected->tt_type == VAR_LIST)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
475 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
476 // "unknown" is used for an empty list or dict
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
477 if (actual->tt_member != &t_unknown)
22004
a9e60176dcd3 patch 8.2.1551: Vim9: error for argument type does not mention the number
Bram Moolenaar <Bram@vim.org>
parents: 21909
diff changeset
478 ret = check_type(expected->tt_member, actual->tt_member,
a9e60176dcd3 patch 8.2.1551: Vim9: error for argument type does not mention the number
Bram Moolenaar <Bram@vim.org>
parents: 21909
diff changeset
479 FALSE, 0);
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
480 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
481 else if (expected->tt_type == VAR_FUNC)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
482 {
23418
681f042ae5ac patch 8.2.2252: Vim9: crash when using lambda without return type in dict
Bram Moolenaar <Bram@vim.org>
parents: 23362
diff changeset
483 // If the return type is unknown it can be anything, including
681f042ae5ac patch 8.2.2252: Vim9: crash when using lambda without return type in dict
Bram Moolenaar <Bram@vim.org>
parents: 23362
diff changeset
484 // nothing, thus there is no point in checking.
681f042ae5ac patch 8.2.2252: Vim9: crash when using lambda without return type in dict
Bram Moolenaar <Bram@vim.org>
parents: 23362
diff changeset
485 if (expected->tt_member != &t_unknown
681f042ae5ac patch 8.2.2252: Vim9: crash when using lambda without return type in dict
Bram Moolenaar <Bram@vim.org>
parents: 23362
diff changeset
486 && actual->tt_member != &t_unknown)
22004
a9e60176dcd3 patch 8.2.1551: Vim9: error for argument type does not mention the number
Bram Moolenaar <Bram@vim.org>
parents: 21909
diff changeset
487 ret = check_type(expected->tt_member, actual->tt_member,
a9e60176dcd3 patch 8.2.1551: Vim9: error for argument type does not mention the number
Bram Moolenaar <Bram@vim.org>
parents: 21909
diff changeset
488 FALSE, 0);
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
489 if (ret == OK && expected->tt_argcount != -1
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
490 && actual->tt_argcount != -1
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
491 && (actual->tt_argcount < expected->tt_min_argcount
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
492 || actual->tt_argcount > expected->tt_argcount))
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
493 ret = FAIL;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
494 if (expected->tt_args != NULL && actual->tt_args != NULL)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
495 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
496 int i;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
497
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
498 for (i = 0; i < expected->tt_argcount; ++i)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
499 // Allow for using "any" argument type, lambda's have them.
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
500 if (actual->tt_args[i] != &t_any && check_type(
22004
a9e60176dcd3 patch 8.2.1551: Vim9: error for argument type does not mention the number
Bram Moolenaar <Bram@vim.org>
parents: 21909
diff changeset
501 expected->tt_args[i], actual->tt_args[i], FALSE, 0)
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
502 == FAIL)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
503 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
504 ret = FAIL;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
505 break;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
506 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
507 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
508 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
509 if (ret == FAIL && give_msg)
22004
a9e60176dcd3 patch 8.2.1551: Vim9: error for argument type does not mention the number
Bram Moolenaar <Bram@vim.org>
parents: 21909
diff changeset
510 arg_type_mismatch(expected, actual, argidx);
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
511 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
512 return ret;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
513 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
514
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
515 /*
22898
a8bccb0634bc patch 8.2.1996: Vim9: invalid error for argument of extend()
Bram Moolenaar <Bram@vim.org>
parents: 22804
diff changeset
516 * Like check_type() but also allow for a runtime type check. E.g. "any" can be
a8bccb0634bc patch 8.2.1996: Vim9: invalid error for argument of extend()
Bram Moolenaar <Bram@vim.org>
parents: 22804
diff changeset
517 * used for "number".
a8bccb0634bc patch 8.2.1996: Vim9: invalid error for argument of extend()
Bram Moolenaar <Bram@vim.org>
parents: 22804
diff changeset
518 */
a8bccb0634bc patch 8.2.1996: Vim9: invalid error for argument of extend()
Bram Moolenaar <Bram@vim.org>
parents: 22804
diff changeset
519 int
a8bccb0634bc patch 8.2.1996: Vim9: invalid error for argument of extend()
Bram Moolenaar <Bram@vim.org>
parents: 22804
diff changeset
520 check_arg_type(type_T *expected, type_T *actual, int argidx)
a8bccb0634bc patch 8.2.1996: Vim9: invalid error for argument of extend()
Bram Moolenaar <Bram@vim.org>
parents: 22804
diff changeset
521 {
a8bccb0634bc patch 8.2.1996: Vim9: invalid error for argument of extend()
Bram Moolenaar <Bram@vim.org>
parents: 22804
diff changeset
522 if (check_type(expected, actual, FALSE, 0) == OK
a8bccb0634bc patch 8.2.1996: Vim9: invalid error for argument of extend()
Bram Moolenaar <Bram@vim.org>
parents: 22804
diff changeset
523 || use_typecheck(actual, expected))
a8bccb0634bc patch 8.2.1996: Vim9: invalid error for argument of extend()
Bram Moolenaar <Bram@vim.org>
parents: 22804
diff changeset
524 return OK;
a8bccb0634bc patch 8.2.1996: Vim9: invalid error for argument of extend()
Bram Moolenaar <Bram@vim.org>
parents: 22804
diff changeset
525 // TODO: should generate a TYPECHECK instruction.
a8bccb0634bc patch 8.2.1996: Vim9: invalid error for argument of extend()
Bram Moolenaar <Bram@vim.org>
parents: 22804
diff changeset
526 return check_type(expected, actual, TRUE, argidx);
a8bccb0634bc patch 8.2.1996: Vim9: invalid error for argument of extend()
Bram Moolenaar <Bram@vim.org>
parents: 22804
diff changeset
527 }
a8bccb0634bc patch 8.2.1996: Vim9: invalid error for argument of extend()
Bram Moolenaar <Bram@vim.org>
parents: 22804
diff changeset
528
a8bccb0634bc patch 8.2.1996: Vim9: invalid error for argument of extend()
Bram Moolenaar <Bram@vim.org>
parents: 22804
diff changeset
529 /*
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
530 * Skip over a type definition and return a pointer to just after it.
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
531 * When "optional" is TRUE then a leading "?" is accepted.
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
532 */
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
533 char_u *
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
534 skip_type(char_u *start, int optional)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
535 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
536 char_u *p = start;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
537
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
538 if (optional && *p == '?')
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
539 ++p;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
540 while (ASCII_ISALNUM(*p) || *p == '_')
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
541 ++p;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
542
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
543 // Skip over "<type>"; this is permissive about white space.
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
544 if (*skipwhite(p) == '<')
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
545 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
546 p = skipwhite(p);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
547 p = skip_type(skipwhite(p + 1), FALSE);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
548 p = skipwhite(p);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
549 if (*p == '>')
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
550 ++p;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
551 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
552 else if ((*p == '(' || (*p == ':' && VIM_ISWHITE(p[1])))
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
553 && STRNCMP("func", start, 4) == 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
554 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
555 if (*p == '(')
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
556 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
557 // handle func(args): type
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
558 ++p;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
559 while (*p != ')' && *p != NUL)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
560 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
561 char_u *sp = p;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
562
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
563 if (STRNCMP(p, "...", 3) == 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
564 p += 3;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
565 p = skip_type(p, TRUE);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
566 if (p == sp)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
567 return p; // syntax error
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
568 if (*p == ',')
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
569 p = skipwhite(p + 1);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
570 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
571 if (*p == ')')
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
572 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
573 if (p[1] == ':')
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
574 p = skip_type(skipwhite(p + 2), FALSE);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
575 else
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
576 ++p;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
577 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
578 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
579 else
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
580 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
581 // handle func: return_type
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
582 p = skip_type(skipwhite(p + 1), FALSE);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
583 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
584 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
585
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
586 return p;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
587 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
588
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
589 /*
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
590 * Parse the member type: "<type>" and return "type" with the member set.
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
591 * Use "type_gap" if a new type needs to be added.
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
592 * Returns NULL in case of failure.
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
593 */
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
594 static type_T *
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
595 parse_type_member(
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
596 char_u **arg,
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
597 type_T *type,
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
598 garray_T *type_gap,
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
599 int give_error)
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
600 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
601 type_T *member_type;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
602 int prev_called_emsg = called_emsg;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
603
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
604 if (**arg != '<')
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
605 {
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
606 if (give_error)
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
607 {
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
608 if (*skipwhite(*arg) == '<')
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
609 semsg(_(e_no_white_space_allowed_before_str), "<");
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
610 else
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
611 emsg(_(e_missing_type));
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
612 }
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
613 return NULL;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
614 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
615 *arg = skipwhite(*arg + 1);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
616
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
617 member_type = parse_type(arg, type_gap, give_error);
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
618 if (member_type == NULL)
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
619 return NULL;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
620
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
621 *arg = skipwhite(*arg);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
622 if (**arg != '>' && called_emsg == prev_called_emsg)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
623 {
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
624 if (give_error)
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
625 emsg(_(e_missing_gt_after_type));
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
626 return NULL;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
627 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
628 ++*arg;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
629
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
630 if (type->tt_type == VAR_LIST)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
631 return get_list_type(member_type, type_gap);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
632 return get_dict_type(member_type, type_gap);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
633 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
634
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
635 /*
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
636 * Parse a type at "arg" and advance over it.
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
637 * When "give_error" is TRUE give error messages, otherwise be quiet.
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
638 * Return NULL for failure.
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
639 */
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
640 type_T *
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
641 parse_type(char_u **arg, garray_T *type_gap, int give_error)
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
642 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
643 char_u *p = *arg;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
644 size_t len;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
645
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
646 // skip over the first word
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
647 while (ASCII_ISALNUM(*p) || *p == '_')
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
648 ++p;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
649 len = p - *arg;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
650
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
651 switch (**arg)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
652 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
653 case 'a':
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
654 if (len == 3 && STRNCMP(*arg, "any", len) == 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
655 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
656 *arg += len;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
657 return &t_any;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
658 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
659 break;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
660 case 'b':
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
661 if (len == 4 && STRNCMP(*arg, "bool", len) == 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
662 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
663 *arg += len;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
664 return &t_bool;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
665 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
666 if (len == 4 && STRNCMP(*arg, "blob", len) == 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
667 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
668 *arg += len;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
669 return &t_blob;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
670 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
671 break;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
672 case 'c':
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
673 if (len == 7 && STRNCMP(*arg, "channel", len) == 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
674 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
675 *arg += len;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
676 return &t_channel;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
677 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
678 break;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
679 case 'd':
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
680 if (len == 4 && STRNCMP(*arg, "dict", len) == 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
681 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
682 *arg += len;
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
683 return parse_type_member(arg, &t_dict_any,
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
684 type_gap, give_error);
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
685 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
686 break;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
687 case 'f':
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
688 if (len == 5 && STRNCMP(*arg, "float", len) == 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
689 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
690 #ifdef FEAT_FLOAT
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
691 *arg += len;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
692 return &t_float;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
693 #else
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
694 if (give_error)
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
695 emsg(_(e_this_vim_is_not_compiled_with_float_support));
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
696 return NULL;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
697 #endif
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
698 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
699 if (len == 4 && STRNCMP(*arg, "func", len) == 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
700 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
701 type_T *type;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
702 type_T *ret_type = &t_unknown;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
703 int argcount = -1;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
704 int flags = 0;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
705 int first_optional = -1;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
706 type_T *arg_type[MAX_FUNC_ARGS + 1];
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
707
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
708 // func({type}, ...{type}): {type}
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
709 *arg += len;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
710 if (**arg == '(')
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
711 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
712 // "func" may or may not return a value, "func()" does
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
713 // not return a value.
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
714 ret_type = &t_void;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
715
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
716 p = ++*arg;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
717 argcount = 0;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
718 while (*p != NUL && *p != ')')
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
719 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
720 if (*p == '?')
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
721 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
722 if (first_optional == -1)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
723 first_optional = argcount;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
724 ++p;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
725 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
726 else if (STRNCMP(p, "...", 3) == 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
727 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
728 flags |= TTFLAG_VARARGS;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
729 p += 3;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
730 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
731 else if (first_optional != -1)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
732 {
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
733 if (give_error)
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
734 emsg(_(e_mandatory_argument_after_optional_argument));
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
735 return NULL;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
736 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
737
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
738 type = parse_type(&p, type_gap, give_error);
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
739 if (type == NULL)
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
740 return NULL;
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
741 arg_type[argcount++] = type;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
742
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
743 // Nothing comes after "...{type}".
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
744 if (flags & TTFLAG_VARARGS)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
745 break;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
746
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
747 if (*p != ',' && *skipwhite(p) == ',')
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
748 {
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
749 if (give_error)
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
750 semsg(_(e_no_white_space_allowed_before_str), ",");
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
751 return NULL;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
752 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
753 if (*p == ',')
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
754 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
755 ++p;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
756 if (!VIM_ISWHITE(*p))
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
757 {
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
758 if (give_error)
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
759 semsg(_(e_white_space_required_after_str), ",");
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
760 return NULL;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
761 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
762 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
763 p = skipwhite(p);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
764 if (argcount == MAX_FUNC_ARGS)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
765 {
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
766 if (give_error)
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
767 emsg(_(e_too_many_argument_types));
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
768 return NULL;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
769 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
770 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
771
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
772 p = skipwhite(p);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
773 if (*p != ')')
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
774 {
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
775 if (give_error)
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
776 emsg(_(e_missing_close));
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
777 return NULL;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
778 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
779 *arg = p + 1;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
780 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
781 if (**arg == ':')
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
782 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
783 // parse return type
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
784 ++*arg;
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
785 if (!VIM_ISWHITE(**arg) && give_error)
21909
a211bca98bc3 patch 8.2.1504: Vim9: white space checks are only done for a :def function
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
786 semsg(_(e_white_space_required_after_str), ":");
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
787 *arg = skipwhite(*arg);
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
788 ret_type = parse_type(arg, type_gap, give_error);
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
789 if (ret_type == NULL)
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
790 return NULL;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
791 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
792 if (flags == 0 && first_optional == -1 && argcount <= 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
793 type = get_func_type(ret_type, argcount, type_gap);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
794 else
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
795 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
796 type = alloc_func_type(ret_type, argcount, type_gap);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
797 type->tt_flags = flags;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
798 if (argcount > 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
799 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
800 type->tt_argcount = argcount;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
801 type->tt_min_argcount = first_optional == -1
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
802 ? argcount : first_optional;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
803 if (func_type_add_arg_types(type, argcount,
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
804 type_gap) == FAIL)
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
805 return NULL;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
806 mch_memmove(type->tt_args, arg_type,
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
807 sizeof(type_T *) * argcount);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
808 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
809 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
810 return type;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
811 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
812 break;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
813 case 'j':
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
814 if (len == 3 && STRNCMP(*arg, "job", len) == 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
815 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
816 *arg += len;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
817 return &t_job;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
818 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
819 break;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
820 case 'l':
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
821 if (len == 4 && STRNCMP(*arg, "list", len) == 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
822 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
823 *arg += len;
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
824 return parse_type_member(arg, &t_list_any,
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
825 type_gap, give_error);
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
826 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
827 break;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
828 case 'n':
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
829 if (len == 6 && STRNCMP(*arg, "number", len) == 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
830 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
831 *arg += len;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
832 return &t_number;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
833 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
834 break;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
835 case 's':
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
836 if (len == 6 && STRNCMP(*arg, "string", len) == 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
837 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
838 *arg += len;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
839 return &t_string;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
840 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
841 break;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
842 case 'v':
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
843 if (len == 4 && STRNCMP(*arg, "void", len) == 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
844 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
845 *arg += len;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
846 return &t_void;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
847 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
848 break;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
849 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
850
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
851 if (give_error)
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
852 semsg(_(e_type_not_recognized_str), *arg);
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
853 return NULL;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
854 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
855
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
856 /*
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
857 * Check if "type1" and "type2" are exactly the same.
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
858 */
23362
f181fe2150ab patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents: 23338
diff changeset
859 int
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
860 equal_type(type_T *type1, type_T *type2)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
861 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
862 int i;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
863
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
864 if (type1->tt_type != type2->tt_type)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
865 return FALSE;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
866 switch (type1->tt_type)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
867 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
868 case VAR_UNKNOWN:
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
869 case VAR_ANY:
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
870 case VAR_VOID:
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
871 case VAR_SPECIAL:
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
872 case VAR_BOOL:
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
873 case VAR_NUMBER:
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
874 case VAR_FLOAT:
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
875 case VAR_STRING:
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
876 case VAR_BLOB:
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
877 case VAR_JOB:
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
878 case VAR_CHANNEL:
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
879 break; // not composite is always OK
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
880 case VAR_LIST:
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
881 case VAR_DICT:
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
882 return equal_type(type1->tt_member, type2->tt_member);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
883 case VAR_FUNC:
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
884 case VAR_PARTIAL:
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
885 if (!equal_type(type1->tt_member, type2->tt_member)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
886 || type1->tt_argcount != type2->tt_argcount)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
887 return FALSE;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
888 if (type1->tt_argcount < 0
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
889 || type1->tt_args == NULL || type2->tt_args == NULL)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
890 return TRUE;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
891 for (i = 0; i < type1->tt_argcount; ++i)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
892 if (!equal_type(type1->tt_args[i], type2->tt_args[i]))
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
893 return FALSE;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
894 return TRUE;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
895 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
896 return TRUE;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
897 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
898
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
899 /*
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
900 * Find the common type of "type1" and "type2" and put it in "dest".
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
901 * "type2" and "dest" may be the same.
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
902 */
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
903 void
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
904 common_type(type_T *type1, type_T *type2, type_T **dest, garray_T *type_gap)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
905 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
906 if (equal_type(type1, type2))
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
907 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
908 *dest = type1;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
909 return;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
910 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
911
22322
a5b16c9eee9d patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents: 22284
diff changeset
912 // If either is VAR_UNKNOWN use the other type. An empty list/dict has no
a5b16c9eee9d patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents: 22284
diff changeset
913 // specific type.
a5b16c9eee9d patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents: 22284
diff changeset
914 if (type1->tt_type == VAR_UNKNOWN)
a5b16c9eee9d patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents: 22284
diff changeset
915 {
a5b16c9eee9d patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents: 22284
diff changeset
916 *dest = type2;
a5b16c9eee9d patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents: 22284
diff changeset
917 return;
a5b16c9eee9d patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents: 22284
diff changeset
918 }
a5b16c9eee9d patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents: 22284
diff changeset
919 if (type2->tt_type == VAR_UNKNOWN)
a5b16c9eee9d patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents: 22284
diff changeset
920 {
a5b16c9eee9d patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents: 22284
diff changeset
921 *dest = type1;
a5b16c9eee9d patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents: 22284
diff changeset
922 return;
a5b16c9eee9d patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents: 22284
diff changeset
923 }
a5b16c9eee9d patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents: 22284
diff changeset
924
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
925 if (type1->tt_type == type2->tt_type)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
926 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
927 if (type1->tt_type == VAR_LIST || type2->tt_type == VAR_DICT)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
928 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
929 type_T *common;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
930
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
931 common_type(type1->tt_member, type2->tt_member, &common, type_gap);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
932 if (type1->tt_type == VAR_LIST)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
933 *dest = get_list_type(common, type_gap);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
934 else
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
935 *dest = get_dict_type(common, type_gap);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
936 return;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
937 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
938 if (type1->tt_type == VAR_FUNC)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
939 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
940 type_T *common;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
941
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
942 common_type(type1->tt_member, type2->tt_member, &common, type_gap);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
943 if (type1->tt_argcount == type2->tt_argcount
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
944 && type1->tt_argcount >= 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
945 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
946 int argcount = type1->tt_argcount;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
947 int i;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
948
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
949 *dest = alloc_func_type(common, argcount, type_gap);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
950 if (type1->tt_args != NULL && type2->tt_args != NULL)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
951 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
952 if (func_type_add_arg_types(*dest, argcount,
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
953 type_gap) == OK)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
954 for (i = 0; i < argcount; ++i)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
955 common_type(type1->tt_args[i], type2->tt_args[i],
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
956 &(*dest)->tt_args[i], type_gap);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
957 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
958 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
959 else
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
960 *dest = alloc_func_type(common, -1, type_gap);
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22419
diff changeset
961 // Use the minimum of min_argcount.
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22419
diff changeset
962 (*dest)->tt_min_argcount =
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22419
diff changeset
963 type1->tt_min_argcount < type2->tt_min_argcount
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22419
diff changeset
964 ? type1->tt_min_argcount : type2->tt_min_argcount;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
965 return;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
966 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
967 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
968
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
969 *dest = &t_any;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
970 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
971
21715
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
972 /*
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
973 * Get the member type of a dict or list from the items on the stack.
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
974 * "stack_top" points just after the last type on the type stack.
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
975 * For a list "skip" is 1, for a dict "skip" is 2, keys are skipped.
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
976 * Returns &t_void for an empty list or dict.
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
977 * Otherwise finds the common type of all items.
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
978 */
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
979 type_T *
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
980 get_member_type_from_stack(
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
981 type_T **stack_top,
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
982 int count,
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
983 int skip,
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
984 garray_T *type_gap)
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
985 {
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
986 int i;
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
987 type_T *result;
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
988 type_T *type;
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
989
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
990 // Use "any" for an empty list or dict.
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
991 if (count == 0)
22322
a5b16c9eee9d patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents: 22284
diff changeset
992 return &t_unknown;
21715
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
993
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
994 // Use the first value type for the list member type, then find the common
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
995 // type from following items.
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
996 result = *(stack_top -(count * skip) + skip - 1);
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
997 for (i = 1; i < count; ++i)
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
998 {
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
999 if (result == &t_any)
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
1000 break; // won't get more common
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
1001 type = *(stack_top -((count - i) * skip) + skip - 1);
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
1002 common_type(type, result, &result, type_gap);
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
1003 }
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
1004
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
1005 return result;
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
1006 }
571832713efa patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents: 21711
diff changeset
1007
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1008 char *
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1009 vartype_name(vartype_T type)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1010 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1011 switch (type)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1012 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1013 case VAR_UNKNOWN: break;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1014 case VAR_ANY: return "any";
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1015 case VAR_VOID: return "void";
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1016 case VAR_SPECIAL: return "special";
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1017 case VAR_BOOL: return "bool";
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1018 case VAR_NUMBER: return "number";
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1019 case VAR_FLOAT: return "float";
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1020 case VAR_STRING: return "string";
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1021 case VAR_BLOB: return "blob";
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1022 case VAR_JOB: return "job";
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1023 case VAR_CHANNEL: return "channel";
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1024 case VAR_LIST: return "list";
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1025 case VAR_DICT: return "dict";
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1026
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1027 case VAR_FUNC:
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1028 case VAR_PARTIAL: return "func";
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1029 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1030 return "unknown";
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1031 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1032
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1033 /*
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1034 * Return the name of a type.
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1035 * The result may be in allocated memory, in which case "tofree" is set.
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1036 */
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1037 char *
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1038 type_name(type_T *type, char **tofree)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1039 {
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
1040 char *name;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1041
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1042 *tofree = NULL;
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
1043 if (type == NULL)
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
1044 return "[unknown]";
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
1045 name = vartype_name(type->tt_type);
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1046 if (type->tt_type == VAR_LIST || type->tt_type == VAR_DICT)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1047 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1048 char *member_free;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1049 char *member_name = type_name(type->tt_member, &member_free);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1050 size_t len;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1051
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1052 len = STRLEN(name) + STRLEN(member_name) + 3;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1053 *tofree = alloc(len);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1054 if (*tofree != NULL)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1055 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1056 vim_snprintf(*tofree, len, "%s<%s>", name, member_name);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1057 vim_free(member_free);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1058 return *tofree;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1059 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1060 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1061 if (type->tt_type == VAR_FUNC)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1062 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1063 garray_T ga;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1064 int i;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1065 int varargs = (type->tt_flags & TTFLAG_VARARGS) ? 1 : 0;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1066
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1067 ga_init2(&ga, 1, 100);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1068 if (ga_grow(&ga, 20) == FAIL)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1069 return "[unknown]";
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1070 STRCPY(ga.ga_data, "func(");
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1071 ga.ga_len += 5;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1072
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1073 for (i = 0; i < type->tt_argcount; ++i)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1074 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1075 char *arg_free;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1076 char *arg_type;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1077 int len;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1078
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1079 if (type->tt_args == NULL)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1080 arg_type = "[unknown]";
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1081 else
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1082 arg_type = type_name(type->tt_args[i], &arg_free);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1083 if (i > 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1084 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1085 STRCPY((char *)ga.ga_data + ga.ga_len, ", ");
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1086 ga.ga_len += 2;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1087 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1088 len = (int)STRLEN(arg_type);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1089 if (ga_grow(&ga, len + 8) == FAIL)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1090 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1091 vim_free(arg_free);
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
1092 ga_clear(&ga);
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1093 return "[unknown]";
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1094 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1095 if (varargs && i == type->tt_argcount - 1)
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
1096 ga_concat(&ga, (char_u *)"...");
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1097 else if (i >= type->tt_min_argcount)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1098 *((char *)ga.ga_data + ga.ga_len++) = '?';
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
1099 ga_concat(&ga, (char_u *)arg_type);
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1100 vim_free(arg_free);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1101 }
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
1102 if (type->tt_argcount < 0)
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
1103 // any number of arguments
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
1104 ga_concat(&ga, (char_u *)"...");
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1105
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1106 if (type->tt_member == &t_void)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1107 STRCPY((char *)ga.ga_data + ga.ga_len, ")");
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1108 else
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1109 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1110 char *ret_free;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1111 char *ret_name = type_name(type->tt_member, &ret_free);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1112 int len;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1113
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1114 len = (int)STRLEN(ret_name) + 4;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1115 if (ga_grow(&ga, len) == FAIL)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1116 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1117 vim_free(ret_free);
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
1118 ga_clear(&ga);
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1119 return "[unknown]";
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1120 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1121 STRCPY((char *)ga.ga_data + ga.ga_len, "): ");
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1122 STRCPY((char *)ga.ga_data + ga.ga_len + 3, ret_name);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1123 vim_free(ret_free);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1124 }
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22202
diff changeset
1125 *tofree = ga.ga_data;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1126 return ga.ga_data;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1127 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1128
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1129 return name;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1130 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1131
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1132 #endif // FEAT_EVAL