annotate src/vim9type.c @ 23888:d95403445b6b v8.2.2486

patch 8.2.2486: Vim9: some errors for white space do not show context Commit: https://github.com/vim/vim/commit/ba98fb54aefada4c36390add4c7dd90b93e7e5bb Author: Bram Moolenaar <Bram@vim.org> Date: Sun Feb 7 18:06:29 2021 +0100 patch 8.2.2486: Vim9: some errors for white space do not show context Problem: Vim9: some errors for white space do not show context. Solution: Include the text at the error.
author Bram Moolenaar <Bram@vim.org>
date Sun, 07 Feb 2021 18:15:05 +0100
parents 85cf06ddb2a8
children 4b417b776b95
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
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23640
diff changeset
339 && compile_def_function(ufunc, TRUE, FALSE, NULL)
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23640
diff changeset
340 == FAIL)
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
341 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
342 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
343 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
344 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
345 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
346 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
347 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
348
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
349 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
350 if (type == NULL)
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
351 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
352 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
353 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
354 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
355
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
356 return type;
21711
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
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
359 /*
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
360 * 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
361 */
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 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
363 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
364 {
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
365 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
366 && (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
367 && (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
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
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
370 /*
22494
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
371 * 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
372 * "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
373 */
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 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
375 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
376 {
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 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
378
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
379 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
380 && (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
381 && (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
382 // 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
383 // bool.
4b4f695e9cd1 patch 8.2.2210: Vim9: allocating a type to set TTFLAG_BOOL_OK
Bram Moolenaar <Bram@vim.org>
parents: 23332
diff changeset
384 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
385 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
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
7899b4e2880c patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
388 /*
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
389 * 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
390 * "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
391 */
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
392 type_T *
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
393 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
394 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
395 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
396 return &t_list_string;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
397 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
398 return &t_dict_any;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
399 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
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 /*
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
404 * 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
405 * 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
406 */
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
407 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
408 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
409 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
410 garray_T type_list;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
411 type_T *actual_type;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
412 int res = FAIL;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
413
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
414 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
415 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
416 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
417 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
418 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
419 return res;
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
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
422 void
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
423 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
424 {
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
425 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
426 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
427
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
428 void
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
429 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
430 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
431 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
432 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
433 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
434
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
435 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
436 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
437 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
438 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
439 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
440 typename1, typename2);
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
441 vim_free(tofree1);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
442 vim_free(tofree2);
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 /*
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
446 * 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
447 * 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
448 * 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
449 */
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
450 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
451 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
452 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
453 int ret = OK;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
454
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
455 // 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
456 // 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
457 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
458 && !(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
459
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
460 {
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
461 // 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
462 // 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
463 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
464 || (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
465 && 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
466 {
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
467 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
468 && (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
469 // 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
470 return OK;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
471 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
472 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
473 return FAIL;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
474 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
475 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
476 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
477 // "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
478 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
479 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
480 FALSE, 0);
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
481 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
482 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
483 {
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
484 // 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
485 // 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
486 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
487 && 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
488 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
489 FALSE, 0);
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
490 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
491 && 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
492 && (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
493 || actual->tt_argcount > expected->tt_argcount))
23481
62fe9a7fd582 patch 8.2.2283: Vim9: crash when lambda has fewer arguments than expected
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
494 ret = FAIL;
62fe9a7fd582 patch 8.2.2283: Vim9: crash when lambda has fewer arguments than expected
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
495 if (ret == OK && expected->tt_args != NULL
62fe9a7fd582 patch 8.2.2283: Vim9: crash when lambda has fewer arguments than expected
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
496 && actual->tt_args != NULL)
21711
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 int i;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
499
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
500 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
501 // 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
502 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
503 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
504 == FAIL)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
505 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
506 ret = FAIL;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
507 break;
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 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
510 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
511 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
512 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
513 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
514 return ret;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
515 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
516
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
517 /*
23527
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
518 * Check that the arguments of "type" match "argvars[argcount]".
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
519 * Return OK/FAIL.
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
520 */
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
521 int
23640
8dcb2255ff9a patch 8.2.2362: Vim9: check of builtin function argument type is incomplete
Bram Moolenaar <Bram@vim.org>
parents: 23594
diff changeset
522 check_argument_types(
8dcb2255ff9a patch 8.2.2362: Vim9: check of builtin function argument type is incomplete
Bram Moolenaar <Bram@vim.org>
parents: 23594
diff changeset
523 type_T *type,
8dcb2255ff9a patch 8.2.2362: Vim9: check of builtin function argument type is incomplete
Bram Moolenaar <Bram@vim.org>
parents: 23594
diff changeset
524 typval_T *argvars,
8dcb2255ff9a patch 8.2.2362: Vim9: check of builtin function argument type is incomplete
Bram Moolenaar <Bram@vim.org>
parents: 23594
diff changeset
525 int argcount,
8dcb2255ff9a patch 8.2.2362: Vim9: check of builtin function argument type is incomplete
Bram Moolenaar <Bram@vim.org>
parents: 23594
diff changeset
526 char_u *name)
23527
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
527 {
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
528 int varargs = (type->tt_flags & TTFLAG_VARARGS) ? 1 : 0;
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
529 int i;
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
530
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
531 if (type->tt_type != VAR_FUNC && type->tt_type != VAR_PARTIAL)
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
532 return OK; // just in case
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
533 if (argcount < type->tt_min_argcount - varargs)
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
534 {
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
535 semsg(_(e_toofewarg), name);
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
536 return FAIL;
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
537 }
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
538 if (!varargs && type->tt_argcount >= 0 && argcount > type->tt_argcount)
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
539 {
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
540 semsg(_(e_toomanyarg), name);
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
541 return FAIL;
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
542 }
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
543 if (type->tt_args == NULL)
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
544 return OK; // cannot check
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
545
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
546
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
547 for (i = 0; i < argcount; ++i)
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
548 {
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
549 type_T *expected;
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
550
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
551 if (varargs && i >= type->tt_argcount - 1)
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
552 expected = type->tt_args[type->tt_argcount - 1]->tt_member;
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
553 else
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
554 expected = type->tt_args[i];
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
555 if (check_typval_type(expected, &argvars[i], i + 1) == FAIL)
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
556 return FAIL;
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
557 }
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
558 return OK;
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
559 }
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
560
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23481
diff changeset
561 /*
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
562 * 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
563 * 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
564 */
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
565 char_u *
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
566 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
567 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
568 char_u *p = start;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
569
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
570 if (optional && *p == '?')
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
571 ++p;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
572 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
573 ++p;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
574
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
575 // 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
576 if (*skipwhite(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 p = skipwhite(p);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
579 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
580 p = skipwhite(p);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
581 if (*p == '>')
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
582 ++p;
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 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
585 && 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
586 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
587 if (*p == '(')
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 // handle func(args): type
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
590 ++p;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
591 while (*p != ')' && *p != NUL)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
592 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
593 char_u *sp = p;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
594
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
595 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
596 p += 3;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
597 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
598 if (p == sp)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
599 return p; // syntax error
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
600 if (*p == ',')
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
601 p = skipwhite(p + 1);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
602 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
603 if (*p == ')')
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
604 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
605 if (p[1] == ':')
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
606 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
607 else
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
608 ++p;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
609 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
610 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
611 else
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
612 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
613 // handle func: return_type
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
614 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
615 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
616 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
617
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
618 return p;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
619 }
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 /*
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
622 * 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
623 * 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
624 * 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
625 */
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
626 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
627 parse_type_member(
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
628 char_u **arg,
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
629 type_T *type,
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
630 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
631 int give_error)
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
632 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
633 type_T *member_type;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
634 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
635
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
636 if (**arg != '<')
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
637 {
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
638 if (give_error)
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
639 {
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
640 if (*skipwhite(*arg) == '<')
23888
d95403445b6b patch 8.2.2486: Vim9: some errors for white space do not show context
Bram Moolenaar <Bram@vim.org>
parents: 23877
diff changeset
641 semsg(_(e_no_white_space_allowed_before_str_str), "<", *arg);
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
642 else
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
643 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
644 }
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
645 return NULL;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
646 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
647 *arg = skipwhite(*arg + 1);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
648
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
649 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
650 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
651 return NULL;
21711
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 *arg = skipwhite(*arg);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
654 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
655 {
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
656 if (give_error)
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
657 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
658 return NULL;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
659 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
660 ++*arg;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
661
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
662 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
663 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
664 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
665 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
666
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 * 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
669 * 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
670 * 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
671 */
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
672 type_T *
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
673 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
674 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
675 char_u *p = *arg;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
676 size_t len;
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 // 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
679 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
680 ++p;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
681 len = p - *arg;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
682
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
683 switch (**arg)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
684 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
685 case 'a':
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
686 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
687 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
688 *arg += len;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
689 return &t_any;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
690 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
691 break;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
692 case 'b':
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
693 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
694 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
695 *arg += len;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
696 return &t_bool;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
697 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
698 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
699 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
700 *arg += len;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
701 return &t_blob;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
702 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
703 break;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
704 case 'c':
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
705 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
706 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
707 *arg += len;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
708 return &t_channel;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
709 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
710 break;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
711 case 'd':
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
712 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
713 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
714 *arg += len;
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
715 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
716 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
717 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
718 break;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
719 case 'f':
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
720 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
721 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
722 #ifdef FEAT_FLOAT
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
723 *arg += len;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
724 return &t_float;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
725 #else
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
726 if (give_error)
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
727 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
728 return NULL;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
729 #endif
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 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
732 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
733 type_T *type;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
734 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
735 int argcount = -1;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
736 int flags = 0;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
737 int first_optional = -1;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
738 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
739
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
740 // func({type}, ...{type}): {type}
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
741 *arg += len;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
742 if (**arg == '(')
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
743 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
744 // "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
745 // not return a value.
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
746 ret_type = &t_void;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
747
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
748 p = ++*arg;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
749 argcount = 0;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
750 while (*p != NUL && *p != ')')
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
751 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
752 if (*p == '?')
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
753 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
754 if (first_optional == -1)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
755 first_optional = argcount;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
756 ++p;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
757 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
758 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
759 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
760 flags |= TTFLAG_VARARGS;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
761 p += 3;
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 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
764 {
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
765 if (give_error)
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
766 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
767 return NULL;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
768 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
769
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
770 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
771 if (type == NULL)
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
772 return NULL;
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
773 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
774
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
775 // Nothing comes after "...{type}".
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
776 if (flags & TTFLAG_VARARGS)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
777 break;
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 if (*p != ',' && *skipwhite(p) == ',')
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
780 {
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
781 if (give_error)
23888
d95403445b6b patch 8.2.2486: Vim9: some errors for white space do not show context
Bram Moolenaar <Bram@vim.org>
parents: 23877
diff changeset
782 semsg(_(e_no_white_space_allowed_before_str_str),
d95403445b6b patch 8.2.2486: Vim9: some errors for white space do not show context
Bram Moolenaar <Bram@vim.org>
parents: 23877
diff changeset
783 ",", p);
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
784 return NULL;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
785 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
786 if (*p == ',')
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
787 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
788 ++p;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
789 if (!VIM_ISWHITE(*p))
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
790 {
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
791 if (give_error)
23877
85cf06ddb2a8 patch 8.2.2480: Vim9: some errors for white space do not show context
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
792 semsg(_(e_white_space_required_after_str_str),
85cf06ddb2a8 patch 8.2.2480: Vim9: some errors for white space do not show context
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
793 ",", p - 1);
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
794 return NULL;
21711
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 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
797 p = skipwhite(p);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
798 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
799 {
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
800 if (give_error)
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
801 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
802 return NULL;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
803 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
804 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
805
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
806 p = skipwhite(p);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
807 if (*p != ')')
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
808 {
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
809 if (give_error)
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
810 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
811 return NULL;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
812 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
813 *arg = p + 1;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
814 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
815 if (**arg == ':')
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
816 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
817 // parse return type
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
818 ++*arg;
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
819 if (!VIM_ISWHITE(**arg) && give_error)
23877
85cf06ddb2a8 patch 8.2.2480: Vim9: some errors for white space do not show context
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
820 semsg(_(e_white_space_required_after_str_str),
85cf06ddb2a8 patch 8.2.2480: Vim9: some errors for white space do not show context
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
821 ":", *arg - 1);
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
822 *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
823 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
824 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
825 return NULL;
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 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
828 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
829 else
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 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
832 type->tt_flags = flags;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
833 if (argcount > 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
834 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
835 type->tt_argcount = argcount;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
836 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
837 ? argcount : first_optional;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
838 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
839 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
840 return NULL;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
841 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
842 sizeof(type_T *) * argcount);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
843 }
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 return type;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
846 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
847 break;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
848 case 'j':
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
849 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
850 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
851 *arg += len;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
852 return &t_job;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
853 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
854 break;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
855 case 'l':
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
856 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
857 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
858 *arg += len;
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
859 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
860 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
861 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
862 break;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
863 case 'n':
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
864 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
865 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
866 *arg += len;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
867 return &t_number;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
868 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
869 break;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
870 case 's':
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
871 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
872 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
873 *arg += len;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
874 return &t_string;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
875 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
876 break;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
877 case 'v':
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
878 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
879 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
880 *arg += len;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
881 return &t_void;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
882 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
883 break;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
884 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
885
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
886 if (give_error)
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
887 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
888 return NULL;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
889 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
890
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
891 /*
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
892 * 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
893 */
23362
f181fe2150ab patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents: 23338
diff changeset
894 int
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
895 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
896 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
897 int i;
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 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
900 return FALSE;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
901 switch (type1->tt_type)
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 case VAR_UNKNOWN:
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
904 case VAR_ANY:
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
905 case VAR_VOID:
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
906 case VAR_SPECIAL:
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
907 case VAR_BOOL:
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
908 case VAR_NUMBER:
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
909 case VAR_FLOAT:
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
910 case VAR_STRING:
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
911 case VAR_BLOB:
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
912 case VAR_JOB:
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
913 case VAR_CHANNEL:
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
914 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
915 case VAR_LIST:
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
916 case VAR_DICT:
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
917 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
918 case VAR_FUNC:
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
919 case VAR_PARTIAL:
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
920 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
921 || 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
922 return FALSE;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
923 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
924 || 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
925 return TRUE;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
926 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
927 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
928 return FALSE;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
929 return TRUE;
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 return TRUE;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
932 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
933
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
934 /*
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
935 * 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
936 * "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
937 */
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
938 void
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
939 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
940 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
941 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
942 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
943 *dest = type1;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
944 return;
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
22322
a5b16c9eee9d patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents: 22284
diff changeset
947 // 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
948 // specific type.
a5b16c9eee9d patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents: 22284
diff changeset
949 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
950 {
a5b16c9eee9d patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents: 22284
diff changeset
951 *dest = type2;
a5b16c9eee9d patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents: 22284
diff changeset
952 return;
a5b16c9eee9d patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents: 22284
diff changeset
953 }
a5b16c9eee9d patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents: 22284
diff changeset
954 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
955 {
a5b16c9eee9d patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents: 22284
diff changeset
956 *dest = type1;
a5b16c9eee9d patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents: 22284
diff changeset
957 return;
a5b16c9eee9d patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents: 22284
diff changeset
958 }
a5b16c9eee9d patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents: 22284
diff changeset
959
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
960 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
961 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
962 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
963 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
964 type_T *common;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
965
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
966 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
967 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
968 *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
969 else
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
970 *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
971 return;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
972 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
973 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
974 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
975 type_T *common;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
976
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
977 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
978 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
979 && type1->tt_argcount >= 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
980 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
981 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
982 int i;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
983
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
984 *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
985 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
986 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
987 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
988 type_gap) == OK)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
989 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
990 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
991 &(*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
992 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
993 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
994 else
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
995 *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
996 // Use the minimum of min_argcount.
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22419
diff changeset
997 (*dest)->tt_min_argcount =
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22419
diff changeset
998 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
999 ? 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
1000 return;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1001 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1002 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1003
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1004 *dest = &t_any;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1005 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1006
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
1007 /*
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
1008 * 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
1009 * "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
1010 * 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
1011 * 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
1012 * 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
1013 */
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
1014 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
1015 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
1016 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
1017 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
1018 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
1019 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
1020 {
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
1021 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
1022 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
1023 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
1024
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
1025 // 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
1026 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
1027 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
1028
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
1029 // 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
1030 // 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
1031 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
1032 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
1033 {
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
1034 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
1035 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
1036 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
1037 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
1038 }
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
1039
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
1040 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
1041 }
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
1042
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1043 char *
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1044 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
1045 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1046 switch (type)
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 case VAR_UNKNOWN: break;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1049 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
1050 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
1051 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
1052 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
1053 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
1054 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
1055 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
1056 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
1057 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
1058 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
1059 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
1060 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
1061
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1062 case VAR_FUNC:
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1063 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
1064 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1065 return "unknown";
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
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1068 /*
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1069 * 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
1070 * 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
1071 */
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1072 char *
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1073 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
1074 {
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
1075 char *name;
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1076
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1077 *tofree = NULL;
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
1078 if (type == NULL)
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
1079 return "[unknown]";
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
1080 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
1081 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
1082 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1083 char *member_free;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1084 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
1085 size_t len;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1086
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1087 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
1088 *tofree = alloc(len);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1089 if (*tofree != NULL)
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_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
1092 vim_free(member_free);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1093 return *tofree;
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 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1096 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
1097 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1098 garray_T ga;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1099 int i;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1100 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
1101
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1102 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
1103 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
1104 return "[unknown]";
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1105 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
1106 ga.ga_len += 5;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1107
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1108 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
1109 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1110 char *arg_free;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1111 char *arg_type;
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 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
1115 arg_type = "[unknown]";
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1116 else
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1117 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
1118 if (i > 0)
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1119 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1120 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
1121 ga.ga_len += 2;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1122 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1123 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
1124 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
1125 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1126 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
1127 ga_clear(&ga);
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1128 return "[unknown]";
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1129 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1130 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
1131 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
1132 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
1133 *((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
1134 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
1135 vim_free(arg_free);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1136 }
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
1137 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
1138 // 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
1139 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
1140
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1141 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
1142 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
1143 else
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1144 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1145 char *ret_free;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1146 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
1147 int len;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1148
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1149 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
1150 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
1151 {
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1152 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
1153 ga_clear(&ga);
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1154 return "[unknown]";
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1155 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1156 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
1157 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
1158 vim_free(ret_free);
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1159 }
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
1160 *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
1161 return ga.ga_data;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1162 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1163
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1164 return name;
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1165 }
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1166
23594
d3e064f54890 patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
1167 /*
d3e064f54890 patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
1168 * "typename(expr)" function
d3e064f54890 patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
1169 */
d3e064f54890 patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
1170 void
d3e064f54890 patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
1171 f_typename(typval_T *argvars, typval_T *rettv)
d3e064f54890 patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
1172 {
d3e064f54890 patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
1173 garray_T type_list;
d3e064f54890 patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
1174 type_T *type;
d3e064f54890 patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
1175 char *tofree;
d3e064f54890 patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
1176 char *name;
d3e064f54890 patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
1177
d3e064f54890 patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
1178 rettv->v_type = VAR_STRING;
d3e064f54890 patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
1179 ga_init2(&type_list, sizeof(type_T *), 10);
d3e064f54890 patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
1180 type = typval2type(argvars, &type_list);
d3e064f54890 patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
1181 name = type_name(type, &tofree);
d3e064f54890 patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
1182 if (tofree != NULL)
d3e064f54890 patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
1183 rettv->vval.v_string = (char_u *)tofree;
d3e064f54890 patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
1184 else
d3e064f54890 patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
1185 {
d3e064f54890 patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
1186 rettv->vval.v_string = vim_strsave((char_u *)name);
d3e064f54890 patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
1187 vim_free(tofree);
d3e064f54890 patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
1188 }
d3e064f54890 patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
1189 clear_type_list(&type_list);
d3e064f54890 patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
1190 }
d3e064f54890 patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
1191
21711
d2dee69de7c7 patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1192 #endif // FEAT_EVAL